{{- $app := .Values }}
{{- $pvc := $app.persistentVolume }}
{{- if and $pvc.enabled (not $pvc.existingClaim) (eq $app.mode "deployment") }}
{{- $ctx := dict "helm" . }}
{{- $fullname := include "vm.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ tpl ($pvc.name | default $fullname) $ctx }}
  namespace: {{ $ns }}
  {{- $_ := set $ctx "extraLabels" $pvc.extraLabels }}
  labels: {{ include "vm.labels" $ctx | nindent 4 }}
  {{- $_ := unset $ctx "extraLabels" }}
  {{- with $pvc.annotations  }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- with $pvc.accessModes }}
  accessModes: {{ toYaml . | nindent 4 }}
  {{- end }}
  {{- with $pvc.volumeAttributeClassName }}
  volumeAttributesClassName: {{ . }}
  {{- end }}
  resources:
    requests:
      storage: {{ $pvc.size }}
  {{- with $pvc.storageClassName }}
  storageClassName: {{ . }}
  {{- end -}}
  {{- with $pvc.matchLabels }}
  selector:
    matchLabels: {{ toYaml . | nindent 6 }}
  {{- end }}
{{- end }}
