
apiVersion: batch/v1
kind: Job
metadata:
  name: mongodb-backup
spec:
  template:
    spec:
      containers:
      - name: cs-mongodb-backup
        image: quay.io/opencloudio/ibm-mongodb:4.0.24
        command: ["bash", "-c", "cat /cred/mongo-certs/tls.crt /cred/mongo-certs/tls.key > /mongo.pem; cat /cred/cluster-ca/tls.crt /cred/cluster-ca/tls.key > /ca.pem; mongodump --oplog --out /dump/dump --host mongodb:$MONGODB_SERVICE_PORT --username $ADMIN_USER --password $ADMIN_PASSWORD --authenticationDatabase admin --ssl --sslCAFile /ca.pem --sslPEMKeyFile /mongo.pem"]
        volumeMounts:
        - mountPath: "/dump"
          name: mongodump
        - mountPath: "/cred/mongo-certs"
          name: icp-mongodb-client-cert
        - mountPath: "/cred/cluster-ca"
          name: cluster-ca-cert
        env:
          - name: ADMIN_USER
            valueFrom:
              secretKeyRef:
                name: icp-mongodb-admin
                key: user
          - name: ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: icp-mongodb-admin
                key: password
      volumes:
      - name: mongodump
        persistentVolumeClaim:
          claimName: cs-mongodump
      - name: icp-mongodb-client-cert
        secret:
          defaultMode: 0400
          secretName: icp-mongodb-client-cert
      - name: cluster-ca-cert
        secret:
          defaultMode: 0400
          secretName: mongodb-root-ca-cert
      restartPolicy: Never
      securityContext: 
        runAsUser: 0
