From 82280147aabd529530bec3241182c3d9762d909e Mon Sep 17 00:00:00 2001 From: Jannik Badenhop Date: Thu, 14 Nov 2024 16:27:51 +0000 Subject: [PATCH] create new secret for moodle-database values (except password), that is used by backup/restore. so that backup/restore can work properly with all possible databases --- charts/dbp-moodle/scripts/backup.sh | 13 ++++++----- .../secrets/moodle-database-secret.yaml | 21 ++++++++++++++++++ charts/dbp-moodle/values.yaml | 22 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 charts/dbp-moodle/templates/secrets/moodle-database-secret.yaml diff --git a/charts/dbp-moodle/scripts/backup.sh b/charts/dbp-moodle/scripts/backup.sh index 9b21c68..85ec2b5 100644 --- a/charts/dbp-moodle/scripts/backup.sh +++ b/charts/dbp-moodle/scripts/backup.sh @@ -77,12 +77,13 @@ cd "${backup_dir}" echo "=== Start DB dump ===" export DATE=$( date "+%Y-%m-%d" ) -{{ if .Values.mariadb.enabled }} -MYSQL_PWD="$DATABASE_PASSWORD" mysqldump -h {{ .Release.Name }}-mariadb -P {{ .Values.mariadb.primary.containerPorts.mysql }} -u {{ .Values.mariadb.auth.username }} {{ .Values.mariadb.auth.database }} > moodle_mariadb_dump_$DATE.sql -gzip moodle_mariadb_dump_$DATE.sql -{{ else }} -PGPASSWORD="$DATABASE_PASSWORD" pg_dump -h {{ .Release.Name }}-postgresql -p {{ .Values.postgresql.containerPorts.postgresql }} -U postgres {{ .Values.postgresql.auth.database }} > moodle_postgresqldb_dump_$DATE.sql -gzip moodle_postgresqldb_dump_$DATE.sql +# shellcheck disable=all +{{ if or .Values.mariadb.enabled (eq .Values.moodle.externalDatabase.type "mariadb") }} +MYSQL_PWD="$DATABASE_PASSWORD" mysqldump -h "$DATABASE_HOST" -P "$DATABASE_PORT" -u "$DATABASE_USER" "$DATABASE_NAME" > "moodle_mariadb_dump_${DATE}.sql" +gzip "moodle_mariadb_dump_${DATE}.sql" +{{ else if or .Values.postgresql.enabled (eq .Values.moodle.externalDatabase.type "pgsql") }} +PGPASSWORD="$DATABASE_PASSWORD" pg_dump -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" "$DATABASE_NAME" > "moodle_postgresqldb_dump_${DATE}.sql" +gzip "moodle_postgresqldb_dump_${DATE}.sql" {{ end }} # Get moodle folder diff --git a/charts/dbp-moodle/templates/secrets/moodle-database-secret.yaml b/charts/dbp-moodle/templates/secrets/moodle-database-secret.yaml new file mode 100644 index 0000000..1755f06 --- /dev/null +++ b/charts/dbp-moodle/templates/secrets/moodle-database-secret.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: "moodle-database" + namespace: "{{ .Release.Namespace }}" +stringData: + {{ if .Values.moodle.mariadb.enabled -}} + type: "mariadb" + host: "moodle-mariadb-0" + port: "3306" + user: "{{ .Values.moodle.mariadb.username }}" + name: "{{ .Values.moodle.mariadb.database }}" + {{- else if .Values.moodle.externalDatabase -}} + type: "{{ .Values.moodle.externalDatabase.type }}" + host: "{{ .Values.moodle.externalDatabase.host }}" + port: "{{ .Values.moodle.externalDatabase.port }}" + user: "{{ .Values.moodle.externalDatabase.user }}" + name: "{{ .Values.moodle.externalDatabase.database }}" + {{- end }} + diff --git a/charts/dbp-moodle/values.yaml b/charts/dbp-moodle/values.yaml index b34c6a8..e796faa 100644 --- a/charts/dbp-moodle/values.yaml +++ b/charts/dbp-moodle/values.yaml @@ -262,6 +262,8 @@ moodle: # -- The mariadb included in bitnami/moodle chart. For this chart usage of mariadb.enabled with moodle.externalDatabase.type="mariadb" is recommended mariadb: enabled: false + database: bitnami_moodle + username: bn_moodle externalDatabase: # -- Type of DB to provision, possible values are "mariadb" and "pgsql" type: "mariadb" @@ -556,6 +558,26 @@ backup-cronjob: name: "moodle-backup-job" create: false env: + - name: DATABASE_HOST + valueFrom: + secretKeyRef: + name: moodle-database + key: host + - name: DATABASE_PORT + valueFrom: + secretKeyRef: + name: moodle-database + key: port + - name: DATABASE_NAME + valueFrom: + secretKeyRef: + name: moodle-database + key: name + - name: DATABASE_USER + valueFrom: + secretKeyRef: + name: moodle-database + key: user - name: DATABASE_PASSWORD valueFrom: secretKeyRef: