statefulset.yaml 34 KB

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