apiVersion: batch/v1
kind: CronJob
metadata:
  name: {{ include "restic-helm.fullname" . }}
  labels:
    {{- include "restic-helm.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.schedule }}"
  jobTemplate:
    metadata:
      {{- with .Values.jobAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "restic-helm.labels" . | nindent 8 }}
    spec:
      template:
        metadata:
          {{- with .Values.podAnnotations }}
          annotations:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          labels:
            {{- include "restic-helm.labels" . | nindent 12 }}
        spec:
          {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          securityContext:
            {{- toYaml .Values.podSecurityContext | nindent 12 }}
          volumes:
            - name: data
              {{- .Values.volume | nindent 14 }}
          containers:
            - name: {{ .Chart.Name }}
              securityContext:
                {{- toYaml .Values.securityContext | nindent 16 }}
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              workingDir: "/sync"
              args:
                - "-r"
                - "{{ .Values.repository.name }}"
                - "backup"
                - "."
              envFrom:
                - secretRef:
                    name: {{ include "restic-helm.fullname" . }}
              resources:
                {{- toYaml .Values.resources | nindent 16 }}
              volumeMounts:
                - mountPath: "/sync"
                  name: data
          {{- with .Values.nodeSelector }}
          nodeSelector:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.affinity }}
          affinity:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.tolerations }}
          tolerations:
            {{- toYaml . | nindent 12 }}
          {{- end }}
