---
# mediamover server: REST API + UI on :8080. Spawns one worker Job per queued
# file using this same image with `worker` args (Job spec lives in code; workers
# run as the default ServiceAccount and mount the same PVCs). The queue is
# in-memory, so keep a single replica; a restart just loses queued entries.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mediamover
  namespace: arrstack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mediamover
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mediamover
    spec:
      serviceAccountName: mediamover
      automountServiceAccountToken: true
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
        runAsGroup: 65532
        fsGroup: 65532
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: server
          image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/mediamover:v0.1.0
          imagePullPolicy: IfNotPresent
          args:
            - server
            - --src-root=/srv/src
            - --src-pvc=mediafs
            - --dst-roots=movies=/srv/dst/movies,tv=/srv/dst/tv
            - --dst-pvc=movies=media-movies,tv=media-tv
            - --namespace=arrstack
            - --image=artifactapi.k8s.syd1.au.unkin.net/docker-internal/mediamover:v0.1.0
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
          volumeMounts:
            # RW: move mode deletes the source file after a successful copy.
            - name: src
              mountPath: /srv/src
            - name: dst-movies
              mountPath: /srv/dst/movies
            - name: dst-tv
              mountPath: /srv/dst/tv
          livenessProbe:
            httpGet:
              path: /api/limit
              port: http
            initialDelaySeconds: 10
            periodSeconds: 30
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /api/limit
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - ALL
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 512Mi
      volumes:
        - name: src
          persistentVolumeClaim:
            claimName: mediafs
        - name: dst-movies
          persistentVolumeClaim:
            claimName: media-movies
        - name: dst-tv
          persistentVolumeClaim:
            claimName: media-tv
      restartPolicy: Always
