apiVersion: batch/v1beta1
kind: CronJob
metadata:
  labels:
    app: update-shapes-template
  name: update-shapes
  namespace: nrts-prc-tools
spec:
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            parent: update-shapes
        spec:
          containers:
            - name: update-shapes
              env:
                - name: API_USERNAME
                  value: ''
                - name: API_PASSWORD
                  value: ''
                - name: API_PROTOCOL
                  value: ''
                - name: API_HOST
                  value: ''
                - name: API_PORT
                  value: ''
                - name: CLIENT_ID
                  value: ''
                - name: GRANT_TYPE
                  value: ''
                - name: AUTH_ENDPOINT
                  value: ''
                - name: JSON_PAYLOAD
                  value: '{"attachments":[{"text":"Shapes Import Job for nrts-prc-prod Completed Successfully!", "color":"#00FF00"}]}'
                - name: JSON_PAYLOAD_FAIL
                  value: '{"attachments":[{"text":"Shapes Import Job for nrts-prc-prod Failed!", "color":"#FF0000"}]}'
                - name: NOTIFICATION_URL
                  value: ''
                - name: WEBADE_AUTH_ENDPOINT
                  value: ''
                - name: WEBADE_USERNAME
                  value: ''
                - name: WEBADE_PASSWORD
                  value: ''
                - name: TTLS_API_ENDPOINT
                  value: ''
              image: docker-registry.default.svc:5000/nrts-prc-tools/nrts-prc-api:master
              command:
                - bash
                - -c
                - 'npm install --prefix seed/ &&
                  node seed/shapesMigration/updateShapes.js "${API_USERNAME}" "${API_PASSWORD}" "${API_PROTOCOL}" "${API_HOST}" "${API_PORT}" "${CLIENT_ID}" "${GRANT_TYPE}" "${AUTH_ENDPOINT}";
                  if [ "${PIPESTATUS[0]}" -eq "0" ];
                  then curl -X POST -H "Content-type: application/json" --data "${JSON_PAYLOAD}" "${NOTIFICATION_URL}";
                  else curl -X POST -H "Content-type: application/json" --data "${JSON_PAYLOAD_FAIL}" "${NOTIFICATION_URL}";
                  fi;'
              imagePullPolicy: Always
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
  schedule: '1 2 * * *'
  startingDeadlineSeconds: 999
  suspend: false
