apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ include "mail-mta-autoconfig.fullname" . }}
  labels:
    {{- include "mail-mta-autoconfig.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.schedule }}"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template: 
        metadata:
          labels:
            {{- include "mail-mta-autoconfig.selectorLabels" . | nindent 12 }}
        spec:
          serviceAccountName: {{ include "mail-mta-autoconfig.serviceAccountName" . }}
          {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          securityContext:
            {{- toYaml .Values.podSecurityContext | nindent 12 }}
          restartPolicy: OnFailure
          containers:
            - name: {{ .Release.Name }}
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              command: [ "python3", "watch.py" ]
        {{ if .Values.secretName }}
              volumeMounts:
                - mountPath: "/root/.env"
                  name: envfile
                  subPath: .env
                  readOnly: true
          volumes:
            - name: envfile
              secret:
                secretName: {{ .Values.secretName }}
        {{ end }}
          {{- with .Values.nodeSelector }}
          nodeSelector:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.tolerations }}
          tolerations:
            {{- toYaml . | nindent 12 }}
          {{- end }}