apiVersion: batch/v1
kind: CronJob
metadata:
  name: octodns-cronjob
spec:
  schedule: "0 */6 * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      backoffLimit: 0

      template:
        spec:
          initContainers:
            - name: git
              image: git
              command: ["git"]
              args:
                - clone
                - https://git.kluster.moll.re/remoll/dns.git
                - /etc/octodns
              volumeMounts:
                - name: octodns-config
                  mountPath: /etc/octodns
          containers:
            - name: octodns
              image: octodns
              env:
                # - name: CLOUDFLARE_ACCOUNT_ID
                #   valueFrom:
                #     secretKeyRef:
                #       name: cloudflare-api
                #       key: CLOUDFLARE_ACCOUNT_ID
                - name: CLOUDFLARE_TOKEN
                  valueFrom:
                    secretKeyRef:
                      name: cloudflare-api
                      key: CLOUDFLARE_TOKEN
                # - name: CLOUDFLARE_EMAIL
                #   valueFrom:
                #     secretKeyRef:
                #       name: cloudflare-api
                #       key: CLOUDFLARE_EMAIL

              command: ["/bin/sh", "-c"]
              args:
                - >-
                  cd /etc/octodns
                  &&
                  pip install -r ./requirements.txt
                  &&
                  octodns-sync --config-file ./config.yaml --doit
                  &&
                  echo "done..."
              volumeMounts:
                - name: octodns-config
                  mountPath: /etc/octodns

          volumes:
          - name: octodns-config
            emptyDir: {}
          restartPolicy: Never