{{ if .Values.lftp_mirror.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: lftp-mirror
spec:
  schedule: "{{ .Values.lftp_mirror.schedule }}"
  suspend: {{ .Values.lftp_mirror.suspend }}
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 60
      backoffLimit: 1
      template:
        spec:
          imagePullSecrets:
          - name: regcred
          containers:
          - name: lftp-mirror
            image: goalprofit/lftp-mirror:{{ .Values.lftp_mirror.version }}
            imagePullPolicy: Always
            workingDir: /in
            env:
{{ 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 }}
              - name: LOCAL_URL
                value: {{ .Values.lftp_mirror.local_url }}
              - name: FTP_URL
                value: {{ .Values.lftp_mirror.ftp_url }}
              - name: FTP_FOLDER
                value: {{ .Values.lftp_mirror.ftp_folder }}
              - name: FTP_USERNAME
                valueFrom:
                  secretKeyRef:
                    name: secret-lftp
                    key: username
                    optional: false
              - name: FTP_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: secret-lftp
                    key: password
                    optional: false
            volumeMounts:
            - mountPath: /in
              name: in
            - mountPath: /home
              name: home
          restartPolicy: Never
          volumes:
          - name: in
            hostPath:
              path: /data/{{.Values.customer}}/in/ext
              type: Directory
          - name: home
            hostPath:
              path: /home
              type: Directory
          {{ include "app.affinity" . | nindent 10}}
{{ end }}