statefulset.yaml 36 KB

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