From 72b03e87d4e5ad23dae00c55aaa3fcc2f5cfaedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20P=C3=B6hner?= <10630407+groundhog2k@users.noreply.github.com> Date: Fri, 30 Sep 2022 08:45:13 +0200 Subject: [PATCH] Add optional inline script configuration for database initialization to charts (#1168) --- charts/mariadb/Chart.yaml | 2 +- charts/mariadb/README.md | 3 +- charts/mariadb/RELEASENOTES.md | 1 + charts/mariadb/templates/customscripts.yaml | 13 +++++++++ charts/mariadb/templates/scripts.yaml | 4 +++ charts/mariadb/templates/statefulset.yaml | 11 ++++++++ charts/mariadb/values.yaml | 7 +++++ charts/mongodb/Chart.yaml | 2 +- charts/mongodb/README.md | 3 +- charts/mongodb/RELEASENOTES.md | 1 + charts/mongodb/templates/customscripts.yaml | 13 +++++++++ charts/mongodb/templates/scripts.yaml | 4 +++ charts/mongodb/templates/statefulset.yaml | 31 ++++++++++++++------- charts/mongodb/values.yaml | 7 +++++ charts/mysql/Chart.yaml | 2 +- charts/mysql/README.md | 3 +- charts/mysql/RELEASENOTES.md | 1 + charts/mysql/templates/customscripts.yaml | 13 +++++++++ charts/mysql/templates/scripts.yaml | 4 +++ charts/mysql/templates/statefulset.yaml | 11 ++++++++ charts/mysql/values.yaml | 6 ++++ charts/postgres/Chart.yaml | 2 +- charts/postgres/README.md | 2 +- charts/postgres/RELEASENOTES.md | 2 +- 24 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 charts/mariadb/templates/customscripts.yaml create mode 100644 charts/mongodb/templates/customscripts.yaml create mode 100644 charts/mysql/templates/customscripts.yaml diff --git a/charts/mariadb/Chart.yaml b/charts/mariadb/Chart.yaml index 86a651e4..476f11a6 100644 --- a/charts/mariadb/Chart.yaml +++ b/charts/mariadb/Chart.yaml @@ -7,6 +7,6 @@ type: application maintainers: - name: groundhog2k -version: 0.6.1 +version: 0.6.2 appVersion: "10.9.3" diff --git a/charts/mariadb/README.md b/charts/mariadb/README.md index 6c79ebea..b907eefd 100644 --- a/charts/mariadb/README.md +++ b/charts/mariadb/README.md @@ -1,6 +1,6 @@ # MariaDB -   +   ## Changelog @@ -117,6 +117,7 @@ helm uninstall my-release | customConfig | string | `nil` | Additional MariaDB custom configuration mounted as `/etc/mysql/custom.cnf` | | extraEnvSecrets | list | `[]` | A list of existing secrets that will be mounted into the container as environment variables | | extraSecretConfigs | string | `nil` | An existing secret with files that will be mounted into the container as custom MariaDB configuration files (`*.cnf`) in `/etc/mysql/conf.d` | +| customScripts | object | `nil` | Optional custom scripts that can be defined inline and will be mounted as files in `/docker-entrypoint-initdb.d` | | extraScripts | string | `nil` | An existing configMap with files that will be mounted into the container as script files (`*.sql`, `*.sh`) in `/docker-entrypoint-initdb.d` | | extraSecrets | list | `[]` | A list of additional existing secrets that will be mounted into the container | | extraSecrets[].name | string | `nil` | Name of the existing K8s secret | diff --git a/charts/mariadb/RELEASENOTES.md b/charts/mariadb/RELEASENOTES.md index a09b1458..05eade4f 100644 --- a/charts/mariadb/RELEASENOTES.md +++ b/charts/mariadb/RELEASENOTES.md @@ -27,4 +27,5 @@ | 0.5.2 | 10.8.5 | Upgraded MariaDB to 10.8.5 | | 0.6.0 | 10.9.2 | Upgraded MariaDB to 10.9.2 | | 0.6.1 | 10.9.3 | Upgraded MariaDB to 10.9.3 | +| 0.6.2 | 10.9.3 | Implemented support for custom inline init scripts | | | | | diff --git a/charts/mariadb/templates/customscripts.yaml b/charts/mariadb/templates/customscripts.yaml new file mode 100644 index 00000000..be82bf3a --- /dev/null +++ b/charts/mariadb/templates/customscripts.yaml @@ -0,0 +1,13 @@ +{{- if .Values.customScripts }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mariadb.fullname" . }}-customscripts + labels: + {{- include "mariadb.labels" . | nindent 4 }} +data: + {{- range $name, $value := .Values.customScripts }} + {{- $name | nindent 2 }}: | + {{- $value | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/mariadb/templates/scripts.yaml b/charts/mariadb/templates/scripts.yaml index 369c753f..150731d3 100644 --- a/charts/mariadb/templates/scripts.yaml +++ b/charts/mariadb/templates/scripts.yaml @@ -12,6 +12,10 @@ data: echo "Copy extra scripts" cp /extrascripts/* /scripts fi + if [ -d /customscripts ]; then + echo "Copy custom scripts" + cp /customscripts/* /scripts + fi if [ -d /extraconfigs ]; then echo "Copy extra configs" cp /extraconfigs/* /configs diff --git a/charts/mariadb/templates/statefulset.yaml b/charts/mariadb/templates/statefulset.yaml index ae1287ac..20454851 100644 --- a/charts/mariadb/templates/statefulset.yaml +++ b/charts/mariadb/templates/statefulset.yaml @@ -21,6 +21,7 @@ spec: annotations: checksum/customconfig: {{ include (print $.Template.BasePath "/customconfig.yaml") . | sha256sum }} checksum/secureconfig: {{ include (print $.Template.BasePath "/secureconfig.yaml") . | sha256sum }} + checksum/customscripts: {{ include (print $.Template.BasePath "/customscripts.yaml") . | sha256sum }} checksum/scripts: {{ include (print $.Template.BasePath "/scripts.yaml") . | sha256sum }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} @@ -50,6 +51,10 @@ spec: - mountPath: /extrascripts name: extrascripts-volume {{- end }} + {{- if .Values.customScripts }} + - mountPath: /customscripts + name: customscripts-volume + {{- end }} {{- if .Values.extraSecretConfigs }} - mountPath: /extraconfigs name: extraconfigs-volume @@ -212,6 +217,12 @@ spec: configMap: name: {{ include "mariadb.fullname" . }}-scripts defaultMode: 0555 + {{- if .Values.customScripts }} + - name: customscripts-volume + configMap: + name: {{ include "mariadb.fullname" . }}-customscripts + defaultMode: 0555 + {{- end }} {{- if .Values.extraSecretConfigs }} - name: extraconfigs-volume secret: diff --git a/charts/mariadb/values.yaml b/charts/mariadb/values.yaml index 48524c5f..54411d63 100644 --- a/charts/mariadb/values.yaml +++ b/charts/mariadb/values.yaml @@ -152,6 +152,13 @@ userDatabase: {} ## For more flexible options see extraSecretConfigs: section customConfig: | +## Optional custom scripts that can be defined inline and will be mounted as files in /docker-entrypoint-initdb.d +customScripts: {} +# 01-a-script.sh: | +# echo "hello" +# 02-another-script.sh: | +# echo "hello 2" + ## A list of existing secrets that will be mounted into the container as environment variables ## As an alternative these secrets can set the database root password or optional user database when userDatabase: and rootPassword: were not specified ## For example: Setting MARIADB_DATABASE, MARIADB_USER, MARIADB_PASSWORD will allow creating a user database and grant access for the given user diff --git a/charts/mongodb/Chart.yaml b/charts/mongodb/Chart.yaml index 0155b620..8cf443f6 100644 --- a/charts/mongodb/Chart.yaml +++ b/charts/mongodb/Chart.yaml @@ -7,6 +7,6 @@ type: application maintainers: - name: groundhog2k -version: 0.5.0 +version: 0.5.1 appVersion: "6.0.1" diff --git a/charts/mongodb/README.md b/charts/mongodb/README.md index 8e034634..43c0d5f3 100644 --- a/charts/mongodb/README.md +++ b/charts/mongodb/README.md @@ -1,6 +1,6 @@ # MongoDB -   +   ## Changelog @@ -116,6 +116,7 @@ helm uninstall my-release | customConfig | string | `nil` | Custom MongoDB configuration block that will be mounted as file in `/etc/mongo/custom.conf` | | extraEnvSecrets | list | `[]` | A list of existing secrets that will be mounted into the container as environment variables | | extraSecretConfigs | string | `nil` | An existing secret with files that will be added to the mongodb configuration in addition to `/etc/mongo/custom.conf` | +| customScripts | object | `nil` | Optional custom scripts that can be defined inline and will be mounted as files in `/docker-entrypoint-initdb.d` | | extraScripts | string | `nil` | An existing configMap with files that will be mounted into the container as script files (`*.js`, `*.sh`) in `/docker-entrypoint-initdb.d` | | extraSecrets | list | `[]` | A list of additional existing secrets that will be mounted into the container | | extraSecrets[].name | string | `nil` | Name of the existing K8s secret | diff --git a/charts/mongodb/RELEASENOTES.md b/charts/mongodb/RELEASENOTES.md index fe8af327..5d057fb9 100644 --- a/charts/mongodb/RELEASENOTES.md +++ b/charts/mongodb/RELEASENOTES.md @@ -30,4 +30,5 @@ | 0.4.9 | 5.0.11 | Upgraded to MongoDB 5.0.11 | | 0.4.10 | 5.0.12 | Upgraded to MongoDB 5.0.12 | | 0.5.0 | 6.0.1 | Upgraded to MongoDB 6.0.1 | +| 0.5.1 | 6.0.1 | Implemented support for custom inline init scripts | | | | | diff --git a/charts/mongodb/templates/customscripts.yaml b/charts/mongodb/templates/customscripts.yaml new file mode 100644 index 00000000..f6ea68eb --- /dev/null +++ b/charts/mongodb/templates/customscripts.yaml @@ -0,0 +1,13 @@ +{{- if .Values.customScripts }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mongodb.fullname" . }}-customscripts + labels: + {{- include "mongodb.labels" . | nindent 4 }} +data: + {{- range $name, $value := .Values.customScripts }} + {{- $name | nindent 2 }}: | + {{- $value | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/mongodb/templates/scripts.yaml b/charts/mongodb/templates/scripts.yaml index e87ac0fa..f198a17a 100644 --- a/charts/mongodb/templates/scripts.yaml +++ b/charts/mongodb/templates/scripts.yaml @@ -27,6 +27,10 @@ data: echo "Copy extra scripts" cp /extrascripts/* /scripts fi + if [ -d /customscripts ]; then + echo "Copy custom scripts" + cp /customscripts/* /scripts + fi if [ -d /customconfig ]; then echo "Create custom mongodb config" cat /customconfig/* >>/configs/custom.conf diff --git a/charts/mongodb/templates/statefulset.yaml b/charts/mongodb/templates/statefulset.yaml index 4182a09b..8d0f811b 100644 --- a/charts/mongodb/templates/statefulset.yaml +++ b/charts/mongodb/templates/statefulset.yaml @@ -21,6 +21,7 @@ spec: annotations: checksum/customconfig: {{ include (print $.Template.BasePath "/customconfig.yaml") . | sha256sum }} checksum/secureconfig: {{ include (print $.Template.BasePath "/secureconfig.yaml") . | sha256sum }} + checksum/customscripts: {{ include (print $.Template.BasePath "/customscripts.yaml") . | sha256sum }} checksum/scripts: {{ include (print $.Template.BasePath "/scripts.yaml") . | sha256sum }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} @@ -54,6 +55,10 @@ spec: - mountPath: /extraconfigs name: extraconfigs-volume {{- end }} + {{- if .Values.customScripts }} + - mountPath: /customscripts + name: customscripts-volume + {{- end }} {{- if .Values.customConfig }} - mountPath: /customconfig name: customconfig-volume @@ -88,9 +93,9 @@ spec: startupProbe: exec: command: - - mongosh - - --eval - - "db.adminCommand('ping')" + - /bin/sh + - -c + - mongosh --eval "db.adminCommand('ping')" {{- with .Values.startupProbe }} initialDelaySeconds: {{ .initialDelaySeconds }} timeoutSeconds: {{ .timeoutSeconds }} @@ -108,9 +113,9 @@ spec: livenessProbe: exec: command: - - mongosh - - --eval - - "db.adminCommand('ping')" + - /bin/sh + - -c + - mongosh --eval "db.adminCommand('ping')" {{- with .Values.livenessProbe }} initialDelaySeconds: {{ .initialDelaySeconds }} timeoutSeconds: {{ .timeoutSeconds }} @@ -128,9 +133,9 @@ spec: readinessProbe: exec: command: - - mongosh - - --eval - - "db.adminCommand('ping')" + - /bin/sh + - -c + - mongosh --eval "db.adminCommand('ping')" {{- with .Values.readinessProbe }} initialDelaySeconds: {{ .initialDelaySeconds }} timeoutSeconds: {{ .timeoutSeconds }} @@ -209,7 +214,13 @@ spec: configMap: name: {{ .Values.extraScripts }} defaultMode: 0555 - {{- end }} + {{- end }} + {{- if .Values.customScripts }} + - name: customscripts-volume + configMap: + name: {{ include "mongodb.fullname" . }}-customscripts + defaultMode: 0555 + {{- end }} {{- if .Values.extraSecretConfigs }} - name: extraconfigs-volume secret: diff --git a/charts/mongodb/values.yaml b/charts/mongodb/values.yaml index 409c6852..717d4123 100644 --- a/charts/mongodb/values.yaml +++ b/charts/mongodb/values.yaml @@ -145,6 +145,13 @@ userDatabase: {} ## For more flexible options see extraSecretConfigs: section customConfig: | +## Optional custom scripts that can be defined inline and will be mounted as files in /docker-entrypoint-initdb.d +customScripts: {} +# 01-a-script.sh: | +# echo "hello" +# 02-another-script.sh: | +# echo "hello 2" + ## A list of existing secrets that will be mounted into the container as environment variables ## As an alternative these secrets can set the database root user and password or other options when settings.rootUsername and settings.rootPassword was not specified ## For example: Setting MONGO_INITDB_DATABASE, USERDB_USER, USERDB_PASSWORD will allow creating a user database and grant access for the given user diff --git a/charts/mysql/Chart.yaml b/charts/mysql/Chart.yaml index 7d0b0af8..3b00f281 100644 --- a/charts/mysql/Chart.yaml +++ b/charts/mysql/Chart.yaml @@ -7,6 +7,6 @@ type: application maintainers: - name: groundhog2k -version: 0.1.1 +version: 0.1.2 appVersion: "8.0.30-oracle" diff --git a/charts/mysql/README.md b/charts/mysql/README.md index 2ec87dd0..0b56cf1e 100644 --- a/charts/mysql/README.md +++ b/charts/mysql/README.md @@ -1,6 +1,6 @@ # MySQL -   +   ## Changelog @@ -117,6 +117,7 @@ helm uninstall my-release | customConfig | string | `nil` | Additional MySQL custom configuration mounted as `/etc/mysql/custom.cnf` | | extraEnvSecrets | list | `[]` | A list of existing secrets that will be mounted into the container as environment variables | | extraSecretConfigs | string | `nil` | An existing secret with files that will be mounted into the container as custom MySQL configuration files (`*.cnf`) in `/etc/mysql/conf.d` | +| customScripts | object | `nil` | Optional custom scripts that can be defined inline and will be mounted as files in `/docker-entrypoint-initdb.d` | | extraScripts | string | `nil` | An existing configMap with files that will be mounted into the container as script files (`*.sql`, `*.sh`) in `/docker-entrypoint-initdb.d` | | extraSecrets | list | `[]` | A list of additional existing secrets that will be mounted into the container | | extraSecrets[].name | string | `nil` | Name of the existing K8s secret | diff --git a/charts/mysql/RELEASENOTES.md b/charts/mysql/RELEASENOTES.md index c89b281e..e3656804 100644 --- a/charts/mysql/RELEASENOTES.md +++ b/charts/mysql/RELEASENOTES.md @@ -4,4 +4,5 @@ | :------------ | :---------- | :----------------- | | 0.1.0 | 8.0.29 | Initial version of chart | | 0.1.1 | 8.0.30 | Upgraded MySQL to 8.0.30 | +| 0.1.2 | 8.0.30 | Implemented support for custom inline init scripts | | | | | diff --git a/charts/mysql/templates/customscripts.yaml b/charts/mysql/templates/customscripts.yaml new file mode 100644 index 00000000..bf903b24 --- /dev/null +++ b/charts/mysql/templates/customscripts.yaml @@ -0,0 +1,13 @@ +{{- if .Values.customScripts }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mysql.fullname" . }}-customscripts + labels: + {{- include "mysql.labels" . | nindent 4 }} +data: + {{- range $name, $value := .Values.customScripts }} + {{- $name | nindent 2 }}: | + {{- $value | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/mysql/templates/scripts.yaml b/charts/mysql/templates/scripts.yaml index 989333e6..c80ab89d 100644 --- a/charts/mysql/templates/scripts.yaml +++ b/charts/mysql/templates/scripts.yaml @@ -12,6 +12,10 @@ data: echo "Copy extra scripts" cp /extrascripts/* /scripts fi + if [ -d /customscripts ]; then + echo "Copy custom scripts" + cp /customscripts/* /scripts + fi if [ -d /extraconfigs ]; then echo "Copy extra configs" cp /extraconfigs/* /configs diff --git a/charts/mysql/templates/statefulset.yaml b/charts/mysql/templates/statefulset.yaml index abd876cf..007a5d80 100644 --- a/charts/mysql/templates/statefulset.yaml +++ b/charts/mysql/templates/statefulset.yaml @@ -21,6 +21,7 @@ spec: annotations: checksum/customconfig: {{ include (print $.Template.BasePath "/customconfig.yaml") . | sha256sum }} checksum/secureconfig: {{ include (print $.Template.BasePath "/secureconfig.yaml") . | sha256sum }} + checksum/customscripts: {{ include (print $.Template.BasePath "/customscripts.yaml") . | sha256sum }} checksum/scripts: {{ include (print $.Template.BasePath "/scripts.yaml") . | sha256sum }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} @@ -50,6 +51,10 @@ spec: - mountPath: /extrascripts name: extrascripts-volume {{- end }} + {{- if .Values.customScripts }} + - mountPath: /customscripts + name: customscripts-volume + {{- end }} {{- if .Values.extraSecretConfigs }} - mountPath: /extraconfigs name: extraconfigs-volume @@ -212,6 +217,12 @@ spec: configMap: name: {{ include "mysql.fullname" . }}-scripts defaultMode: 0555 + {{- if .Values.customScripts }} + - name: customscripts-volume + configMap: + name: {{ include "mysql.fullname" . }}-customscripts + defaultMode: 0555 + {{- end }} {{- if .Values.extraSecretConfigs }} - name: extraconfigs-volume secret: diff --git a/charts/mysql/values.yaml b/charts/mysql/values.yaml index cdbd7e3f..8f9281b1 100644 --- a/charts/mysql/values.yaml +++ b/charts/mysql/values.yaml @@ -152,6 +152,12 @@ userDatabase: {} ## For more flexible options see extraSecretConfigs: section customConfig: | +customScripts: {} +# 01-a-script.sh: | +# echo "hello" +# 02-another-script.sh: | +# echo "hello 2" + ## A list of existing secrets that will be mounted into the container as environment variables ## As an alternative these secrets can set the database root password or optional user database when userDatabase: and rootPassword: were not specified ## For example: Setting MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD will allow creating a user database and grant access for the given user diff --git a/charts/postgres/Chart.yaml b/charts/postgres/Chart.yaml index 4cfe061e..88985572 100644 --- a/charts/postgres/Chart.yaml +++ b/charts/postgres/Chart.yaml @@ -7,6 +7,6 @@ type: application maintainers: - name: groundhog2k -version: 0.4.0 +version: 0.3.12 appVersion: "14.5" diff --git a/charts/postgres/README.md b/charts/postgres/README.md index c8f4e2a7..935a7246 100644 --- a/charts/postgres/README.md +++ b/charts/postgres/README.md @@ -1,6 +1,6 @@ # PostgreSQL -   +   ## Changelog diff --git a/charts/postgres/RELEASENOTES.md b/charts/postgres/RELEASENOTES.md index 4c71a430..73679794 100644 --- a/charts/postgres/RELEASENOTES.md +++ b/charts/postgres/RELEASENOTES.md @@ -16,5 +16,5 @@ | 0.3.9 | 14.3 | Upgraded to Postgres 14.3 | | 0.3.10 | 14.4 | Upgraded to Postgres 14.4 | | 0.3.11 | 14.5 | Upgraded to Postgres 14.5 | -| 0.4.0 | 14.5 | Implemented support for custom inline init scripts | +| 0.3.12 | 14.5 | Implemented support for custom inline init scripts | | | | | -- GitLab