apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: pg-backup-cron
spec:
  schedule: "0 */6 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: pg-backup
            image: dockerhub.iudx.io/iudx/postgresql-repmgr:11.12.0
            imagePullPolicy: "IfNotPresent"
            securityContext:
              runAsUser: 1001
            env:
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: psql-passwords
                  key: postgresql-password
            envFrom:
              - secretRef: 
                  name: backup-s3-secret
            command: ["/bin/sh", "-c", "--"]
            args: ["/usr/bin/backup-script.sh"]
            volumeMounts:
            - name: backup-s3-cfg
              mountPath: /s3cmd/
            - name: backup-script
              mountPath: /usr/bin/backup-script.sh
              subPath: backup-script.sh
          restartPolicy: OnFailure
          imagePullSecrets:
          - name: regcred
          volumes:
            - name: backup-s3-cfg
              configMap:
                name: backup-s3-cfg
                items:
                - key: s3cfg
                  path: .s3cfg
            - name: backup-script
              configMap:
                name: pg-backup-script
                defaultMode: 0555

