# SPDX-License-Identifier: Apache-2.0
# Copyright 2023 The HuggingFace Authors.

{{- if and .Values.images.jobs.cacheMaintenance .Values.cacheMetricsCollector.enabled}}
apiVersion: batch/v1
kind: CronJob
metadata:
  labels: {{ include "labels.cacheMetricsCollector" . | nindent 4 }}
  name: "{{ include "name" . }}-job-cache-metrics-collector"
  namespace: {{ .Release.Namespace }}
spec:
  schedule: {{ .Values.cacheMetricsCollector.schedule | quote }}
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 3600
      template:
        spec:
          restartPolicy: OnFailure
          {{- include "dnsConfig" . | nindent 10 }}
          {{- include "image.imagePullSecrets" . | nindent 6 }}
          nodeSelector: {{ toYaml .Values.cacheMetricsCollector.nodeSelector | nindent 12 }}
          tolerations: {{ toYaml .Values.cacheMetricsCollector.tolerations | nindent 12 }}
          containers: {{ include "containerCacheMetricsCollector" . | nindent 12 }}
          securityContext: {{ include "securityContext" . | nindent 12 }}
{{- end}}
