J release changes
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / charts / postgresql / templates / read / statefulset.yaml
1 {{- if eq .Values.architecture "replication" }}
2 {{- $customUser := include "postgresql.username" . }}
3 apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
4 kind: StatefulSet
5 metadata:
6   name: {{ include "postgresql.readReplica.fullname" . }}
7   namespace: {{ .Release.Namespace | quote }}
8   labels: {{- include "common.labels.standard" . | nindent 4 }}
9     app.kubernetes.io/component: read
10     {{- if .Values.commonLabels }}
11     {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
12     {{- end }}
13     {{- if .Values.readReplicas.labels }}
14     {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.labels "context" $ ) | nindent 4 }}
15     {{- end }}
16   annotations:
17     {{- if .Values.commonAnnotations }}
18     {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
19     {{- end }}
20     {{- if .Values.readReplicas.annotations }}
21     {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.annotations "context" $ ) | nindent 4 }}
22     {{- end }}
23 spec:
24   replicas: {{ .Values.readReplicas.replicaCount }}
25   serviceName: {{ include "postgresql.readReplica.svc.headless" . }}
26   {{- if .Values.readReplicas.updateStrategy }}
27   updateStrategy: {{- toYaml .Values.readReplicas.updateStrategy | nindent 4 }}
28   {{- end }}
29   selector:
30     matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
31       app.kubernetes.io/component: read
32   template:
33     metadata:
34       name: {{ include "postgresql.readReplica.fullname" . }}
35       labels: {{- include "common.labels.standard" . | nindent 8 }}
36         app.kubernetes.io/component: read
37         {{- if .Values.commonLabels }}
38         {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
39         {{- end }}
40         {{- if .Values.readReplicas.podLabels }}
41         {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.podLabels "context" $ ) | nindent 8 }}
42         {{- end }}
43       annotations:
44         {{- if (include "postgresql.readReplicas.createExtendedConfigmap" .) }}
45         checksum/extended-configuration: {{ include (print $.Template.BasePath "/read/extended-configmap.yaml") . | sha256sum }}
46         {{- end }}
47         {{- if .Values.readReplicas.podAnnotations }}
48         {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.podAnnotations "context" $ ) | nindent 8 }}
49         {{- end }}
50     spec:
51       {{- if .Values.readReplicas.extraPodSpec }}
52       {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.extraPodSpec "context" $) | nindent 6 }}
53       {{- end }}
54       serviceAccountName: {{ include "postgresql.serviceAccountName" . }}
55       {{- include "postgresql.imagePullSecrets" . | nindent 6 }}
56       {{- if .Values.readReplicas.hostAliases }}
57       hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.hostAliases "context" $) | nindent 8 }}
58       {{- end }}
59       {{- if .Values.readReplicas.affinity }}
60       affinity: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.affinity "context" $) | nindent 8 }}
61       {{- else }}
62       affinity:
63         podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.readReplicas.podAffinityPreset "component" "read" "context" $) | nindent 10 }}
64         podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.readReplicas.podAntiAffinityPreset "component" "read" "context" $) | nindent 10 }}
65         nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.readReplicas.nodeAffinityPreset.type "key" .Values.readReplicas.nodeAffinityPreset.key "values" .Values.readReplicas.nodeAffinityPreset.values) | nindent 10 }}
66       {{- end }}
67       {{- if .Values.readReplicas.nodeSelector }}
68       nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.nodeSelector "context" $) | nindent 8 }}
69       {{- end }}
70       {{- if .Values.readReplicas.tolerations }}
71       tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.tolerations "context" $) | nindent 8 }}
72       {{- end }}
73       {{- if .Values.readReplicas.topologySpreadConstraints }}
74       topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.topologySpreadConstraints "context" $) | nindent 8 }}
75       {{- end }}
76       {{- if .Values.readReplicas.priorityClassName }}
77       priorityClassName: {{ .Values.readReplicas.priorityClassName }}
78       {{- end }}
79       {{- if .Values.readReplicas.schedulerName }}
80       schedulerName: {{ .Values.readReplicas.schedulerName | quote }}
81       {{- end }}
82       {{- if .Values.readReplicas.terminationGracePeriodSeconds }}
83       terminationGracePeriodSeconds: {{ .Values.readReplicas.terminationGracePeriodSeconds }}
84       {{- end }}
85       {{- if .Values.readReplicas.podSecurityContext.enabled }}
86       securityContext: {{- omit .Values.readReplicas.podSecurityContext "enabled" | toYaml | nindent 8 }}
87       {{- end }}
88       hostNetwork: {{ .Values.readReplicas.hostNetwork }}
89       hostIPC: {{ .Values.readReplicas.hostIPC }}
90       initContainers:
91         {{- if and .Values.tls.enabled (not .Values.volumePermissions.enabled) }}
92         - name: copy-certs
93           image: {{ include "postgresql.volumePermissions.image" . }}
94           imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
95           {{- if .Values.readReplicas.resources }}
96           resources: {{- toYaml .Values.readReplicas.resources | nindent 12 }}
97           {{- end }}
98           # We don't require a privileged container in this case
99           {{- if .Values.readReplicas.containerSecurityContext.enabled }}
100           securityContext: {{- omit .Values.readReplicas.containerSecurityContext "enabled" | toYaml | nindent 12 }}
101           {{- end }}
102           command:
103             - /bin/sh
104             - -ec
105             - |
106               cp /tmp/certs/* /opt/bitnami/postgresql/certs/
107               chmod 600 {{ include "postgresql.tlsCertKey" . }}
108           volumeMounts:
109             - name: raw-certificates
110               mountPath: /tmp/certs
111             - name: postgresql-certificates
112               mountPath: /opt/bitnami/postgresql/certs
113         {{- else if and .Values.volumePermissions.enabled (or .Values.readReplicas.persistence.enabled .Values.shmVolume.enabled) }}
114         - name: init-chmod-data
115           image: {{ include "postgresql.volumePermissions.image" . }}
116           imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
117           {{- if .Values.readReplicas.resources }}
118           resources: {{- toYaml .Values.readReplicas.resources | nindent 12 }}
119           {{- end }}
120           command:
121             - /bin/sh
122             - -ec
123             - |
124               {{- if .Values.readReplicas.persistence.enabled }}
125               {{- if eq ( toString ( .Values.volumePermissions.containerSecurityContext.runAsUser )) "auto" }}
126               chown `id -u`:`id -G | cut -d " " -f2` {{ .Values.readReplicas.persistence.mountPath }}
127               {{- else }}
128               chown {{ .Values.readReplicas.containerSecurityContext.runAsUser }}:{{ .Values.readReplicas.podSecurityContext.fsGroup }} {{ .Values.readReplicas.persistence.mountPath }}
129               {{- end }}
130               mkdir -p {{ .Values.readReplicas.persistence.mountPath }}/data {{- if (include "postgresql.mountConfigurationCM" .) }} {{ .Values.readReplicas.persistence.mountPath }}/conf {{- end }}
131               chmod 700 {{ .Values.readReplicas.persistence.mountPath }}/data {{- if (include "postgresql.mountConfigurationCM" .) }} {{ .Values.readReplicas.persistence.mountPath }}/conf {{- end }}
132               find {{ .Values.readReplicas.persistence.mountPath }} -mindepth 1 -maxdepth 1 {{- if not (include "postgresql.mountConfigurationCM" .) }} -not -name "conf" {{- end }} -not -name ".snapshot" -not -name "lost+found" | \
133               {{- if eq ( toString ( .Values.volumePermissions.containerSecurityContext.runAsUser )) "auto" }}
134                 xargs -r chown -R `id -u`:`id -G | cut -d " " -f2`
135               {{- else }}
136                 xargs -r chown -R {{ .Values.readReplicas.containerSecurityContext.runAsUser }}:{{ .Values.readReplicas.podSecurityContext.fsGroup }}
137               {{- end }}
138               {{- end }}
139               {{- if .Values.shmVolume.enabled }}
140               chmod -R 777 /dev/shm
141               {{- end }}
142               {{- if .Values.tls.enabled }}
143               cp /tmp/certs/* /opt/bitnami/postgresql/certs/
144               {{- if eq ( toString ( .Values.volumePermissions.containerSecurityContext.runAsUser )) "auto" }}
145               chown -R `id -u`:`id -G | cut -d " " -f2` /opt/bitnami/postgresql/certs/
146               {{- else }}
147               chown -R {{ .Values.readReplicas.containerSecurityContext.runAsUser }}:{{ .Values.readReplicas.podSecurityContext.fsGroup }} /opt/bitnami/postgresql/certs/
148               {{- end }}
149               chmod 600 {{ include "postgresql.tlsCertKey" . }}
150               {{- end }}
151           {{- if eq ( toString ( .Values.volumePermissions.containerSecurityContext.runAsUser )) "auto" }}
152           securityContext: {{- omit .Values.volumePermissions.containerSecurityContext "runAsUser" | toYaml | nindent 12 }}
153           {{- else }}
154           securityContext: {{- .Values.volumePermissions.containerSecurityContext | toYaml | nindent 12 }}
155           {{- end }}
156           volumeMounts:
157             {{ if .Values.readReplicas.persistence.enabled }}
158             - name: data
159               mountPath: {{ .Values.readReplicas.persistence.mountPath }}
160               {{- if .Values.readReplicas.persistence.subPath }}
161               subPath: {{ .Values.readReplicas.persistence.subPath }}
162               {{- end }}
163             {{- end }}
164             {{- if .Values.shmVolume.enabled }}
165             - name: dshm
166               mountPath: /dev/shm
167             {{- end }}
168             {{- if .Values.tls.enabled }}
169             - name: raw-certificates
170               mountPath: /tmp/certs
171             - name: postgresql-certificates
172               mountPath: /opt/bitnami/postgresql/certs
173             {{- end }}
174         {{- end }}
175         {{- if .Values.readReplicas.initContainers }}
176         {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.initContainers "context" $ ) | nindent 8 }}
177         {{- end }}
178       containers:
179         - name: postgresql
180           image: {{ include "postgresql.image" . }}
181           imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
182           {{- if .Values.readReplicas.containerSecurityContext.enabled }}
183           securityContext: {{- omit .Values.readReplicas.containerSecurityContext "enabled" | toYaml | nindent 12 }}
184           {{- end }}
185           {{- if .Values.diagnosticMode.enabled }}
186           command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
187           {{- else if .Values.readReplicas.command }}
188           command: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.command "context" $) | nindent 12 }}
189           {{- end }}
190           {{- if .Values.diagnosticMode.enabled }}
191           args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
192           {{- else if .Values.readReplicas.args }}
193           args: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.args "context" $) | nindent 12 }}
194           {{- end }}
195           env:
196             - name: BITNAMI_DEBUG
197               value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
198             - name: POSTGRESQL_PORT_NUMBER
199               value: {{ .Values.containerPorts.postgresql | quote }}
200             - name: POSTGRESQL_VOLUME_DIR
201               value: {{ .Values.readReplicas.persistence.mountPath | quote }}
202             {{- if .Values.readReplicas.persistence.mountPath }}
203             - name: PGDATA
204               value: {{ .Values.postgresqlDataDir | quote }}
205             {{- end }}
206             # Authentication
207           {{- if and (not (empty $customUser)) (ne $customUser "postgres") .Values.auth.enablePostgresUser }}
208             {{- if .Values.auth.usePasswordFiles }}
209             - name: POSTGRES_POSTGRES_PASSWORD_FILE
210               value: "/opt/bitnami/postgresql/secrets/postgres-password"
211             {{- else }}
212             - name: POSTGRES_POSTGRES_PASSWORD
213               valueFrom:
214                 secretKeyRef:
215                   name: {{ include "postgresql.secretName" . }}
216                   key: {{ include "postgresql.adminPasswordKey" . }}
217             {{- end }}
218           {{- end }}
219             {{- if .Values.auth.usePasswordFiles }}
220             - name: POSTGRES_PASSWORD_FILE
221               value: {{ printf "/opt/bitnami/postgresql/secrets/%s" (ternary "password" "postgres-password" (and (not (empty $customUser)) (ne $customUser "postgres"))) }}
222             {{- else }}
223             - name: POSTGRES_PASSWORD
224               valueFrom:
225                 secretKeyRef:
226                   name: {{ include "postgresql.secretName" . }}
227                   key: {{ include "postgresql.userPasswordKey" . }}
228             {{- end }}
229             # Replication
230             - name: POSTGRES_REPLICATION_MODE
231               value: "slave"
232             - name: POSTGRES_REPLICATION_USER
233               value: {{ .Values.auth.replicationUsername | quote }}
234             {{- if .Values.auth.usePasswordFiles }}
235             - name: POSTGRES_REPLICATION_PASSWORD_FILE
236               value: "/opt/bitnami/postgresql/secrets/replication-password"
237             {{- else }}
238             - name: POSTGRES_REPLICATION_PASSWORD
239               valueFrom:
240                 secretKeyRef:
241                   name: {{ include "postgresql.secretName" . }}
242                   key: {{ include "postgresql.replicationPasswordKey" . }}
243             {{- end }}
244             - name: POSTGRES_CLUSTER_APP_NAME
245               value: {{ .Values.replication.applicationName }}
246             - name: POSTGRES_MASTER_HOST
247               value: {{ include "postgresql.primary.fullname" . }}
248             - name: POSTGRES_MASTER_PORT_NUMBER
249               value: {{ include "postgresql.service.port" . | quote }}
250             # TLS
251             - name: POSTGRESQL_ENABLE_TLS
252               value: {{ ternary "yes" "no" .Values.tls.enabled | quote }}
253             {{- if .Values.tls.enabled }}
254             - name: POSTGRESQL_TLS_PREFER_SERVER_CIPHERS
255               value: {{ ternary "yes" "no" .Values.tls.preferServerCiphers | quote }}
256             - name: POSTGRESQL_TLS_CERT_FILE
257               value: {{ include "postgresql.tlsCert" . }}
258             - name: POSTGRESQL_TLS_KEY_FILE
259               value: {{ include "postgresql.tlsCertKey" . }}
260             {{- if .Values.tls.certCAFilename }}
261             - name: POSTGRESQL_TLS_CA_FILE
262               value: {{ include "postgresql.tlsCACert" . }}
263             {{- end }}
264             {{- if .Values.tls.crlFilename }}
265             - name: POSTGRESQL_TLS_CRL_FILE
266               value: {{ include "postgresql.tlsCRL" . }}
267             {{- end }}
268             {{- end }}
269             # Audit
270             - name: POSTGRESQL_LOG_HOSTNAME
271               value: {{ .Values.audit.logHostname | quote }}
272             - name: POSTGRESQL_LOG_CONNECTIONS
273               value: {{ .Values.audit.logConnections | quote }}
274             - name: POSTGRESQL_LOG_DISCONNECTIONS
275               value: {{ .Values.audit.logDisconnections | quote }}
276             {{- if .Values.audit.logLinePrefix }}
277             - name: POSTGRESQL_LOG_LINE_PREFIX
278               value: {{ .Values.audit.logLinePrefix | quote }}
279             {{- end }}
280             {{- if .Values.audit.logTimezone }}
281             - name: POSTGRESQL_LOG_TIMEZONE
282               value: {{ .Values.audit.logTimezone | quote }}
283             {{- end }}
284             {{- if .Values.audit.pgAuditLog }}
285             - name: POSTGRESQL_PGAUDIT_LOG
286               value: {{ .Values.audit.pgAuditLog | quote }}
287             {{- end }}
288             - name: POSTGRESQL_PGAUDIT_LOG_CATALOG
289               value: {{ .Values.audit.pgAuditLogCatalog | quote }}
290             # Others
291             - name: POSTGRESQL_CLIENT_MIN_MESSAGES
292               value: {{ .Values.audit.clientMinMessages | quote }}
293             - name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES
294               value: {{ .Values.postgresqlSharedPreloadLibraries | quote }}
295             {{- if .Values.readReplicas.extraEnvVars }}
296             {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.extraEnvVars "context" $) | nindent 12 }}
297             {{- end }}
298           {{- if or .Values.readReplicas.extraEnvVarsCM .Values.readReplicas.extraEnvVarsSecret }}
299           envFrom:
300             {{- if .Values.readReplicas.extraEnvVarsCM }}
301             - configMapRef:
302                 name: {{ .Values.readReplicas.extraEnvVarsCM }}
303             {{- end }}
304             {{- if .Values.readReplicas.extraEnvVarsSecret }}
305             - secretRef:
306                 name: {{ .Values.readReplicas.extraEnvVarsSecret }}
307             {{- end }}
308           {{- end }}
309           ports:
310             - name: tcp-postgresql
311               containerPort: {{ .Values.containerPorts.postgresql }}
312           {{- if not .Values.diagnosticMode.enabled }}
313           {{- if .Values.readReplicas.customStartupProbe }}
314           startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.customStartupProbe "context" $) | nindent 12 }}
315           {{- else if .Values.readReplicas.startupProbe.enabled }}
316           startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.readReplicas.startupProbe "enabled") "context" $) | nindent 12 }}
317             exec:
318               command:
319                 - /bin/sh
320                 - -c
321                 {{- if (include "postgresql.database" .) }}
322                 - exec pg_isready -U {{ default "postgres" $customUser| quote }} -d "dbname={{ include "postgresql.database" . }} {{- if and .Values.tls.enabled .Values.tls.certCAFilename }} sslcert={{ include "postgresql.tlsCert" . }} sslkey={{ include "postgresql.tlsCertKey" . }}{{- end }}" -h 127.0.0.1 -p {{ .Values.containerPorts.postgresql }}
323                 {{- else }}
324                 - exec pg_isready -U {{ default "postgres" $customUser | quote }} {{- if and .Values.tls.enabled .Values.tls.certCAFilename }} -d "sslcert={{ include "postgresql.tlsCert" . }} sslkey={{ include "postgresql.tlsCertKey" . }}"{{- end }} -h 127.0.0.1 -p {{ .Values.containerPorts.postgresql }}
325                 {{- end }}
326           {{- end }}
327           {{- if .Values.readReplicas.customLivenessProbe }}
328           livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.customLivenessProbe "context" $) | nindent 12 }}
329           {{- else if .Values.readReplicas.livenessProbe.enabled }}
330           livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.readReplicas.livenessProbe "enabled") "context" $) | nindent 12 }}
331             exec:
332               command:
333                 - /bin/sh
334                 - -c
335                 {{- if (include "postgresql.database" .) }}
336                 - exec pg_isready -U {{ default "postgres" $customUser | quote }} -d "dbname={{ include "postgresql.database" . }} {{- if and .Values.tls.enabled .Values.tls.certCAFilename }} sslcert={{ include "postgresql.tlsCert" . }} sslkey={{ include "postgresql.tlsCertKey" . }}{{- end }}" -h 127.0.0.1 -p {{ .Values.containerPorts.postgresql }}
337                 {{- else }}
338                 - exec pg_isready -U {{default "postgres" $customUser | quote }} {{- if and .Values.tls.enabled .Values.tls.certCAFilename }} -d "sslcert={{ include "postgresql.tlsCert" . }} sslkey={{ include "postgresql.tlsCertKey" . }}"{{- end }} -h 127.0.0.1 -p {{ .Values.containerPorts.postgresql }}
339                 {{- end }}
340           {{- end }}
341           {{- if .Values.readReplicas.customReadinessProbe }}
342           readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.customReadinessProbe "context" $) | nindent 12 }}
343           {{- else if .Values.readReplicas.readinessProbe.enabled }}
344           readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.readReplicas.readinessProbe "enabled") "context" $) | nindent 12 }}
345             exec:
346               command:
347                 - /bin/sh
348                 - -c
349                 - -e
350                 {{- include "postgresql.readinessProbeCommand" . | nindent 16 }}
351           {{- end }}
352           {{- end }}
353           {{- if .Values.readReplicas.resources }}
354           resources: {{- toYaml .Values.readReplicas.resources | nindent 12 }}
355           {{- end }}
356           {{- if .Values.readReplicas.lifecycleHooks }}
357           lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.lifecycleHooks "context" $) | nindent 12 }}
358           {{- end }}
359           volumeMounts:
360             {{- if .Values.auth.usePasswordFiles }}
361             - name: postgresql-password
362               mountPath: /opt/bitnami/postgresql/secrets/
363             {{- end }}
364             {{- if .Values.readReplicas.extendedConfiguration }}
365             - name: postgresql-extended-config
366               mountPath: /bitnami/postgresql/conf/conf.d/
367             {{- end }}
368             {{- if .Values.tls.enabled }}
369             - name: postgresql-certificates
370               mountPath: /opt/bitnami/postgresql/certs
371               readOnly: true
372             {{- end }}
373             {{- if .Values.shmVolume.enabled }}
374             - name: dshm
375               mountPath: /dev/shm
376             {{- end }}
377             {{- if .Values.readReplicas.persistence.enabled }}
378             - name: data
379               mountPath: {{ .Values.readReplicas.persistence.mountPath }}
380               {{- if .Values.readReplicas.persistence.subPath }}
381               subPath: {{ .Values.readReplicas.persistence.subPath }}
382               {{- end }}
383             {{- end }}
384             {{- if .Values.readReplicas.extraVolumeMounts }}
385             {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.extraVolumeMounts "context" $) | nindent 12 }}
386             {{- end }}
387         {{- if .Values.metrics.enabled }}
388         - name: metrics
389           image: {{ include "postgresql.metrics.image" . }}
390           imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
391           {{- if .Values.metrics.containerSecurityContext.enabled }}
392           securityContext: {{- omit .Values.metrics.containerSecurityContext "enabled" | toYaml | nindent 12 }}
393           {{- end }}
394           {{- if .Values.diagnosticMode.enabled }}
395           command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
396           args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
397           {{- else if .Values.metrics.customMetrics }}
398           args: [ "--extend.query-path", "/conf/custom-metrics.yaml" ]
399           {{- end }}
400           env:
401             {{- $database := required "In order to enable metrics you need to specify a database (.Values.auth.database or .Values.global.postgresql.auth.database)" (include "postgresql.database" .) }}
402               - name: DATA_SOURCE_URI
403                 value: {{ printf "127.0.0.1:%d/%s?sslmode=disable" (int (include "postgresql.service.port" .)) $database }}
404               {{- if .Values.auth.usePasswordFiles }}
405               - name: DATA_SOURCE_PASS_FILE
406                 value: {{ printf "/opt/bitnami/postgresql/secrets/%s" (ternary "password" "postgres-password" (and (not (empty $customUser)) (ne $customUser "postgres"))) }}
407               {{- else }}
408               - name: DATA_SOURCE_PASS
409                 valueFrom:
410                   secretKeyRef:
411                     name: {{ include "postgresql.secretName" . }}
412                     key: {{ include "postgresql.userPasswordKey" . }}
413               {{- end }}
414               - name: DATA_SOURCE_USER
415                 value: {{ default "postgres" $customUser | quote }}
416               {{- if .Values.metrics.extraEnvVars }}
417               {{- include "common.tplvalues.render" (dict "value" .Values.metrics.extraEnvVars "context" $) | nindent 12 }}
418               {{- end }}
419           ports:
420             - name: http-metrics
421               containerPort: {{ .Values.metrics.containerPorts.metrics }}
422           {{- if not .Values.diagnosticMode.enabled }}
423           {{- if .Values.metrics.customStartupProbe }}
424           startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customStartupProbe "context" $) | nindent 12 }}
425           {{- else if .Values.metrics.startupProbe.enabled }}
426           startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.startupProbe "enabled") "context" $) | nindent 12 }}
427             tcpSocket:
428               port: http-metrics
429           {{- end }}
430           {{- if .Values.metrics.customLivenessProbe }}
431           livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customLivenessProbe "context" $) | nindent 12 }}
432           {{- else if .Values.metrics.livenessProbe.enabled }}
433           livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.livenessProbe "enabled") "context" $) | nindent 12 }}
434             httpGet:
435               path: /
436               port: http-metrics
437           {{- end }}
438           {{- if .Values.metrics.customReadinessProbe }}
439           readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.metrics.customReadinessProbe "context" $) | nindent 12 }}
440           {{- else if .Values.metrics.readinessProbe.enabled }}
441           readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.metrics.readinessProbe "enabled") "context" $) | nindent 12 }}
442             httpGet:
443               path: /
444               port: http-metrics
445           {{- end }}
446           {{- end }}
447           volumeMounts:
448             {{- if .Values.auth.usePasswordFiles }}
449             - name: postgresql-password
450               mountPath: /opt/bitnami/postgresql/secrets/
451             {{- end }}
452             {{- if .Values.metrics.customMetrics }}
453             - name: custom-metrics
454               mountPath: /conf
455               readOnly: true
456             {{- end }}
457           {{- if .Values.metrics.resources }}
458           resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
459           {{- end }}
460         {{- end }}
461         {{- if .Values.readReplicas.sidecars }}
462         {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.sidecars "context" $ ) | nindent 8 }}
463         {{- end }}
464       volumes:
465         {{- if .Values.readReplicas.extendedConfiguration }}
466         - name: postgresql-extended-config
467           configMap:
468             name: {{ include "postgresql.readReplicas.extendedConfigmapName" . }}
469         {{- end }}
470         {{- if .Values.auth.usePasswordFiles }}
471         - name: postgresql-password
472           secret:
473             secretName: {{ include "postgresql.secretName" . }}
474         {{- end }}
475         {{- if .Values.tls.enabled }}
476         - name: raw-certificates
477           secret:
478             secretName: {{ include "postgresql.tlsSecretName" . }}
479         - name: postgresql-certificates
480           emptyDir: {}
481         {{- end }}
482         {{- if and .Values.metrics.enabled .Values.metrics.customMetrics }}
483         - name: custom-metrics
484           configMap:
485             name: {{ printf "%s-metrics" (include "common.names.fullname" .) }}
486         {{- end }}
487         {{- if .Values.shmVolume.enabled }}
488         - name: dshm
489           emptyDir:
490             medium: Memory
491             {{- if .Values.shmVolume.sizeLimit }}
492             sizeLimit: {{ .Values.shmVolume.sizeLimit }}
493             {{- end }}
494         {{- end }}
495         {{- if .Values.readReplicas.extraVolumes }}
496         {{- include "common.tplvalues.render" ( dict "value" .Values.readReplicas.extraVolumes "context" $ ) | nindent 8 }}
497         {{- end }}
498   {{- if and .Values.readReplicas.persistence.enabled .Values.readReplicas.persistence.existingClaim }}
499         - name: data
500           persistentVolumeClaim:
501             claimName: {{ tpl .Values.readReplicas.persistence.existingClaim $ }}
502   {{- else if not .Values.readReplicas.persistence.enabled }}
503         - name: data
504           emptyDir: {}
505   {{- else }}
506   volumeClaimTemplates:
507     - metadata:
508         name: data
509         {{- if .Values.readReplicas.persistence.annotations }}
510         annotations: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.persistence.annotations "context" $) | nindent 10 }}
511         {{- end }}
512         {{- if .Values.readReplicas.persistence.labels }}
513         labels: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.persistence.labels "context" $) | nindent 10 }}
514         {{- end }}
515       spec:
516         accessModes:
517         {{- range .Values.readReplicas.persistence.accessModes }}
518           - {{ . | quote }}
519         {{- end }}
520         {{- if .Values.readReplicas.persistence.dataSource }}
521         dataSource: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.persistence.dataSource "context" $) | nindent 10 }}
522         {{- end }}
523         resources:
524           requests:
525             storage: {{ .Values.readReplicas.persistence.size | quote }}
526         {{- if .Values.readReplicas.persistence.selector }}
527         selector: {{- include "common.tplvalues.render" (dict "value" .Values.readReplicas.persistence.selector "context" $) | nindent 10 }}
528         {{- end -}}
529         {{- include "common.storage.class" (dict "persistence" .Values.readReplicas.persistence "global" .Values.global) | nindent 8 }}
530   {{- end }}
531 {{- end }}