{{ if .Values.download.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: download
spec:
  schedule: "{{ .Values.download.schedule }}"
  suspend: {{ .Values.download.suspend }}
  timeZone: "{{ .Values.timeZone }}"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 604800 # 7 days
      backoffLimit: 0
      completions: 1
      parallelism: 1
      template:
        spec:
          imagePullSecrets:
          - name: regcred
          containers:
          - name: model
            image: goalprofit/{{ .Values.download.image }}
            imagePullPolicy: Always
            volumeMounts:
 #           - mountPath: /raw
#              name: raw
            - mountPath: /in
              name: in
            - mountPath: /data
              name: data
            env:
              - name: SERVICE_LOGIN
                valueFrom:
                  secretKeyRef:
                    name: secret-service
                    key: username
                    optional: false
              - name: SERVICE_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: secret-service
                    key: password
                    optional: false
            {{- range $param := .Values.download.env }}
              - name: {{ $param.name }}
                valueFrom:
                  secretKeyRef:
                    name: {{ $param.secret }}
                    key: {{ $param.key }}
            {{- end }}

        {{ if .Values.local_user_id }}
              - name: LOCAL_USER_ID
                value: "{{.Values.local_user_id}}"
      {{ end }}
      {{ if .Values.local_user_name }}
              - name: LOCAL_USER_NAME
                value: "{{.Values.local_user_name}}"
      {{ end }}
          restartPolicy: Never
          volumes:
          - name: in
            hostPath:
              path: /data/{{.Values.customer}}/in
              type: Directory
#              readOnly: true
#          - name: raw
#            hostPath:
#              path: /data/{{.Values.customer}}/raw
#              type: Directory
#              readOnly: true
          - name: data
            hostPath:
              path: /data/{{.Values.customer}}/data
              type: Directory
#              readOnly: true
          {{ include "app.affinity" . | nindent 10}}
{{ end }}