apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: aws-ecr-credentials-updater-cron
spec:
  # Every 6 hours
  schedule: "0 */6 * * *"
  successfulJobsHistoryLimit: 2
  failedJobsHistoryLimit: 2
  jobTemplate:
    spec:
      backoffLimit: 4
      template:
        spec:
          serviceAccountName: aws-ecr-credentials-updater-service-account
          terminationGracePeriodSeconds: 0
          restartPolicy: Never
          containers:
            - name: rancher-registry-credentials-generator
              imagePullPolicy: Always
              image: meappy/rancher-registry-credentials-generator:latest
              command:
                - "/run.sh"
              env:
                - name: AWS_ACCOUNT
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: aws-account
                - name: AWS_REGION
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: aws-region
                - name: AWS_ACCESS_KEY_ID
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: aws-access-key-id
                - name: AWS_SECRET_ACCESS_KEY
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: aws-secret-access-key
                - name: RANCHER_ACCESS_KEY
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: rancher-access-key
                - name: RANCHER_SECRET_KEY
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: rancher-secret-key
                - name: REGISTRY_USERNAME
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: registry-username
                - name: REGISTRY_SECRET
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: registry-secret
                - name: RANCHER_PROJECT_ID
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: rancher-project-id
                - name: RANCHER_URL
                  valueFrom:
                    secretKeyRef:
                      name: aws-ecr-credentials-updater-secrets
                      key: rancher-url
