From fbd69f5ffd1e448d04d45cf74f282b4417db0bc4 Mon Sep 17 00:00:00 2001 From: OmriHarary Date: Wed, 19 Feb 2020 05:00:10 -0500 Subject: [PATCH] [bitnami/mysql] Match init script support to bitnami/mariadb (#1947) * Updates to mysql chart to have equivalent init script support to mariadb chart * Updated README with new init script variables Co-authored-by: Marcos Bjoerkelund --- bitnami/mysql/Chart.yaml | 2 +- bitnami/mysql/README.md | 2 ++ bitnami/mysql/templates/_helpers.tpl | 12 ++++++++++++ .../mysql/templates/initialization-configmap.yaml | 9 ++++++++- bitnami/mysql/templates/master-statefulset.yaml | 6 +++--- bitnami/mysql/values-production.yaml | 13 +++++++++++++ bitnami/mysql/values.yaml | 13 +++++++++++++ 7 files changed, 52 insertions(+), 5 deletions(-) diff --git a/bitnami/mysql/Chart.yaml b/bitnami/mysql/Chart.yaml index dffc9657b..120cabf4a 100644 --- a/bitnami/mysql/Chart.yaml +++ b/bitnami/mysql/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: mysql -version: 6.8.1 +version: 6.9.0 appVersion: 8.0.19 description: Chart to create a Highly available MySQL cluster keywords: diff --git a/bitnami/mysql/README.md b/bitnami/mysql/README.md index 93bb043f1..b2d1b7033 100644 --- a/bitnami/mysql/README.md +++ b/bitnami/mysql/README.md @@ -82,6 +82,8 @@ The following tables lists the configurable parameters of the MySQL chart and th | `replication.password` | MySQL replication user password | _random 10 character alphanumeric string_ | | `replication.forcePassword` | Force users to specify a password. That is required for 'helm upgrade' to work properly | `false` | | `replication.injectSecretsAsVolume` | Mount user password as a file instead of using an environment variable | `false` | +| `initdbScripts` | Dictionary of initdb scripts | `nil` | +| `initdbScriptsConfigMap` | ConfigMap with the initdb scripts (Note: Overrides `initdbScripts`) | `nil` | | `master.config` | Config file for the MySQL Master server | `_default values in the values.yaml file_` | | `master.updateStrategy.type` | Master statefulset update strategy policy | `RollingUpdate` | | `master.podAnnotations` | Pod annotations for master nodes | `{}` | diff --git a/bitnami/mysql/templates/_helpers.tpl b/bitnami/mysql/templates/_helpers.tpl index c71e84654..3aeee1405 100644 --- a/bitnami/mysql/templates/_helpers.tpl +++ b/bitnami/mysql/templates/_helpers.tpl @@ -94,6 +94,18 @@ Also, we can't use a single if because lazy evaluation is not an option {{- end -}} {{- end -}} +{{ template "mysql.initdbScriptsCM" . }} +{{/* +Get the initialization scripts ConfigMap name. +*/}} +{{- define "mysql.initdbScriptsCM" -}} +{{- if .Values.initdbScriptsConfigMap -}} +{{- printf "%s" .Values.initdbScriptsConfigMap -}} +{{- else -}} +{{- printf "%s-init-scripts" (include "mysql.master.fullname" .) -}} +{{- end -}} +{{- end -}} + {{/* Return the proper MySQL metrics exporter image name */}} diff --git a/bitnami/mysql/templates/initialization-configmap.yaml b/bitnami/mysql/templates/initialization-configmap.yaml index 52816732d..6bf5689bf 100644 --- a/bitnami/mysql/templates/initialization-configmap.yaml +++ b/bitnami/mysql/templates/initialization-configmap.yaml @@ -1,15 +1,22 @@ -{{- 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 "mysql.master.fullname" . }}-init-scripts labels: {{- include "mysql.labels" . | nindent 4 }} 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/bitnami/mysql/templates/master-statefulset.yaml b/bitnami/mysql/templates/master-statefulset.yaml index bcd835fe7..2e2d37e44 100644 --- a/bitnami/mysql/templates/master-statefulset.yaml +++ b/bitnami/mysql/templates/master-statefulset.yaml @@ -155,7 +155,7 @@ spec: - name: data {{- end }} mountPath: {{ .Values.master.persistence.mountPath }} - {{- 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 }} @@ -222,10 +222,10 @@ spec: configMap: name: {{ template "mysql.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 "mysql.master.fullname" . }}-init-scripts + name: {{ template "mysql.initdbScriptsCM" . }} {{- end }} {{- if or .Values.root.injectSecretsAsVolume .Values.db.injectSecretsAsVolume .Values.replication.injectSecretsAsVolume }} - name: mysql-credentials diff --git a/bitnami/mysql/values-production.yaml b/bitnami/mysql/values-production.yaml index 992ca29af..e883b2232 100644 --- a/bitnami/mysql/values-production.yaml +++ b/bitnami/mysql/values-production.yaml @@ -134,6 +134,19 @@ replication: ## injectSecretsAsVolume: true +## initdb scripts +## Specify dictionary 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 nodes parameters ## master: diff --git a/bitnami/mysql/values.yaml b/bitnami/mysql/values.yaml index 2caafb36d..fb1792c09 100644 --- a/bitnami/mysql/values.yaml +++ b/bitnami/mysql/values.yaml @@ -138,6 +138,19 @@ replication: ## injectSecretsAsVolume: false +## initdb scripts +## Specify dictionary 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 nodes parameters ## master: