Skip to content

Commit 0cdafb8

Browse files
onichandameBitnami ContainersrafariossaaCarlos Rodríguez Hernández
authoredJun 20, 2024··
[bitnami/postgresql] Add pre-init scripts (#26467)
* [bitnami/postgresql] Add pre-init scripts Signed-off-by: onichandame <zxinmyth@gmail.com> * Update CHANGELOG.md Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com> * Update CHANGELOG.md Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com> * Update CHANGELOG.md Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com> --------- Signed-off-by: onichandame <zxinmyth@gmail.com> Signed-off-by: Bitnami Containers <bitnami-bot@vmware.com> Signed-off-by: Rafael Ríos Saavedra <rrios@vmware.com> Signed-off-by: Carlos Rodríguez Hernández <carlosrh@vmware.com> Co-authored-by: Bitnami Containers <bitnami-bot@vmware.com> Co-authored-by: Rafael Ríos Saavedra <rrios@vmware.com> Co-authored-by: Carlos Rodríguez Hernández <carlosrh@vmware.com>
1 parent 272a58e commit 0cdafb8

File tree

7 files changed

+73
-3
lines changed

7 files changed

+73
-3
lines changed
 

‎bitnami/postgresql/CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Changelog
22

3-
## 15.5.7 (2024-06-18)
3+
## 15.5.8 (2024-06-19)
44

5-
* [bitnami/postgresql] Release 15.5.7 ([#27401](https://github.com/bitnami/charts/pull/27401))
5+
* [bitnami/postgresql] Add pre-init scripts ([#26467](https://github.com/bitnami/charts/pull/26467))
6+
7+
## <small>15.5.7 (2024-06-18)</small>
8+
9+
* [bitnami/postgresql] Release 15.5.7 (#27401) ([2fff79d](https://github.com/bitnami/charts/commit/2fff79d0d54da3680cb8dac3652884c82c314e74)), closes [#27401](https://github.com/bitnami/charts/issues/27401)
610

711
## <small>15.5.6 (2024-06-17)</small>
812

‎bitnami/postgresql/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ maintainers:
3535
name: postgresql
3636
sources:
3737
- https://github.com/bitnami/charts/tree/main/bitnami/postgresql
38-
version: 15.5.7
38+
version: 15.5.8

‎bitnami/postgresql/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ If you already have data in it, you will fail to sync to standby nodes for all c
384384
| `primary.initdb.scriptsSecret` | Secret with scripts to be run at first boot (in case it contains sensitive information) | `""` |
385385
| `primary.initdb.user` | Specify the PostgreSQL username to execute the initdb scripts | `""` |
386386
| `primary.initdb.password` | Specify the PostgreSQL password to execute the initdb scripts | `""` |
387+
| `primary.preInitDb.scripts` | Dictionary of pre-init scripts | `{}` |
388+
| `primary.preInitDb.scriptsConfigMap` | ConfigMap with pre-init scripts to be run | `""` |
389+
| `primary.preInitDb.scriptsSecret` | Secret with pre-init scripts to be run | `""` |
387390
| `primary.standby.enabled` | Whether to enable current cluster's primary as standby server of another cluster or not | `false` |
388391
| `primary.standby.primaryHost` | The Host of replication primary in the other cluster | `""` |
389392
| `primary.standby.primaryPort` | The Port of replication primary in the other cluster | `""` |

‎bitnami/postgresql/templates/_helpers.tpl

+11
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ Return true if a configmap should be mounted with PostgreSQL configuration
267267
{{- end -}}
268268
{{- end -}}
269269

270+
{{/*
271+
Get the pre-initialization scripts ConfigMap name.
272+
*/}}
273+
{{- define "postgresql.v1.preInitDb.scriptsCM" -}}
274+
{{- if .Values.primary.preInitDb.scriptsConfigMap -}}
275+
{{- printf "%s" (tpl .Values.primary.preInitDb.scriptsConfigMap $) -}}
276+
{{- else -}}
277+
{{- printf "%s-preinit-scripts" (include "postgresql.v1.primary.fullname" .) -}}
278+
{{- end -}}
279+
{{- end -}}
280+
270281
{{/*
271282
Get the initialization scripts ConfigMap name.
272283
*/}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- /*
2+
Copyright Broadcom, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: APACHE-2.0
4+
*/}}
5+
6+
{{- if and .Values.primary.preInitDb.scripts (not .Values.primary.preInitDb.scriptsConfigMap) }}
7+
apiVersion: v1
8+
kind: ConfigMap
9+
metadata:
10+
name: {{ printf "%s-preinit-scripts" (include "postgresql.v1.primary.fullname" .) }}
11+
namespace: {{ .Release.Namespace | quote }}
12+
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
13+
{{- if .Values.commonAnnotations }}
14+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
15+
{{- end }}
16+
data: {{- include "common.tplvalues.render" (dict "value" .Values.primary.preInitDb.scripts "context" .) | nindent 2 }}
17+
{{- end }}

‎bitnami/postgresql/templates/primary/statefulset.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ spec:
466466
- name: empty-dir
467467
mountPath: /opt/bitnami/postgresql/tmp
468468
subPath: app-tmp-dir
469+
{{- if or .Values.primary.preInitDb.scriptsConfigMap .Values.primary.preInitDb.scripts }}
470+
- name: custom-preinit-scripts
471+
mountPath: /docker-entrypoint-preinitdb.d/
472+
{{- end }}
473+
{{- if .Values.primary.preInitDb.scriptsSecret }}
474+
- name: custom-preinit-scripts-secret
475+
mountPath: /docker-entrypoint-preinitdb.d/secret
476+
{{- end }}
469477
{{- if or .Values.primary.initdb.scriptsConfigMap .Values.primary.initdb.scripts }}
470478
- name: custom-init-scripts
471479
mountPath: /docker-entrypoint-initdb.d/
@@ -611,6 +619,16 @@ spec:
611619
secret:
612620
secretName: {{ include "postgresql.v1.secretName" . }}
613621
{{- end }}
622+
{{- if or .Values.primary.preInitDb.scriptsConfigMap .Values.primary.preInitDb.scripts }}
623+
- name: custom-preinit-scripts
624+
configMap:
625+
name: {{ include "postgresql.v1.preInitDb.scriptsCM" . }}
626+
{{- end }}
627+
{{- if .Values.primary.preInitDb.scriptsSecret }}
628+
- name: custom-preinit-scripts-secret
629+
secret:
630+
secretName: {{ tpl .Values.primary.preInitDb.scriptsSecret $ }}
631+
{{- end }}
614632
{{- if or .Values.primary.initdb.scriptsConfigMap .Values.primary.initdb.scripts }}
615633
- name: custom-init-scripts
616634
configMap:

‎bitnami/postgresql/values.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,23 @@ primary:
357357
## @param primary.initdb.password Specify the PostgreSQL password to execute the initdb scripts
358358
##
359359
password: ""
360+
## Pre-init configuration
361+
## ref: https://github.com/bitnami/containers/tree/main/bitnami/postgresql/#on-container-start
362+
preInitDb:
363+
## @param primary.preInitDb.scripts Dictionary of pre-init scripts
364+
## Specify dictionary of shell scripts to be run before db boot
365+
## e.g:
366+
## scripts:
367+
## my_pre_init_script.sh: |
368+
## #!/bin/sh
369+
## echo "Do something."
370+
scripts: {}
371+
## @param primary.preInitDb.scriptsConfigMap ConfigMap with pre-init scripts to be run
372+
## NOTE: This will override `primary.preInitDb.scripts`
373+
scriptsConfigMap: ""
374+
## @param primary.preInitDb.scriptsSecret Secret with pre-init scripts to be run
375+
## NOTE: This can work along `primary.preInitDb.scripts` or `primary.preInitDb.scriptsConfigMap`
376+
scriptsSecret: ""
360377
## Configure current cluster's primary server to be the standby server in other cluster.
361378
## This will allow cross cluster replication and provide cross cluster high availability.
362379
## You will need to configure pgHbaConfiguration if you want to enable this feature with local cluster replication enabled.

0 commit comments

Comments
 (0)
Please sign in to comment.