{{- if .Values.taskCollector.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: task-collector
  namespace: observability
spec:
  concurrencyPolicy: Allow
  failedJobsHistoryLimit: {{ .Values.taskCollector.failedJobsHistoryLimit }}
  jobTemplate:
    spec:
      template:
{{- with .Values.taskCollector.podLabels }}
        metadata:
          labels:
{{ toYaml . | indent 12 }}
{{- end }}
        spec:
          containers:
            - args:
                - -region
                - {{ .Values.taskCollector.region }}
                - -vendor
                - {{ .Values.taskCollector.vendor }}
                - -account
                - {{ .Values.taskCollector.account | quote }}
{{- with .Values.taskCollector.extraArgs }}
{{ toYaml . | indent 16 }}
{{- end }}
              image: "{{ .Values.taskCollector.image.repository }}:{{ .Values.taskCollector.image.tag }}"
              imagePullPolicy: {{ .Values.taskCollector.image.pullPolicy }}
              name: task-collector
              resources:
{{ toYaml .Values.taskCollector.resources | indent 16 }}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
{{- with .Values.taskCollector.env }}
              env:
{{ toYaml . | indent 16 }}
{{- end }}
{{- with .Values.taskCollector.volumeMounts }}
              volumeMounts:
{{ toYaml . | indent 16 }}
{{- end }}
          dnsPolicy: ClusterFirst
          nodeSelector:
{{ toYaml .Values.taskCollector.nodeSelector | indent 12 }}
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          serviceAccount: {{ .Values.taskCollector.serviceAccountName }}
          serviceAccountName: {{ .Values.taskCollector.serviceAccountName }}
          terminationGracePeriodSeconds: 30
{{- with .Values.taskCollector.volumes }}
          volumes:
{{ toYaml . | indent 12 }}
{{- end }}
      ttlSecondsAfterFinished: {{ .Values.taskCollector.ttlSecondsAfterFinished }}
  schedule: {{ .Values.taskCollector.schedule | quote }}
  successfulJobsHistoryLimit: {{ .Values.taskCollector.successfulJobsHistoryLimit }}
  suspend: false
{{- end }}
