From 96e19d643eef01cd96f3f010e5ab632395ebd39e Mon Sep 17 00:00:00 2001 From: Juan Ariza Toledano Date: Wed, 2 Jan 2019 16:14:33 +0100 Subject: [PATCH] [stable/mariadb] Add support to existing configMaps as init scripts (#10338) Signed-off-by: juan131 --- stable/mariadb/Chart.yaml | 2 +- stable/mariadb/README.md | 6 ++++++ stable/mariadb/templates/_helpers.tpl | 12 ++++++++++++ .../mariadb/templates/initialization-configmap.yaml | 11 +++++++++-- stable/mariadb/templates/master-statefulset.yaml | 6 +++--- stable/mariadb/values-production.yaml | 13 +++++++++++++ stable/mariadb/values.yaml | 13 +++++++++++++ 7 files changed, 57 insertions(+), 6 deletions(-) diff --git a/stable/mariadb/Chart.yaml b/stable/mariadb/Chart.yaml index 9ad534eac1..050e0165b2 100644 --- a/stable/mariadb/Chart.yaml +++ b/stable/mariadb/Chart.yaml @@ -1,5 +1,5 @@ name: mariadb -version: 5.2.6 +version: 5.3.0 appVersion: 10.1.37 description: Fast, reliable, scalable, and easy to use open-source relational database system. MariaDB Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software. Highly available MariaDB cluster. keywords: diff --git a/stable/mariadb/README.md b/stable/mariadb/README.md index 7b6144587f..e6f50a132f 100644 --- a/stable/mariadb/README.md +++ b/stable/mariadb/README.md @@ -70,6 +70,8 @@ The following table lists the configurable parameters of the MariaDB chart and t | `replication.enabled` | MariaDB replication enabled | `true` | | `replication.user` | MariaDB replication user | `replicator` | | `replication.password` | MariaDB replication user password | _random 10 character alphanumeric string_ | +| `initdbScripts` | List of initdb scripts | `nil` | +| `initdbScriptsConfigMap` | ConfigMap with the initdb scripts (Note: Overrides `initdbScripts`) | `nil` | | `master.annotations[].key` | key for the the annotation list item | `nil` | | `master.annotations[].value` | value for the the annotation list item | `nil` | | `master.affinity` | Master affinity (in addition to master.antiAffinity when set) | `{}` | @@ -152,6 +154,10 @@ $ helm install --name my-release -f values.yaml stable/mariadb The [Bitnami MariaDB](https://github.com/bitnami/bitnami-docker-mariadb) 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. +Alternatively, you can specify custom scripts using the `initdbScripts` parameter as dict. + +In addition to these options, you can also set an external ConfigMap with all the initialization scripts. This is done by setting the `initdbScriptsConfigMap` parameter. Note that this will override the two previous options. + The allowed extensions are `.sh`, `.sql` and `.sql.gz`. ## Persistence diff --git a/stable/mariadb/templates/_helpers.tpl b/stable/mariadb/templates/_helpers.tpl index 9d785167bc..693b02992f 100644 --- a/stable/mariadb/templates/_helpers.tpl +++ b/stable/mariadb/templates/_helpers.tpl @@ -63,3 +63,15 @@ Return the proper metrics image name {{- $tag := .Values.metrics.image.tag | toString -}} {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} {{- end -}} + +{{ template "mariadb.initdbScriptsCM" . }} +{{/* +Get the initialization scripts ConfigMap name. +*/}} +{{- define "mariadb.initdbScriptsCM" -}} +{{- if .Values.initdbScriptsConfigMap -}} +{{- printf "%s" .Values.initdbScriptsConfigMap -}} +{{- else -}} +{{- printf "%s-init-scripts" (include "mariadb.fullname" .) -}} +{{- end -}} +{{- end -}} diff --git a/stable/mariadb/templates/initialization-configmap.yaml b/stable/mariadb/templates/initialization-configmap.yaml index 7ce6711836..f7380aff77 100644 --- a/stable/mariadb/templates/initialization-configmap.yaml +++ b/stable/mariadb/templates/initialization-configmap.yaml @@ -1,19 +1,26 @@ -{{ if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|sql|sql.gz]") }} +{{- if and (or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.initdbScripts) (not .Values.initdbScriptsConfigMap) }} apiVersion: v1 kind: ConfigMap metadata: name: {{ template "master.fullname" . }}-init-scripts labels: app: {{ template "mariadb.name" . }} - component: "master" chart: {{ template "mariadb.chart" . }} release: {{ .Release.Name | quote }} heritage: {{ .Release.Service | quote }} + component: "master" +{{- if and (.Files.Glob "files/docker-entrypoint-initdb.d/*.sql.gz") (not .Values.initdbScriptsConfigMap) }} binaryData: {{- $root := . }} {{- range $path, $bytes := .Files.Glob "files/docker-entrypoint-initdb.d/*.sql.gz" }} {{ base $path }}: {{ $root.Files.Get $path | b64enc | quote }} {{- end }} +{{- end }} data: +{{- if and (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql}") (not .Values.initdbScriptsConfigMap) }} {{ (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql}").AsConfig | indent 2 }} +{{- end }} +{{- with .Values.initdbScripts }} +{{ toYaml . | indent 2 }} +{{- end }} {{ end }} diff --git a/stable/mariadb/templates/master-statefulset.yaml b/stable/mariadb/templates/master-statefulset.yaml index 4cad6fef4f..fe79f8d73e 100644 --- a/stable/mariadb/templates/master-statefulset.yaml +++ b/stable/mariadb/templates/master-statefulset.yaml @@ -143,7 +143,7 @@ spec: volumeMounts: - name: data mountPath: /bitnami/mariadb - {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|sql|sql.gz]") }} + {{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.initdbScriptsConfigMap .Values.initdbScripts }} - name: custom-init-scripts mountPath: /docker-entrypoint-initdb.d {{- end }} @@ -196,10 +196,10 @@ spec: configMap: name: {{ template "master.fullname" . }} {{- end }} - {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|sql|sql.gz]") }} + {{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.initdbScriptsConfigMap .Values.initdbScripts }} - name: custom-init-scripts configMap: - name: {{ template "master.fullname" . }}-init-scripts + name: {{ template "mariadb.initdbScriptsCM" . }} {{- end }} {{- if .Values.master.persistence.enabled }} volumeClaimTemplates: diff --git a/stable/mariadb/values-production.yaml b/stable/mariadb/values-production.yaml index 906e91d735..7f67fd71b5 100644 --- a/stable/mariadb/values-production.yaml +++ b/stable/mariadb/values-production.yaml @@ -94,6 +94,19 @@ replication: ## If it is not force, a random password will be generated. forcePassword: true +## initdb scripts +## Specify dictionnary of scripts to be run at first boot +## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory +## +# initdbScripts: +# my_init_script.sh: | +# #!/bin/sh +# echo "Do something." +# +## ConfigMap with scripts to be run at first boot +## Note: This will override initdbScripts +# initdbScriptsConfigMap: + master: ## Mariadb Master additional pod annotations ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ diff --git a/stable/mariadb/values.yaml b/stable/mariadb/values.yaml index 7de7ae8df6..2b5f565a5d 100644 --- a/stable/mariadb/values.yaml +++ b/stable/mariadb/values.yaml @@ -94,6 +94,19 @@ replication: ## If it is not force, a random password will be generated. forcePassword: false +## initdb scripts +## Specify dictionnary of scripts to be run at first boot +## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory +## +# initdbScripts: +# my_init_script.sh: | +# #!/bin/sh +# echo "Do something." +# +## ConfigMap with scripts to be run at first boot +## Note: This will override initdbScripts +# initdbScriptsConfigMap: + master: ## Mariadb Master additional pod annotations ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/