{{- $kubefullname := include "k8s-token-rotate.fullname" . }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ include "k8s-token-rotate.fullname" . }}
  labels:
    {{- include "k8s-token-rotate.labels" . | nindent 4 }}
spec:
  schedule: {{ .Values.schedule | quote }}
  concurrencyPolicy: Replace
  failedJobsHistoryLimit: 3
  successfulJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: k8s-token-rotate
              image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              env:
              {{ range $key, $value := .Values.environmentVariables -}}
              - name: "{{ $key }}"
                valueFrom:
                  secretKeyRef:
                    name: {{ $kubefullname }}
                    key: {{ $key }}
              {{ end }}
              resources:
              {{- toYaml .Values.engineResources | nindent 16 }}
          restartPolicy: OnFailure