apiVersion: batch/v1
kind: CronJob
metadata:
  name: {{ include "seafile-helm.fullname" . }}
  labels:
    {{- include "seafile-helm.labels" . | nindent 4 }}
spec:
  concurrencyPolicy: Forbid
  schedule: "{{ .Values.schedule }}"
  suspend: {{ .Values.suspend }}
  jobTemplate:
    metadata:
      {{- with .Values.jobAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "seafile-helm.labels" . | nindent 8 }}
    spec:
      template:
        metadata:
          {{- with .Values.podAnnotations }}
          annotations:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          labels:
            {{- include "seafile-helm.labels" . | nindent 12 }}
        spec:
          restartPolicy: OnFailure
          {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          securityContext:
            {{- toYaml .Values.podSecurityContext | nindent 12 }}
          volumes:
            - name: seafile
              {{- .Values.seafile.volume | nindent 14 }}
            - name: config
              secret:
                secretName: {{ include "seafile-helm.fullname" . }}
            - name: tmp
              emptyDir: {}
          containers:
            - name: seafile
              command:
                - "seafserv-gc"
              args:
                - "-c"
                - "/conf"
                - "-d"
                - "/data"
              securityContext:
                {{- toYaml .Values.securityContext | nindent 16 }}
              image: "{{ .Values.image.repository }}:server-{{ .Values.image.tag | default .Chart.AppVersion }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              ports:
                - name: seafhttp
                  containerPort: 8082
                  protocol: TCP
              startupProbe:
                tcpSocket:
                  port: seafhttp
              livenessProbe:
                tcpSocket:
                  port: seafhttp
              readinessProbe:
                tcpSocket:
                  port: seafhttp
              resources:
                {{- toYaml .Values.resources | nindent 16 }}
              volumeMounts:
                - mountPath: "/data"
                  name: seafile
                - mountPath: "/conf"
                  name: config
                - mountPath: "/tmp"
                  name: tmp
          {{- with .Values.nodeSelector }}
          nodeSelector:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.affinity }}
          affinity:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.tolerations }}
          tolerations:
            {{- toYaml . | nindent 12 }}
          {{- end }}
