apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-mongodb
spec:
  schedule: "0 */1 * * *"
  concurrencyPolicy: Forbid
  suspend: false
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          
          containers:
          - name: backup-mongodb
            image: tandris/k8s-backup-mongodb:latest
            env:
            - name: MONGODB_URI
              valueFrom:
                secretKeyRef:
                  name: mongodb-uri
                  key: MONGODB_URI              

            - name: BUCKET_URI
              valueFrom:
                secretKeyRef:
                  name: aws-bucket
                  key: BUCKET_URI

            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  name: aws-key
                  key: AWS_ACCESS_KEY_ID

            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: aws-secret
                  key: AWS_SECRET_ACCESS_KEY

            - name: AWS_DEFAULT_REGION
              valueFrom:
                secretKeyRef:
                  name: aws-region
                  key: AWS_DEFAULT_REGION
            
            - name: AWS_ENDPOINT_URL
              valueFrom:
                secretKeyRef:
                  name: aws-endpoint
                  key: AWS_ENDPOINT_URL
            
            - name: SUBFOLDER
              valueFrom:
                secretKeyRef:
                  name: aws-subfolder
                  key: SUBFOLDER
            
            - name: MONGODB_DB_NAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-db-name
                  key: MONGODB_DB_NAME 
                  
