apiVersion: batch/v1beta1
kind: CronJob
metadata:
  labels:
    app: vault-agent
    app.kubernetes.io/instance: bilby 
  name: secrets-integrator-bilby
  namespace: gwcloud
spec:
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 5
  jobTemplate:
    metadata:
      labels:
        app: vault-kube-integrator
    spec:
      backoffLimit: 1
      template:
        metadata:
          annotations:
            vault.hashicorp.com/agent-init-first: 'true'
            vault.hashicorp.com/agent-inject: 'true'
            vault.hashicorp.com/agent-inject-secret-bilby.yaml: gwcloud/kv/bilby
            vault.hashicorp.com/agent-inject-template-bilby.yaml: |
              {{- with secret "gwcloud/kv/bilby" -}}
              apiVersion: v1
              kind: Secret
              type: Opaque
              stringData:
                {{ range $k, $v := .Data.data }}
                {{ $k }}: {{ $v }}
                {{ end }}
              metadata:
                namespace: gwcloud
                name: bilby 
              {{- end }}
            vault.hashicorp.com/agent-pre-populate-only: 'true'
            vault.hashicorp.com/role: bilby
        spec:
          containers:
            - command:
                - kubectl
                - apply
                - '-f'
                - /vault/secrets/
              image: 'bitnami/kubectl:1.17.4'
              imagePullPolicy: IfNotPresent
              name: bilby-vault-kube-integrator
              resources: {}
          imagePullSecrets:
            - name: regcred
          restartPolicy: Never
          serviceAccountName: bilby 
  schedule: '* * * * *'
  successfulJobsHistoryLimit: 1
