---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: trash-updater
  namespace: media
spec:
  schedule: "0 0 * * *"
  concurrencyPolicy: "Forbid"
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 5
  jobTemplate:
    spec:
      backoffLimit: 3
      ttlSecondsAfterFinished: 300
      template:
        spec:
          restartPolicy: OnFailure
          initContainers:
            - name: render-config
              image: ghcr.io/k8s-at-home/trash-updater:v1.8.0
              envFrom:
                - secretRef:
                    name: arr-apikeys
              command:
                - "/bin/bash"
                - -c
              args:
                - "envsubst < /config/trash.yaml > /shared/trash.yaml"
              volumeMounts:
                - name: config
                  mountPath: /config
                - name: shared
                  mountPath: /shared
          containers:
            - name: trash-updater-sonarr
              image: ghcr.io/k8s-at-home/trash-updater:v1.8.0
              imagePullPolicy: IfNotPresent
              env:
                - name: TZ
                  value: "${TIMEZONE}"
                - name: DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
                  value: "1"
              command:
                - /app/trash
              args:
                - sonarr
                - --config
                - /config/trash.yaml
              volumeMounts:
                - name: shared
                  mountPath: /config
                  readOnly: true
            # - name: trash-updater-radarr
            #   image: ghcr.io/k8s-at-home/trash-updater:v1.8.0
            #   imagePullPolicy: IfNotPresent
            #   env:
            #     - name: TZ
            #       value: "${TIMEZONE}"
            #     - name: DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
            #       value: "1"
            #   command:
            #     - /app/trash
            #   args:
            #     - radarr
            #     - --config
            #     - /config/trash.yaml
            #   volumeMounts:
            #     - name: shared
            #       mountPath: /config
            #       readOnly: true
          volumes:
            - name: config
              configMap:
                name: trash-updater-config
            - name: shared
              emptyDir: {}
