{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.tracking.enabled .Values.tracking.persistence.enabled (not .Values.tracking.persistence.existingClaim) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{ include "mlflow.v0.tracking.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.tracking.persistence.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: mlflow
    app.kubernetes.io/component: tracking
  {{- if or .Values.tracking.persistence.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.tracking.persistence.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  accessModes:
  {{- if not (empty .Values.tracking.persistence.accessModes) }}
  {{- range .Values.tracking.persistence.accessModes }}
    - {{ . | quote }}
  {{- end }}
  {{- else }}
    - {{ .Values.tracking.persistence.accessMode | quote }}
  {{- end }}
  resources:
    requests:
      storage: {{ .Values.tracking.persistence.size | quote }}
  {{- if .Values.tracking.persistence.selector }}
  selector: {{- include "common.tplvalues.render" (dict "value" .Values.tracking.persistence.selector "context" $) | nindent 4 }}
  {{- end -}}
  {{- include "common.storage.class" (dict "persistence" .Values.tracking.persistence "global" .Values.global) | nindent 2 }}
  {{- if .Values.tracking.persistence.dataSource }}
  dataSource: {{- include "common.tplvalues.render" (dict "value" .Values.tracking.persistence.dataSource "context" $) | nindent 4 }}
  {{- end }}
{{- end }}
