---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: &app recyclarr
  namespace: media
spec:
  schedule: "0 3 * * *"
  concurrencyPolicy: "Forbid"
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 5
  jobTemplate:
    spec:
      backoffLimit: 3
      ttlSecondsAfterFinished: 300
      template:
        spec:
          automountServiceAccountToken: false
          restartPolicy: OnFailure
          initContainers:
            - name: render-configs
              image: ghcr.io/k8s-at-home/recyclarr:v2.1.2
              envFrom:
                - secretRef:
                    name: *app
              command:
                - "/bin/bash"
                - -c
              args:
                - "envsubst < /config/recyclarr.yaml > /shared/recyclarr.yaml"
              volumeMounts:
                - name: config
                  mountPath: /config
                - name: shared
                  mountPath: /shared
          containers:
            - name: sonarrs
              image: ghcr.io/k8s-at-home/recyclarr:v2.1.2
              imagePullPolicy: IfNotPresent
              env:
                - name: TZ
                  value: "${TIMEZONE}"
                # TODO(recyclarr): Remove once new version is pushed
                - name: XDG_CONFIG_HOME
                  value: /config
              command:
                - /app/recyclarr
              args:
                - sonarr
                - --config
                - /config/recyclarr.yaml
              volumeMounts:
                - name: shared
                  mountPath: /config/recyclarr.yaml
                  subPath: recyclarr.yaml
                  readOnly: true
            - name: radarrs
              image: ghcr.io/k8s-at-home/recyclarr:v2.1.2
              imagePullPolicy: IfNotPresent
              env:
                - name: TZ
                  value: "${TIMEZONE}"
                # TODO(recyclarr): Remove once new version is pushed
                - name: XDG_CONFIG_HOME
                  value: /config
              command:
                - /app/recyclarr
              args:
                - radarr
                - --config
                - /config/recyclarr.yaml
              volumeMounts:
                - name: shared
                  mountPath: /config/recyclarr.yaml
                  subPath: recyclarr.yaml
                  readOnly: true
          volumes:
            - name: config
              configMap:
                name: *app
            - name: shared
              emptyDir: {}
