apiVersion: batch/v1
kind: CronJob
metadata:
  name: vault-snapshot
  labels:
    app.kubernetes.io/controller: snapshot
    app.kubernetes.io/instance: vault
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: vault
    helm.sh/chart: snapshot-4.5.0
  namespace: vault
spec:
  suspend: false
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 90
  timeZone: US/Central
  schedule: "0 4 * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      parallelism: 1
      backoffLimit: 3
      template:
        metadata:
          labels:
            app.kubernetes.io/controller: snapshot
            app.kubernetes.io/instance: vault
            app.kubernetes.io/name: vault
        spec:
          enableServiceLinks: false
          serviceAccountName: default
          automountServiceAccountToken: true
          hostIPC: false
          hostNetwork: false
          hostPID: false
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          initContainers:
            - args:
                - -ec
                - /scripts/snapshot.sh
              command:
                - /bin/ash
              env:
                - name: VAULT_ADDR
                  value: http://vault-active.vault.svc.cluster.local:8200
              envFrom:
                - secretRef:
                    name: vault-snapshot-agent-token
              image: hashicorp/vault:1.21.1
              imagePullPolicy: IfNotPresent
              name: snapshot
              volumeMounts:
                - mountPath: /opt/backup
                  name: backup
                - mountPath: /scripts/snapshot.sh
                  name: snapshot-script
                  subPath: snapshot.sh
          containers:
            - args:
                - -ec
                - /scripts/backup.sh
              command:
                - /bin/sh
              env:
                - name: BUCKET
                  valueFrom:
                    secretKeyRef:
                      key: BUCKET
                      name: vault-s3cmd-external-config
                - name: TARGET
                  value: External
              envFrom:
                - secretRef:
                    name: vault-backup-ntfy-secret
              image: d3fk/s3cmd:latest@sha256:64a23903ee1b156ae7d795efc756b68ad802bce695f5608343edadba3dea1dc1
              imagePullPolicy: IfNotPresent
              name: s3-backup-external
              volumeMounts:
                - mountPath: /opt/backup
                  name: backup
                - mountPath: /scripts/backup.sh
                  name: backup-script
                  subPath: backup.sh
                - mountPath: /root/.s3cfg
                  mountPropagation: None
                  name: s3cmd-external-config
                  readOnly: true
                  subPath: .s3cfg
            - args:
                - -ec
                - /scripts/backup.sh
              command:
                - /bin/sh
              env:
                - name: BUCKET
                  valueFrom:
                    secretKeyRef:
                      key: BUCKET
                      name: vault-s3cmd-local-config
                - name: TARGET
                  value: Local
              envFrom:
                - secretRef:
                    name: vault-backup-ntfy-secret
              image: d3fk/s3cmd:latest@sha256:64a23903ee1b156ae7d795efc756b68ad802bce695f5608343edadba3dea1dc1
              imagePullPolicy: IfNotPresent
              name: s3-backup-local
              volumeMounts:
                - mountPath: /opt/backup
                  name: backup
                - mountPath: /scripts/backup.sh
                  name: backup-script
                  subPath: backup.sh
                - mountPath: /root/.s3cfg
                  mountPropagation: None
                  name: s3cmd-local-config
                  readOnly: true
                  subPath: .s3cfg
            - args:
                - -ec
                - /scripts/backup.sh
              command:
                - /bin/sh
              env:
                - name: BUCKET
                  valueFrom:
                    secretKeyRef:
                      key: BUCKET
                      name: vault-s3cmd-remote-config
                - name: TARGET
                  value: Remote
              envFrom:
                - secretRef:
                    name: vault-backup-ntfy-secret
              image: d3fk/s3cmd:latest@sha256:64a23903ee1b156ae7d795efc756b68ad802bce695f5608343edadba3dea1dc1
              imagePullPolicy: IfNotPresent
              name: s3-backup-remote
              volumeMounts:
                - mountPath: /opt/backup
                  name: backup
                - mountPath: /scripts/backup.sh
                  name: backup-script
                  subPath: backup.sh
                - mountPath: /root/.s3cfg
                  mountPropagation: None
                  name: s3cmd-remote-config
                  readOnly: true
                  subPath: .s3cfg
          volumes:
            - name: backup
              persistentVolumeClaim:
                claimName: vault-storage-backup
            - configMap:
                defaultMode: 493
                name: vault-backup-script
              name: backup-script
            - name: s3cmd-external-config
              secret:
                secretName: vault-s3cmd-external-config
            - name: s3cmd-local-config
              secret:
                secretName: vault-s3cmd-local-config
            - name: s3cmd-remote-config
              secret:
                secretName: vault-s3cmd-remote-config
            - configMap:
                defaultMode: 493
                name: vault-snapshot-script
              name: snapshot-script
