From f2749dde1017e25322f620f3de8bbd0dc2479fe1 Mon Sep 17 00:00:00 2001 From: Tomas Pizarro Date: Wed, 10 Oct 2018 09:19:57 +0200 Subject: [PATCH] [stable/mongodb] - Allow using custom initialization scripts (#8272) * [stable/mongodb] - Allow using custom initialization scripts Signed-off-by: tompizmor * Avoid creating config-map if not needed Signed-off-by: tompizmor * Delete blank line Signed-off-by: tompizmor * Add missing conditional blocks Signed-off-by: tompizmor --- stable/mongodb/Chart.yaml | 2 +- stable/mongodb/README.md | 8 +++++++- .../files/docker-entrypoint-initdb.d/README.md | 3 +++ .../templates/deployment-standalone.yaml | 9 +++++++++ .../templates/initialization-configmap.yaml | 13 +++++++++++++ .../templates/statefulset-primary-rs.yaml | 17 +++++++++++++---- 6 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 stable/mongodb/files/docker-entrypoint-initdb.d/README.md create mode 100644 stable/mongodb/templates/initialization-configmap.yaml diff --git a/stable/mongodb/Chart.yaml b/stable/mongodb/Chart.yaml index 6193ad6117..4d42f80403 100644 --- a/stable/mongodb/Chart.yaml +++ b/stable/mongodb/Chart.yaml @@ -1,5 +1,5 @@ name: mongodb -version: 4.3.10 +version: 4.4.0 appVersion: 4.0.3 description: NoSQL document-oriented database that stores JSON-like documents with dynamic schemas, simplifying the integration of data in content-driven applications. keywords: diff --git a/stable/mongodb/README.md b/stable/mongodb/README.md index 3b429988ec..1f4107d7c8 100644 --- a/stable/mongodb/README.md +++ b/stable/mongodb/README.md @@ -86,7 +86,7 @@ The following table lists the configurable parameters of the MongoDB chart and t | `persistence.accessMode` | Use volume as ReadOnly or ReadWrite | `ReadWriteOnce` | | `persistence.size` | Size of data volume | `8Gi` | | `persistence.annotations` | Persistent Volume annotations | `{}` | -| `persistence.existingClaim` | Name of an existing PVC to use (avoids creating one if this is given) | `nil` | +| `persistence.existingClaim` | Name of an existing PVC to use (avoids creating one if this is given) | `nil` | | `livenessProbe.initialDelaySeconds` | Delay before liveness probe is initiated | `30` | | `livenessProbe.periodSeconds` | How often to perform the probe | `10` | | `livenessProbe.timeoutSeconds` | When the probe times out | `5` | @@ -144,6 +144,12 @@ Some characteristics of this chart are: * The number of secondary and arbiter nodes can be scaled out independently. * Easy to move an application from using a standalone MongoDB server to use a replica set. +## Initialize a fresh instance + +The [Bitnami MongoDB](https://github.com/bitnami/bitnami-docker-mongodb) image allows you to use your custom scripts to initialize a fresh instance. In order to execute the scripts, they must be located inside the chart folder `files/docker-entrypoint-initdb.d` so they can be consumed as a ConfigMap. + +The allowed extensions are `.sh`, and `.js`. + ## Persistence The [Bitnami MongoDB](https://github.com/bitnami/bitnami-docker-mongodb) image stores the MongoDB data and configurations at the `/bitnami/mongodb` path of the container. diff --git a/stable/mongodb/files/docker-entrypoint-initdb.d/README.md b/stable/mongodb/files/docker-entrypoint-initdb.d/README.md new file mode 100644 index 0000000000..a9299905d0 --- /dev/null +++ b/stable/mongodb/files/docker-entrypoint-initdb.d/README.md @@ -0,0 +1,3 @@ +You can copy here your custom .sh, or .js file so they are executed during the first boot of the image. + +More info in the [bitnami-docker-mongodb](https://github.com/bitnami/bitnami-docker-mongodb#initializing-a-new-instance) repository. \ No newline at end of file diff --git a/stable/mongodb/templates/deployment-standalone.yaml b/stable/mongodb/templates/deployment-standalone.yaml index b5165dbb28..d8ff01be35 100644 --- a/stable/mongodb/templates/deployment-standalone.yaml +++ b/stable/mongodb/templates/deployment-standalone.yaml @@ -110,6 +110,10 @@ spec: volumeMounts: - name: data mountPath: /bitnami/mongodb + {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]") }} + - name: custom-init-scripts + mountPath: /docker-entrypoint-initdb.d + {{- end }} {{- if .Values.configmap }} - name: config mountPath: /opt/bitnami/mongodb/conf/mongodb.conf @@ -118,6 +122,11 @@ spec: resources: {{ toYaml .Values.resources | indent 10 }} volumes: + {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]") }} + - name: custom-init-scripts + configMap: + name: {{ template "mongodb.fullname" . }}-init-scripts + {{- end }} - name: data {{- if .Values.persistence.enabled }} persistentVolumeClaim: diff --git a/stable/mongodb/templates/initialization-configmap.yaml b/stable/mongodb/templates/initialization-configmap.yaml new file mode 100644 index 0000000000..840e77ccfa --- /dev/null +++ b/stable/mongodb/templates/initialization-configmap.yaml @@ -0,0 +1,13 @@ +{{ if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]") }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "mongodb.fullname" . }}-init-scripts + labels: + app: {{ template "mongodb.name" . }} + chart: {{ template "mongodb.chart" . }} + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} +data: +{{ (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]").AsConfig | indent 2 }} +{{ end }} \ No newline at end of file diff --git a/stable/mongodb/templates/statefulset-primary-rs.yaml b/stable/mongodb/templates/statefulset-primary-rs.yaml index ca5bae1047..8dcb004715 100644 --- a/stable/mongodb/templates/statefulset-primary-rs.yaml +++ b/stable/mongodb/templates/statefulset-primary-rs.yaml @@ -124,17 +124,26 @@ spec: volumeMounts: - name: datadir mountPath: /bitnami/mongodb - {{- if .Values.configmap }} + {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]") }} + - name: custom-init-scripts + mountPath: /docker-entrypoint-initdb.d + {{- end }} + {{- if .Values.configmap }} - name: config mountPath: /opt/bitnami/mongodb/conf/mongodb.conf subPath: mongodb.conf - {{- end }} + {{- end }} volumes: - {{- if .Values.configmap }} + {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js]") }} + - name: custom-init-scripts + configMap: + name: {{ template "mongodb.fullname" . }}-init-scripts + {{- end }} + {{- if .Values.configmap }} - name: config configMap: name: {{ template "mongodb.fullname" . }} - {{- end }} + {{- end }} {{- if .Values.persistence.enabled }} volumeClaimTemplates: - metadata: