{{ 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/loki-pruner:{{ .Values.loki_pruner.version }}
            imagePullPolicy: Always
            volumeMounts:
            - mountPath: /work
              name: customer
              subPath: data/loki-stack/chunks
            env:
              - name: MAX_SIZE
                value: {{.Values.loki_pruner.max_size}}
              - name: TARGET_DIR
                value: {{.Values.loki_pruner.target_dir}}
          volumes:
          - name: customer
          {{ include "app.customer_volume" . | nindent 10}}
          {{ include "app.affinity" . | nindent 8}}
{{ end }}
