apiVersion: batch/v1
kind: CronJob
metadata:
  name: charts-syncer
spec:
  schedule: "*/30 * * * *"
  # If a job is scheduled wait for it to finish
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: charts-syncer
            imagePullPolicy: Always
            image: gcr.io/bitnami-labs/charts-syncer:v0.14.0
            args: ["sync", "--config", "/charts-syncer.yaml", "-v", "4", "--latest-version-only"]
            env:
              # Helm Chart source repository credentials
              - name: SOURCE_REPO_AUTH_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: SOURCE_REPO_AUTH_USERNAME
              - name: SOURCE_REPO_AUTH_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: SOURCE_REPO_AUTH_PASSWORD
              # Helm Chart target repository credentials
              - name: TARGET_REPO_AUTH_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: TARGET_REPO_AUTH_USERNAME
              - name: TARGET_REPO_AUTH_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: TARGET_REPO_AUTH_PASSWORD
              # Container images source registry credentials
              - name: SOURCE_CONTAINERS_AUTH_REGISTRY
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: SOURCE_CONTAINERS_AUTH_REGISTRY
              - name: SOURCE_CONTAINERS_AUTH_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: SOURCE_CONTAINERS_AUTH_USERNAME
              - name: SOURCE_CONTAINERS_AUTH_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: SOURCE_CONTAINERS_AUTH_PASSWORD
              # Container images target registry credentials
              - name: TARGET_CONTAINERS_AUTH_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: TARGET_CONTAINERS_AUTH_USERNAME
              - name: TARGET_CONTAINERS_AUTH_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: charts-syncer-credentials
                    key: TARGET_CONTAINERS_AUTH_PASSWORD
            volumeMounts:
              - name: config
                mountPath: /charts-syncer.yaml
                subPath: charts-syncer.yaml
          restartPolicy: OnFailure
          volumes:
            - name: config
              configMap:
                name: charts-syncer-config
