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