apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: mysql-backup
  namespace: kubeflow
  labels:
    app: mysql-backup
spec:
  schedule: "0 0 * * *"
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "true"
          labels:
            app: mysql-backup
        spec:
          containers:
          - name: backup
            image: dna/mysql_backup:0.4
            command:
            - sh
            - -c
            - | 
              until curl -fsI http://localhost:15021/healthz/ready; do echo \"Waiting for Sidecar...\"; sleep 3; done;
              echo \"Sidecar available. Running the command...\";
              bash /srv/jobs/backup_script.sh;
              x=$(echo $?); curl -fsI -X POST http://localhost:15020/quitquitquit && exit $x
            imagePullPolicy: Always
            env:
              - name: BACKUPDIR
                value: "/var/backup/mysql"
              - name: HOST
                value: "mysql.kubeflow"
              - name: USER
                value: "root"
              - name: PASS
                valueFrom:
                  secretKeyRef:
                    name: mysql
                    key: mysql-root-password
            volumeMounts:
              - name: mysql-backup
                mountPath: "/var/backup/mysql"
          serviceAccountName: ml-pipeline
          restartPolicy: OnFailure
          securityContext:
            runAsUser: 1001
            runAsGroup: 1001
            fsGroup: 1001
          volumes:
          - name: mysql-backup
            persistentVolumeClaim:
              claimName: mysql-backup