statefulset.yaml 31 KB

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