{{ if .Values.temperature_forecast.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: temperature-forecast
spec:
  schedule: "{{ .Values.temperature_forecast.schedule }}"
  suspend: {{ .Values.temperature_forecast.suspend }}
  timeZone: "{{ .Values.timeZone }}"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 3600 # 1 hpur
      backoffLimit: 0
      completions: 1
      parallelism: 1
      template:
        spec:
          imagePullSecrets:
          - name: regcred
          containers:
          - name: temperature-forecast
            image: goalprofit/temperature-forecast:{{ .Values.temperature_forecast.version }}
            imagePullPolicy: Always
            volumeMounts:
            - mountPath: /in
              name: in
            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

        {{ 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
          {{ include "app.affinity" . | nindent 10}}
{{ end }}