{{/* Define the cronjob */}}
{{- define "nextcloud.cronjob" -}}
{{- $jobName := include "common.names.fullname" . -}}

---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ printf "%s-cronjob" $jobName }}
  labels:
    {{- include "common.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.cronjob.schedule }}"
  concurrencyPolicy: Forbid
  {{- with .Values.cronjob.failedJobsHistoryLimit }}
  failedJobsHistoryLimit: {{ . }}
  {{- end }}
  {{- with .Values.cronjob.successfulJobsHistoryLimit }}
  successfulJobsHistoryLimit: {{ . }}
  {{- end }}
  jobTemplate:
    metadata:
    spec:
      template:
        metadata:
        spec:
          restartPolicy: Never
          {{- with (include "common.controller.volumes" . | trim) }}
          volumes:
            {{- nindent 12 . }}
          {{- end }}
          containers:
            - name: {{ .Chart.Name }}
              image: "{{ .Values.image.repository }}:{{ default .Values.image.tag }}"
              imagePullPolicy: {{ default .Values.image.pullPolicy }}
              command: [ "php" ]
              args:
                - "-f"
                - "/var/www/html/cron.php"
              # Will mount configuration files as www-data (id: 33) by default for nextcloud
              {{- with (include "common.controller.volumeMounts" . | trim) }}
              volumeMounts:
                {{ nindent 16 . }}
              {{- end }}
              securityContext:
                runAsUser: 33
                runAsGroup: 33
              resources:
{{ toYaml .Values.resources | indent 16 }}

{{- end -}}
