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

apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
  name: {{ include "mysql.primary.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: mysql
    app.kubernetes.io/component: primary
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  replicas: 1
  podManagementPolicy: {{ .Values.primary.podManagementPolicy | quote }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.primary.podLabels .Values.commonLabels ) "context" . ) }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
      app.kubernetes.io/part-of: mysql
      app.kubernetes.io/component: primary
  serviceName: {{ printf "%s-headless" (include "mysql.primary.fullname" .) | trunc 63 | trimSuffix "-" }}
  {{- if .Values.primary.updateStrategy }}
  updateStrategy: {{- toYaml .Values.primary.updateStrategy | nindent 4 }}
  {{- end }}
  template:
    metadata:
      annotations:
        {{- if (include "mysql.primary.createConfigmap" .) }}
        checksum/configuration: {{ include (print $.Template.BasePath "/primary/configmap.yaml") . | sha256sum }}
        {{- end }}
        {{- if .Values.passwordUpdateJob.enabled }}
        charts.bitnami.com/password-last-update: {{ now | date "20060102150405" | quote }}
        {{- end }}
        {{- if .Values.primary.podAnnotations }}
        {{- include "common.tplvalues.render" (dict "value" .Values.primary.podAnnotations "context" $) | nindent 8 }}
        {{- end }}
      labels: {{- include "common.labels.standard" ( dict "customLabels" $podLabels "context" $ ) | nindent 8 }}
        app.kubernetes.io/part-of: mysql
        app.kubernetes.io/component: primary
    spec:
      {{- if .Values.primary.extraPodSpec }}
      {{- include "common.tplvalues.render" (dict "value" .Values.primary.extraPodSpec "context" $) | nindent 6 }}
      {{- end }}
      serviceAccountName: {{ template "mysql.serviceAccountName" . }}
      {{- include "mysql.imagePullSecrets" . | nindent 6 }}
      automountServiceAccountToken: {{ .Values.primary.automountServiceAccountToken }}
      {{- if .Values.primary.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.primary.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.primary.affinity }}
      affinity: {{- include "common.tplvalues.render" (dict "value" .Values.primary.affinity "context" $) | nindent 8 }}
      {{- else }}
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.primary.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.primary.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.primary.nodeAffinityPreset.type "key" .Values.primary.nodeAffinityPreset.key "values" .Values.primary.nodeAffinityPreset.values) | nindent 10 }}
      {{- end }}
      {{- if .Values.primary.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.primary.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.primary.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.primary.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.primary.priorityClassName }}
      priorityClassName: {{ .Values.primary.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.primary.runtimeClassName }}
      runtimeClassName: {{ .Values.primary.runtimeClassName | quote }}
      {{- end }}
      {{- if .Values.primary.schedulerName }}
      schedulerName: {{ .Values.primary.schedulerName | quote }}
      {{- end }}
      {{- if .Values.primary.topologySpreadConstraints }}
      topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.primary.topologySpreadConstraints "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.primary.podSecurityContext.enabled }}
      securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.primary.podSecurityContext "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.primary.terminationGracePeriodSeconds }}
      terminationGracePeriodSeconds: {{ .Values.primary.terminationGracePeriodSeconds }}
      {{- end }}
      {{- if or .Values.primary.enableDefaultInitContainers .Values.primary.initContainers }}
      initContainers:
        {{- if .Values.primary.enableDefaultInitContainers }}
        - name: preserve-logs-symlinks
          image: {{ include "mysql.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          {{- if .Values.primary.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.primary.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.primary.resources }}
          resources: {{ toYaml .Values.primary.resources | nindent 12 }}
          {{- else if ne .Values.primary.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.primary.resourcesPreset) | nindent 12 }}
          {{- end }}
          command:
            - /bin/bash
          args:
            - -ec
            - |
              #!/bin/bash

              . /opt/bitnami/scripts/libfs.sh
              # We copy the logs folder because it has symlinks to stdout and stderr
              if ! is_dir_empty /opt/bitnami/mysql/logs; then
                cp -r /opt/bitnami/mysql/logs /emptydir/app-logs-dir
              fi
          volumeMounts:
            - name: empty-dir
              mountPath: /emptydir
        {{- if and .Values.primary.podSecurityContext.enabled .Values.volumePermissions.enabled .Values.primary.persistence.enabled }}
        - name: volume-permissions
          image: {{ include "mysql.volumePermissions.image" . }}
          imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
          command:
            - /bin/bash
            - -ec
            - |
              mkdir -p "/bitnami/mysql"
              chown "{{ .Values.primary.containerSecurityContext.runAsUser }}:{{ .Values.primary.podSecurityContext.fsGroup }}" "/bitnami/mysql"
              find "/bitnami/mysql" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | xargs -r chown -R "{{ .Values.primary.containerSecurityContext.runAsUser }}:{{ .Values.primary.podSecurityContext.fsGroup }}"
          securityContext:
            runAsUser: 0
          {{- if .Values.volumePermissions.resources }}
          resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
          {{- else if ne .Values.volumePermissions.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.volumePermissions.resourcesPreset) | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: data
              mountPath: /bitnami/mysql
              {{- if .Values.primary.persistence.subPath }}
              subPath: {{ .Values.primary.persistence.subPath }}
              {{- end }}
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
        {{- end }}
        {{- end }}
        {{- if .Values.primary.initContainers }}
        {{- include "common.tplvalues.render" (dict "value" .Values.primary.initContainers "context" $) | nindent 8 }}
        {{- end }}
      {{- end }}
      containers:
        - name: mysql
          image: {{ include "mysql.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          {{- if .Values.primary.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.primary.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
          {{- else if .Values.primary.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.primary.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
          {{- else if .Values.primary.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.primary.args "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.primary.lifecycleHooks }}
          lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.primary.lifecycleHooks "context" $) | nindent 12 }}
          {{- end }}
          env:
            - name: BITNAMI_DEBUG
              value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
            {{- if .Values.auth.usePasswordFiles }}
            - name: MYSQL_ROOT_PASSWORD_FILE
              value: {{ default "/opt/bitnami/mysql/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
            {{- else }}
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "mysql.secretName" . }}
                  key: mysql-root-password
            {{- end }}
            - name: MYSQL_ENABLE_SSL
              value: {{ ternary "yes" "no" .Values.tls.enabled | quote }}
            {{- if and .Values.tls.enabled (include "mysql.tlsCACert" .) }}
            - name: MYSQL_CLIENT_CA_FILE
              value: {{ include "mysql.tlsCACert" . | quote }}
            {{- end }}
            {{- if not (empty .Values.auth.username) }}
            - name: MYSQL_USER
              value: {{ .Values.auth.username | quote }}
            {{- if .Values.auth.usePasswordFiles }}
            - name: MYSQL_PASSWORD_FILE
              value: {{ default "/opt/bitnami/mysql/secrets/mysql-password" .Values.auth.customPasswordFiles.user }}
            {{- else }}
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "mysql.secretName" . }}
                  key: mysql-password
            {{- end }}
            {{- end }}
            - name: MYSQL_PORT
              value: {{ .Values.primary.containerPorts.mysql | quote}}
            {{- if and .Values.auth.createDatabase .Values.auth.database }}
            - name: MYSQL_DATABASE
              value: {{ .Values.auth.database | quote }}
            {{- end }}
            {{- if eq .Values.architecture "replication" }}
            - name: MYSQL_REPLICATION_MODE
              value: "master"
            - name: MYSQL_REPLICATION_USER
              value: {{ .Values.auth.replicationUser | quote }}
            {{- if .Values.auth.usePasswordFiles }}
            - name: MYSQL_REPLICATION_PASSWORD_FILE
              value: {{ default "/opt/bitnami/mysql/secrets/mysql-replication-password" .Values.auth.customPasswordFiles.replicator }}
            {{- else }}
            - name: MYSQL_REPLICATION_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "mysql.secretName" . }}
                  key: mysql-replication-password
            {{- end }}
            {{- end }}
            {{- if .Values.primary.extraFlags }}
            - name: MYSQL_EXTRA_FLAGS
              value: "{{ .Values.primary.extraFlags }}"
            {{- end }}
            {{- if .Values.primary.extraEnvVars }}
            {{- include "common.tplvalues.render" (dict "value" .Values.primary.extraEnvVars "context" $) | nindent 12 }}
            {{- end }}
          envFrom:
            {{- if .Values.primary.extraEnvVarsCM }}
            - configMapRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.primary.extraEnvVarsCM "context" $) }}
            {{- end }}
            {{- if .Values.primary.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.primary.extraEnvVarsSecret "context" $) }}
            {{- end }}
          ports:
            - name: mysql
              containerPort: {{ .Values.primary.containerPorts.mysql }}
            {{- if .Values.secondary.enableMySQLX }}
            - name: mysqlx
              containerPort: {{ .Values.primary.containerPorts.mysqlx }}
            {{- end }}
            {{- if .Values.primary.extraPorts }}
            {{- include "common.tplvalues.render" (dict "value" .Values.primary.extraPorts "context" $) | nindent 12 }}
            {{- end }}
          {{- if not .Values.diagnosticMode.enabled }}
          {{- if .Values.primary.customLivenessProbe }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.primary.customLivenessProbe "context" $) | nindent 12 }}
          {{- else if .Values.primary.livenessProbe.enabled }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.primary.livenessProbe "enabled") "context" $) | nindent 12 }}
            exec:
              command:
                - /bin/bash
                - -ec
                - |
                  password_aux="${MYSQL_ROOT_PASSWORD:-}"
                  if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
                      password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
                  fi
                  mysqladmin status -uroot -p"${password_aux}"
          {{- end }}
          {{- if .Values.primary.customReadinessProbe }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.primary.customReadinessProbe "context" $) | nindent 12 }}
          {{- else if .Values.primary.readinessProbe.enabled }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.primary.readinessProbe "enabled") "context" $) | nindent 12 }}
            exec:
              command:
                - /bin/bash
                - -ec
                - |
                  password_aux="${MYSQL_ROOT_PASSWORD:-}"
                  if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
                      password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
                  fi
                  mysqladmin ping -uroot -p"${password_aux}" | grep "mysqld is alive"
          {{- end }}
          {{- if .Values.primary.customStartupProbe }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.primary.customStartupProbe "context" $) | nindent 12 }}
          {{- else if .Values.primary.startupProbe.enabled }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.primary.startupProbe "enabled") "context" $) | nindent 12 }}
            exec:
              command:
                - /bin/bash
                - -ec
                - |
                  password_aux="${MYSQL_ROOT_PASSWORD:-}"
                  if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
                      password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
                  fi
                  mysqladmin ping -uroot -p"${password_aux}" | grep "mysqld is alive"
          {{- end }}
          {{- end }}
          {{- if .Values.primary.resources }}
          resources: {{ toYaml .Values.primary.resources | nindent 12 }}
          {{- else if ne .Values.primary.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.primary.resourcesPreset) | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: data
              mountPath: /bitnami/mysql
              {{- if .Values.primary.persistence.subPath }}
              subPath: {{ .Values.primary.persistence.subPath }}
              {{- end }}
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
            - name: empty-dir
              mountPath: /opt/bitnami/mysql/conf
              subPath: app-conf-dir
            - name: empty-dir
              mountPath: /opt/bitnami/mysql/tmp
              subPath: app-tmp-dir
            - name: empty-dir
              mountPath: /opt/bitnami/mysql/logs
              subPath: app-logs-dir
            {{- if .Values.tls.enabled }}
            - name: cert
              mountPath: /opt/bitnami/mysql/certs
            {{- end }}
            {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
            - name: custom-init-scripts
              mountPath: /docker-entrypoint-initdb.d
            {{- end }}
            {{- if or .Values.startdbScriptsConfigMap .Values.startdbScripts }}
            - name: custom-start-scripts
              mountPath: /docker-entrypoint-startdb.d
            {{- end }}
            {{- if or .Values.primary.configuration .Values.primary.existingConfigmap }}
            - name: config
              mountPath: /opt/bitnami/mysql/conf/my.cnf
              subPath: my.cnf
            {{- end }}
            {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
            - name: mysql-credentials
              mountPath: /opt/bitnami/mysql/secrets/
            {{- end }}
            {{- if .Values.primary.extraVolumeMounts }}
            {{- include "common.tplvalues.render" (dict "value" .Values.primary.extraVolumeMounts "context" $) | nindent 12 }}
            {{- end }}
        {{- if .Values.metrics.enabled }}
        - name: metrics
          image: {{ include "mysql.metrics.image" . }}
          imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
          {{- if .Values.metrics.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.metrics.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          env:
            {{- if .Values.auth.usePasswordFiles }}
            - name: MYSQL_ROOT_PASSWORD_FILE
              value: {{ default "/opt/bitnami/mysqld-exporter/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
            {{- else }}
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "mysql.secretName" . }}
                  key: mysql-root-password
            {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
          {{- else }}
          command:
            - /bin/bash
            - -ec
            - |
              password_aux="${MYSQL_ROOT_PASSWORD:-}"
              if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
                  password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
              fi
              MYSQLD_EXPORTER_PASSWORD=${password_aux} /bin/mysqld_exporter --mysqld.address=localhost:3306 --mysqld.username=root --web.listen-address=:{{ .Values.metrics.containerPorts.http }} {{- range .Values.metrics.extraArgs.primary }} {{ . }} {{- end }}
          {{- end }}
          ports:
            - name: metrics
              containerPort: {{ .Values.metrics.containerPorts.http }}
          {{- if not .Values.diagnosticMode.enabled }}
          {{- if .Values.metrics.livenessProbe.enabled }}
          livenessProbe: {{- omit .Values.metrics.livenessProbe "enabled" | toYaml | nindent 12 }}
            httpGet:
              path: /metrics
              port: metrics
          {{- end }}
          {{- if .Values.metrics.readinessProbe.enabled }}
          readinessProbe: {{- omit .Values.metrics.readinessProbe "enabled" | toYaml | nindent 12 }}
            httpGet:
              path: /metrics
              port: metrics
          {{- end }}
          {{- end }}
          {{- if .Values.metrics.resources }}
          resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
          {{- else if ne .Values.metrics.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.metrics.resourcesPreset) | nindent 12 }}
          {{- end }}
          volumeMounts:
          {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
            - name: mysql-credentials
              mountPath: /opt/bitnami/mysqld-exporter/secrets/
          {{- end }}
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
        {{- end }}
        {{- if .Values.primary.sidecars }}
        {{- include "common.tplvalues.render" (dict "value" .Values.primary.sidecars "context" $) | nindent 8 }}
        {{- end }}
      volumes:
        {{- if or .Values.primary.configuration .Values.primary.existingConfigmap }}
        - name: config
          configMap:
            name: {{ include "mysql.primary.configmapName" . }}
        {{- end }}
        {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
        - name: custom-init-scripts
          configMap:
            name: {{ include "mysql.initdbScriptsCM" . }}
        {{- end }}
        {{- if or .Values.startdbScriptsConfigMap .Values.startdbScripts }}
        - name: custom-start-scripts
          configMap:
            name: {{ include "mysql.startdbScriptsCM" . }}
        {{- end }}
        {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
        - name: mysql-credentials
          secret:
            secretName: {{ include "mysql.secretName" . }}
            items:
              - key: mysql-root-password
                path: mysql-root-password
              - key: mysql-password
                path: mysql-password
              {{- if eq .Values.architecture "replication" }}
              - key: mysql-replication-password
                path: mysql-replication-password
              {{- end }}
        {{- end }}
        {{- if .Values.tls.enabled }}
        - name: cert
          secret:
            secretName: {{ include "mysql.tlsSecretName" . }}
            defaultMode: 256
        {{- end }}
        - name: empty-dir
          emptyDir: {}
        {{- if .Values.primary.extraVolumes }}
        {{- include "common.tplvalues.render" (dict "value" .Values.primary.extraVolumes "context" $) | nindent 8 }}
        {{- end }}
  {{- if and .Values.primary.persistence.enabled .Values.primary.persistence.existingClaim }}
        - name: data
          persistentVolumeClaim:
            claimName: {{ tpl .Values.primary.persistence.existingClaim . }}
  {{- else if not .Values.primary.persistence.enabled }}
        - name: data
          emptyDir: {}
  {{- else if and .Values.primary.persistence.enabled (not .Values.primary.persistence.existingClaim) }}
  {{- if .Values.primary.persistentVolumeClaimRetentionPolicy.enabled }}
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: {{ .Values.primary.persistentVolumeClaimRetentionPolicy.whenDeleted }}
    whenScaled: {{ .Values.primary.persistentVolumeClaimRetentionPolicy.whenScaled }}
  {{- end }}
  volumeClaimTemplates:
    - metadata:
        name: data
        labels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 10 }}
          app.kubernetes.io/component: primary
        {{- if or .Values.primary.persistence.annotations .Values.commonAnnotations }}
        {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list  .Values.primary.persistence.annotations .Values.commonAnnotations ) "context" . ) }}
        annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 10 }}
        {{- end }}
      spec:
        accessModes:
          {{- range .Values.primary.persistence.accessModes }}
          - {{ . | quote }}
          {{- end }}
        resources:
          requests:
            storage: {{ .Values.primary.persistence.size | quote }}
        {{- include "common.storage.class" (dict "persistence" .Values.primary.persistence "global" .Values.global) | nindent 8 }}
        {{- if .Values.primary.persistence.selector }}
        selector: {{- include "common.tplvalues.render" (dict "value" .Values.primary.persistence.selector "context" $) | nindent 10 }}
        {{- end -}}
  {{- end }}
