apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-to-bucket
spec:
  concurrencyPolicy: Forbid
  schedule: '0 */6 * * *'  # This job will run every 6 hours. You can also use " schedule: '* * * * *' " to run this cron job instantly
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        spec:
          volumes:
            - name: koku-metrics-operator-data
              persistentVolumeClaim:
                claimName: koku-metrics-operator-data
            - name: backup-scripts
              configMap:
                name: backup-scripts
          containers:
            - name: s3sync
              image: quay.io/operate-first/curator-s3-sync:latest
              envFrom:
                - secretRef:
                    name: backup-credentials
                - configMapRef:
                    name: backup-config
              command:
                - python3
                - /scripts/unzip_backup.py
              volumeMounts:
                - name: backup-scripts
                  mountPath: /scripts
                - name: koku-metrics-operator-data
                  mountPath: /tmp/koku-metrics-operator-data  #koku meterics operator storage path
            - name: mc
              image: docker.io/minio/mc
              envFrom:
                - secretRef:
                    name: backup-credentials
                - configMapRef:
                    name: backup-config
              command:
                - sh
              args:
                ['-c', '[ "$HAS_S3_ACCESS" ] || exit 1; if [[ $HAS_S3_ACCESS == true ]]; then sh ./scripts/run-backup.sh; else echo no S3 bucket provided; exit 0; fi;']
              volumeMounts:
                - name: backup-scripts
                  mountPath: /scripts
                - name: koku-metrics-operator-data
                  mountPath: /tmp/koku-metrics-operator-data
          restartPolicy: Never
