---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: series-cleanup
  namespace: media
  labels:
    app: series-cleanup
spec:
  schedule: "10 */6 * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 0
  jobTemplate:
    spec:
      activeDeadlineSeconds: 600
      template:
        metadata:
          annotations:
            botkube.io/disable: "true"
        spec:
          automountServiceAccountToken: false

          containers:
            - name: series-cleanup
              image: ghcr.io/dcplaya/series-cleanup:2.1.1
              env:
                - name: TRAKT_CLIENT_ID
                  valueFrom:
                    secretKeyRef:
                      name: series-cleanup-secrets
                      key: TRAKT_CLIENT_ID
                - name: TRAKT_CLIENT_SECRET
                  valueFrom:
                    secretKeyRef:
                      name: series-cleanup-secrets
                      key: TRAKT_CLIENT_SECRET
              volumeMounts:
                - mountPath: /data
                  name: data
                - mountPath: /data/settings.json
                  name: config
                  subPath: settings.json
                - mountPath: /media
                  name: nas-media

          restartPolicy: OnFailure

          securityContext:
            runAsUser: 1031
            runAsGroup: 100
            fsGroup: 2000
            supplementalGroups:
              - 65539

          volumes:
            - name: data
              persistentVolumeClaim:
                claimName: series-cleanup-data
            - name: config
              projected:
                defaultMode: 0775
                sources:
                  - configMap:
                      name: series-cleanup-config
           #  - name: nas-media
           #    nfs:
           #      server: "${NAS_ADDRESS}"
           #      path: /Merged-Media
