feat(helm): support external MariaDB (#1068)
This commit is contained in:
@@ -23,3 +23,4 @@ dependencies:
|
|||||||
- name: mariadb
|
- name: mariadb
|
||||||
version: 0.16.0
|
version: 0.16.0
|
||||||
repository: oci://registry-1.docker.io/cloudpirates
|
repository: oci://registry-1.docker.io/cloudpirates
|
||||||
|
condition: mariadb.enabled
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
{{/*
|
||||||
|
Validation — database configuration preconditions.
|
||||||
|
|
||||||
|
Ensures that the bundled MariaDB subchart and external database
|
||||||
|
configuration are not both specified, and that at least one is set.
|
||||||
|
*/}}
|
||||||
|
{{- define "grimmory.validate-database" -}}
|
||||||
|
{{- if and .Values.mariadb.enabled .Values.externalDatabase.enabled }}
|
||||||
|
{{- fail "mariadb.enabled and externalDatabase.enabled are mutually exclusive: disable the bundled MariaDB subchart or remove the externalDatabase" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if and (not .Values.mariadb.enabled) (not .Values.externalDatabase.enabled) }}
|
||||||
|
{{- fail "At least one database must be set: enable mariadb or provide an externalDatabase" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- if and (not .host) (or (not .existingSecret.enabled) (and .existingSecret.enabled (not .existingSecret.hostnameKey)))}}
|
||||||
|
{{- fail "No host is set for the externalDatabase." }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if and (not .password) (or (not .existingSecret.enabled) (and .existingSecret.enabled (not .existingSecret.passwordKey)))}}
|
||||||
|
{{- fail "No password is set for the externalDatabase." }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Connection helpers — resolve a single database configuration value.
|
||||||
|
|
||||||
|
Usage: {{ include "grimmory.dbHostname" . }}
|
||||||
|
*/}}
|
||||||
|
{{- define "grimmory.dbHostname" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- if and .existingSecret.enabled .existingSecret.hostnameKey }}
|
||||||
|
{{- fail "Chart bug, this helper should not be called when an existing secret is set" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .host }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-mariadb" .Release.Name }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "grimmory.dbPort" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- if and .existingSecret.enabled .existingSecret.portKey }}
|
||||||
|
{{- fail "Chart bug, this helper should not be called when an existing secret is set" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .port }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .Values.mariadb.service.port }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "grimmory.dbName" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- if and .existingSecret.enabled .existingSecret.databaseKey }}
|
||||||
|
{{- fail "Chart bug, this helper should not be called when an existing secret is set" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .database }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .Values.mariadb.auth.database }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "grimmory.dbUserName" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- if and .existingSecret.enabled .existingSecret.usernameKey }}
|
||||||
|
{{- fail "Chart bug, this helper should not be called when an existing secret is set" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .username }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- .Values.mariadb.auth.username }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
|
||||||
|
{{- define "grimmory.dbPasswordSecretName" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- required "No secretName was set for the externalDatabase existingSecret." .existingSecret.secretName }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- with .Values.mariadb.auth }}
|
||||||
|
{{- if .existingSecret }}
|
||||||
|
{{- .existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-mariadb" $.Release.Name }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "grimmory.dbPasswordSecretKey" -}}
|
||||||
|
{{- if .Values.externalDatabase.enabled }}
|
||||||
|
{{- with .Values.externalDatabase }}
|
||||||
|
{{- required "No passwordKey was set for the externalDatabase existingSecret." .existingSecret.passwordKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- with .Values.mariadb.auth }}
|
||||||
|
{{- if not .existingSecret }}
|
||||||
|
{{- "mariadb-password" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- required "No userPasswordKey was set for the built-in database existingSecret" .secretKeys.userPasswordKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
{{- include "grimmory.validate-database" . }}
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ include "grimmory.fullname" . }}
|
name: {{ include "grimmory.fullname" . }}
|
||||||
labels:
|
labels:
|
||||||
@@ -32,23 +33,41 @@ spec:
|
|||||||
initContainers:
|
initContainers:
|
||||||
- name: wait-for-database
|
- name: wait-for-database
|
||||||
image: busybox:1.36
|
image: busybox:1.36
|
||||||
|
env:
|
||||||
|
- name: GRIMMORY_DB_HOST
|
||||||
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.hostnameKey }}
|
||||||
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .secretName }}
|
||||||
|
key: {{ .hostnameKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ include "grimmory.dbHostname" . | quote }}
|
||||||
|
{{- end }}
|
||||||
|
- name: GRIMMORY_DB_PORT
|
||||||
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.portKey }}
|
||||||
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .secretName }}
|
||||||
|
key: {{ .portKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ include "grimmory.dbPort" . | quote }}
|
||||||
|
{{- end }}
|
||||||
command:
|
command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
echo "Waiting for database on port {{ .Values.mariadb.service.port }}..."
|
echo "Waiting for database at $GRIMMORY_DB_HOST:$GRIMMORY_DB_PORT ..."
|
||||||
until nc -z -v -w5 {{ .Release.Name }}-mariadb {{ .Values.mariadb.service.port }}; do
|
until nc -z -v -w5 "$GRIMMORY_DB_HOST" "$GRIMMORY_DB_PORT"; do
|
||||||
echo "Waiting for database..."
|
echo "Waiting for database..."
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
echo "Database is available!"
|
echo "Database is available!"
|
||||||
resources:
|
resources:
|
||||||
requests:
|
{{- toYaml .Values.initContainer.resources | nindent 12 }}
|
||||||
cpu: 10m
|
|
||||||
memory: 16Mi
|
|
||||||
limits:
|
|
||||||
cpu: 50m
|
|
||||||
memory: 32Mi
|
|
||||||
containers:
|
containers:
|
||||||
- name: {{ .Chart.Name }}
|
- name: {{ .Chart.Name }}
|
||||||
{{- with .Values.securityContext }}
|
{{- with .Values.securityContext }}
|
||||||
@@ -62,22 +81,58 @@ spec:
|
|||||||
containerPort: {{ .Values.service.port }}
|
containerPort: {{ .Values.service.port }}
|
||||||
#protocol: TCP
|
#protocol: TCP
|
||||||
env:
|
env:
|
||||||
- name: DATABASE_URL
|
- name: DATABASE_HOST
|
||||||
value: jdbc:mariadb://{{ .Release.Name }}-mariadb:{{ .Values.mariadb.service.port }}/{{ .Values.mariadb.auth.database }}
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.hostnameKey }}
|
||||||
- name: DATABASE_USERNAME
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
value: {{ .Values.mariadb.auth.username }}
|
|
||||||
- name: DATABASE_PASSWORD
|
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
{{- if .Values.mariadb.auth.existingSecret }}
|
name: {{ .secretName }}
|
||||||
name: {{ .Values.mariadb.auth.existingSecret }}
|
key: {{ .hostnameKey }}
|
||||||
{{- else }}
|
|
||||||
name: {{ .Release.Name }}-mariadb
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
key: mariadb-password
|
{{- else }}
|
||||||
{{- with .Values.startupProbe }}
|
value: {{ include "grimmory.dbHostname" . | quote }}
|
||||||
startupProbe:
|
{{- end }}
|
||||||
{{- toYaml . | nindent 12 }}
|
- name: DATABASE_PORT
|
||||||
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.portKey }}
|
||||||
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .secretName }}
|
||||||
|
key: {{ .portKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ include "grimmory.dbPort" . | quote }}
|
||||||
|
{{- end }}
|
||||||
|
- name: DATABASE_USERNAME
|
||||||
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.usernameKey }}
|
||||||
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .secretName }}
|
||||||
|
key: {{ .usernameKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ include "grimmory.dbUserName" . }}
|
||||||
|
{{- end }}
|
||||||
|
- name: DATABASE_PASSWORD
|
||||||
|
{{- if or (and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled) (not .Values.externalDatabase.enabled) }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "grimmory.dbPasswordSecretName" . }}
|
||||||
|
key: {{ include "grimmory.dbPasswordSecretKey" . }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ .Values.externalDatabase.password | quote }}
|
||||||
|
{{- end }}
|
||||||
|
- name: DATABASE_NAME
|
||||||
|
{{- if and .Values.externalDatabase.enabled .Values.externalDatabase.existingSecret.enabled .Values.externalDatabase.existingSecret.databaseKey }}
|
||||||
|
{{- with .Values.externalDatabase.existingSecret }}
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .secretName }}
|
||||||
|
key: {{ .databaseKey }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
value: {{ include "grimmory.dbName" . | quote }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with .Values.livenessProbe }}
|
{{- with .Values.livenessProbe }}
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
|
|||||||
@@ -15,6 +15,37 @@ mariadb:
|
|||||||
# userPasswordKey: mariadb-password
|
# userPasswordKey: mariadb-password
|
||||||
service:
|
service:
|
||||||
port: 3306
|
port: 3306
|
||||||
|
|
||||||
|
# Mutually exclusive with the bundled mariadb subchart above.
|
||||||
|
# Set mariadb.enabled to false and externalDatabase.enabled to true to use this.
|
||||||
|
externalDatabase:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
## Database host
|
||||||
|
host: ""
|
||||||
|
|
||||||
|
## Database port
|
||||||
|
port: 3306
|
||||||
|
|
||||||
|
## Database user
|
||||||
|
username: grimmory
|
||||||
|
|
||||||
|
## Database password
|
||||||
|
password: ""
|
||||||
|
|
||||||
|
## Database name
|
||||||
|
database: grimmory
|
||||||
|
|
||||||
|
## Use an existing secret
|
||||||
|
existingSecret:
|
||||||
|
enabled: false
|
||||||
|
# secretName: nameofsecret
|
||||||
|
# usernameKey: db-username
|
||||||
|
# passwordKey: db-password
|
||||||
|
# hostnameKey: db-hostname
|
||||||
|
# portKey: db-port
|
||||||
|
# databaseKey: db-name
|
||||||
|
|
||||||
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
|
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
|
||||||
image:
|
image:
|
||||||
repository: grimmory/grimmory
|
repository: grimmory/grimmory
|
||||||
@@ -124,6 +155,16 @@ persistence:
|
|||||||
existingClaim: ""
|
existingClaim: ""
|
||||||
extraVolumes: []
|
extraVolumes: []
|
||||||
extraVolumeMounts: []
|
extraVolumeMounts: []
|
||||||
|
|
||||||
|
initContainer:
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 16Mi
|
||||||
|
limits:
|
||||||
|
cpu: 50m
|
||||||
|
memory: 32Mi
|
||||||
|
|
||||||
nodeSelector: {}
|
nodeSelector: {}
|
||||||
tolerations: []
|
tolerations: []
|
||||||
affinity: {}
|
affinity: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user