#--------------------------------------------------------------------------
# Licensed Materials - Property of IBM
#
# (C) Copyright IBM Corporation 2019.
#
# US Government Users Restricted Rights - Use, duplication or disclosure
# restricted by GSA ADP Schedule Contract with IBM Corporation.
#--------------------------------------------------------------------------

apiVersion: batch/v1
kind: Job
metadata:
  name: icp-mongodb-restore
  namespace: ibm-common-services
spec:
  template:
    spec:
      containers:
      - name: icp-mongodb-restore
        image: quay.io/opencloudio/ibm-mongodb@sha256:5004b6073efd2df5eae51431e866123d386495aea1b4baa2dcac9fcbaaf7eb83
        command: ["bash", "-c", "cat /cred/mongo-certs/tls.crt /cred/mongo-certs/tls.key > /dump/mongo.pem; cat /cred/cluster-ca/tls.crt /cred/cluster-ca/tls.key > /dump/ca.pem; mongorestore --oplogReplay --host rs0/mongodb:$MONGODB_SERVICE_PORT --username $ADMIN_USER --password $ADMIN_PASSWORD --authenticationDatabase admin --ssl --sslCAFile /dump/ca.pem --sslPEMKeyFile /dump/mongo.pem /dump"]
        volumeMounts:
        - mountPath: "/dump"
          name: mongodump
        - mountPath: "/cred/mongo-certs"
          name: icp-mongodb-client-cert
        - mountPath: "/cred/cluster-ca"
          name: mongodb-root-ca-cert
        env:
        - name: MONGODB_SERVICE_PORT
          value: "27017"
        - 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: my-mongodump
      - name: icp-mongodb-client-cert
        secret:
          defaultMode: 0400
          secretName: icp-mongodb-client-cert
      - name: mongodb-root-ca-cert
        secret:
          defaultMode: 400
          secretName: mongodb-root-ca-cert
      restartPolicy: Never