---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: mailbackup
  namespace: scripts
  labels:
    app: mailbackup
spec:
  schedule: "0 2 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          automountServiceAccountToken: false

          securityContext:
            supplementalGroups:
              - 65541

          containers:
            - name: mailbackup-2020
              image: ghcr.io/k8s-at-home/getmail:v6.18.8
              imagePullPolicy: IfNotPresent
              env:
                - name: TZ
                  value: "${TIMEZONE}"
              command:
                - "/scripts/mailbackup.sh"
              volumeMounts:
                - name: mailbackup-script
                  mountPath: /scripts/mailbackup.sh
                  subPath: mailbackup.sh
                  readOnly: true
                - name: secrets
                  mountPath: /config
                  readOnly: true
                - mountPath: /data
                  name: mailbackup

          restartPolicy: OnFailure

          volumes:
            - name: mailbackup-script
              projected:
                defaultMode: 0775
                sources:
                  - configMap:
                      name: mailbackup
                      items:
                        - key: mailbackup.sh
                          path: mailbackup.sh
            - name: secrets
              secret:
                secretName: mailbackup-secrets
            - name: mailbackup
              nfs:
                server: "${NAS_ADDRESS}"
                path: /volume1/Backup/Bernd/Email
