From 408e562e4bdf9b794c69c19b7f827fa8500ce9a1 Mon Sep 17 00:00:00 2001 From: kjeld Schouten-Lebbing Date: Mon, 15 Nov 2021 17:52:37 +0100 Subject: [PATCH] feat(common): add mariadb support layer --- charts/library/common/Chart.yaml | 2 +- .../common/templates/lib/chart/_setup.tpl | 3 ++ .../lib/dependencies/_mariadbInjector.tpl | 46 +++++++++++++++++++ charts/library/common/values.yaml | 8 ++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 charts/library/common/templates/lib/dependencies/_mariadbInjector.tpl diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 584a18b7639..b08d9fd3a78 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 8.5.7 +version: 8.6.0 diff --git a/charts/library/common/templates/lib/chart/_setup.tpl b/charts/library/common/templates/lib/chart/_setup.tpl index e0213f8e675..034bc9f03fe 100644 --- a/charts/library/common/templates/lib/chart/_setup.tpl +++ b/charts/library/common/templates/lib/chart/_setup.tpl @@ -7,4 +7,7 @@ {{- /* Autogenerate redis passwords if needed */ -}} {{- include "common.dependencies.redis.injector" . }} + +{{- /* Autogenerate mariadb passwords if needed */ -}} +{{- include "common.dependencies.mariadb.injector" . }} {{- end -}} diff --git a/charts/library/common/templates/lib/dependencies/_mariadbInjector.tpl b/charts/library/common/templates/lib/dependencies/_mariadbInjector.tpl new file mode 100644 index 00000000000..1f50b2cd46c --- /dev/null +++ b/charts/library/common/templates/lib/dependencies/_mariadbInjector.tpl @@ -0,0 +1,46 @@ +{{/* +This template generates a random password and ensures it persists across updates/edits to the chart +*/}} +{{- define "common.dependencies.mariadb.injector" -}} +{{- $pghost := printf "%v-%v" .Release.Name "mariadb" }} + +{{- if .Values.mariadb.enabled }} +--- +apiVersion: v1 +kind: Secret +metadata: + labels: + {{- include "common.labels" . | nindent 4 }} + name: mariamariadbcreds +{{- $dbprevious := lookup "v1" "Secret" .Release.Namespace "mariadbcreds" }} +{{- $dbPass := "" }} +{{- $rootPass := "" }} +data: +{{- if $dbprevious }} + {{- $dbPass = ( index $dbprevious.data "mariadb-password" ) | b64dec }} + {{- $rootPass = ( index $dbprevious.data "mariadb-root-password" ) | b64dec }} + mariadb-password: {{ ( index $dbprevious.data "mariadb-password" ) }} + mariadb-root-password: {{ ( index $dbprevious.data "mariadb-root-password" ) }} +{{- else }} + {{- $dbPass = randAlphaNum 50 }} + {{- $rootPass = randAlphaNum 50 }} + mariadb-password: {{ $dbPass | b64enc | quote }} + mariadb-root-password: {{ $rootPass | b64enc | quote }} +{{- end }} + url: {{ ( printf "sql://%v:%v@%v-mariadb:3306/%v" .Values.mariadb.mariadbUsername $dbPass .Release.Name .Values.mariadb.mariadbDatabase ) | b64enc | quote }} + urlnossl: {{ ( printf "sql://%v:%v@%v-mariadb:3306/%v?sslmode=disable" .Values.mariadb.mariadbUsername $dbPass .Release.Name .Values.mariadb.mariadbDatabase ) | b64enc | quote }} + plainporthost: {{ ( printf "%v-%v" .Release.Name "mariadb" ) | b64enc | quote }} + plainhost: {{ ( printf "%v-%v" .Release.Name "mariadb" ) | b64enc | quote }} + jdbc: {{ ( printf "jdbc:sqlserver://%v-mariadb:3306/%v" .Release.Name .Values.mariadb.mariadbDatabase ) | b64enc | quote }} +type: Opaque +{{- $_ := set .Values.mariadb "mariadbPassword" ( $dbPass | quote ) }} +{{- $_ := set .Values.mariadb "mariadbRootPassword" ( $rootPass | quote ) }} +{{- $_ := set .Values.mariadb.url "plain" ( ( printf "%v-%v" .Release.Name "mariadb" ) | quote ) }} +{{- $_ := set .Values.mariadb.url "plainhost" ( ( printf "%v-%v" .Release.Name "mariadb" ) | quote ) }} +{{- $_ := set .Values.mariadb.url "plainport" ( ( printf "%v-%v:3306" .Release.Name "mariadb" ) | quote ) }} +{{- $_ := set .Values.mariadb.url "plainporthost" ( ( printf "%v-%v:3306" .Release.Name "mariadb" ) | quote ) }} +{{- $_ := set .Values.mariadb.url "complete" ( ( printf "sql://%v:%v@%v-mariadb:3306/%v" .Values.mariadb.mariadbUsername $dbPass .Release.Name .Values.mariadb.mariadbDatabase ) | quote ) }} +{{- $_ := set .Values.mariadb.url "jdbc" ( ( printf "jdbc:sqlserver://%v-mariadb:3306/%v" .Release.Name .Values.mariadb.mariadbDatabase ) | quote ) }} + +{{- end }} +{{- end -}} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 58a050e1e8c..ba07511fafd 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -954,3 +954,11 @@ redis: existingSecret: "rediscreds" # -- can be used to make an easy accessable note which URLS to use to access the DB. url: {} + +# -- mariadb dependency configuration +# @default -- See below +mariadb: + enabled: false + existingSecret: "mariadbcreds" + # -- can be used to make an easy accessable note which URLS to use to access the DB. + url: {}