{{- $app := .Values.server }}
{{- $pvc := $app.persistentVolume }}
{{- if and $pvc.enabled (not $pvc.existingClaim) (eq $app.mode "deployment") -}}
{{- $ctx := dict "helm" . "appKey" "server" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
---
kind: PersistentVolumeClaim
apiVersion: v1
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 }}
