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

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