{{ if .Values.loki_pruner.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: loki-pruner
spec:
  schedule: "{{ .Values.loki_pruner.schedule }}"
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 600
      backoffLimit: 1
      concurrencyPolicy: Forbid
      template:
        spec:
          restartPolicy: Never
          terminationGracePeriodSeconds: 1
          imagePullSecrets:
          - name: regcred
          containers:
          - name: loki-pruner
            image: docker.io/goalprofit/file-remover:{{ .Values.loki_pruner.version }}
            imagePullPolicy: Always
            volumeMounts:
            - mountPath: /work
              name: work
              subPath: data/loki-stack/chunks/fake
            env:
              - name: MAX_SIZE
                value: {{.Values.loki_pruner.max_size}}
              - name: TARGET_DIR
                value: {{.Values.loki_pruner.target_dir}}
          volumes:
          - name: work
            {{ include "app.customer_volume" . | nindent 12}}
          {{ include "app.affinity" . | nindent 10}}
{{ end }}