2 # Copyright © 2019 Orange
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 UID of mariadb root password
20 {{- define "common.mariadb.secret.rootPassUID" -}}
21 {{- printf "db-root-password" }}
25 Name of mariadb secret
27 {{- define "common.mariadb.secret._secretName" -}}
28 {{- $global := .dot }}
29 {{- $chartName := tpl .chartName $global -}}
30 {{- include "common.secret.genName" (dict "global" $global "uid" (include .uidTemplate $global) "chartName" $chartName) }}
34 Name of mariadb root password secret
36 {{- define "common.mariadb.secret.rootPassSecretName" -}}
37 {{- include "common.mariadb.secret._secretName" (set . "uidTemplate" "common.mariadb.secret.rootPassUID") }}
41 UID of mariadb user credentials
43 {{- define "common.mariadb.secret.userCredentialsUID" -}}
44 {{- printf "db-user-credentials" }}
48 UID of mariadb backup credentials
50 {{- define "common.mariadb.secret.backupCredentialsUID" -}}
51 {{- printf "db-backup-credentials" }}
55 Name of mariadb user credentials secret
57 {{- define "common.mariadb.secret.userCredentialsSecretName" -}}
58 {{- include "common.mariadb.secret._secretName" (set . "uidTemplate" "common.mariadb.secret.userCredentialsUID") }}
62 Choose the name of the mariadb app label to use.
64 {{- define "common.mariadbAppName" -}}
65 {{- if .Values.global.mariadbGalera.localCluster -}}
66 {{- index .Values "mariadb-galera" "nameOverride" -}}
68 {{- .Values.global.mariadbGalera.nameOverride -}}
73 Choose the name of the mariadb service to use.
75 {{- define "common.mariadbService" -}}
76 {{- if .Values.global.mariadbGalera.localCluster -}}
77 {{- if and .Values.global.mariadbGalera.useOperator (index .Values "mariadb-galera" "mariadbOperator" "galera" "enabled") }}
78 {{- printf "%s-primary" (index .Values "mariadb-galera" "nameOverride") -}}
80 {{- index .Values "mariadb-galera" "nameOverride" -}}
83 {{- if and .Values.global.mariadbGalera.useOperator }}
84 {{- printf "%s-primary" (.Values.global.mariadbGalera.service) }}
86 {{- .Values.global.mariadbGalera.service -}}
92 Choose the value of mariadb port to use.
94 {{- define "common.mariadbPort" -}}
95 {{- if .Values.global.mariadbGalera.localCluster -}}
96 {{- index .Values "mariadb-galera" "service" "internalPort" -}}
98 {{- .Values.global.mariadbGalera.internalPort -}}
103 Choose the value of secret to retrieve user value.
105 {{- define "common.mariadbSecret" -}}
106 {{- if .Values.global.mariadbGalera.localCluster -}}
107 {{ printf "%s-%s-db-user-credentials" (include "common.fullname" .) (index .Values "mariadb-galera" "nameOverride") -}}
109 {{ printf "%s-%s-%s" ( include "common.release" .) (index .Values "mariadb-init" "nameOverride") (index .Values "mariadb-init" "config" "mysqlDatabase" ) -}}
114 Choose the value of secret param to retrieve user value.
116 {{- define "common.mariadbSecretParam" -}}
117 {{ printf "password" -}}
121 Create MariDB Database via mariadb-operator
123 {{- define "common.mariadbOpDatabase" -}}
124 {{- $dot := default . .dot -}}
125 {{- $dbname := (required "'dbame' param, is required." .dbname) -}}
126 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
128 apiVersion: mariadb.mmontes.io/v1alpha1
131 name: {{ $dbinst }}-{{ $dbname }}
137 collate: utf8_general_ci
142 Create MariaDB User via mariadb-operator
144 {{- define "common.mariadbOpUser" -}}
145 {{- $dot := default . .dot -}}
146 {{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}}
147 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
148 {{- $dbsecret := (required "'dbsecret' param, is required." .dbsecret) -}}
150 apiVersion: mariadb.mmontes.io/v1alpha1
153 name: {{ $dbinst }}-{{ $dbuser }}
158 passwordSecretKeyRef:
159 name: {{ $dbsecret }}
161 # This field is immutable and defaults to 10
162 maxUserConnections: 100
167 Grant rights to a MariaDB User via mariadb-operator
169 {{- define "common.mariadbOpGrants" -}}
170 {{- $dot := default . .dot -}}
171 {{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}}
172 {{- $dbname := (required "'dbame' param, is required." .dbname) -}}
173 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
175 apiVersion: mariadb.mmontes.io/v1alpha1
178 name: {{ $dbuser }}-{{ $dbname }}-{{ $dbinst }}
184 database: {{ $dbname }}
186 username: {{ $dbuser }}
192 MariaDB Backup via mariadb-operator
194 {{- define "common.mariadbOpBackup" -}}
195 {{- $dot := default . .dot -}}
196 {{- $dbinst := include "common.name" $dot -}}
199 name: backup-scheduled
208 persistentVolumeClaim:
212 {{- if .Values.mariadbOperator.storageClassName }}
213 storageClassName: {{ .Values.mariadbOperator.storageClassName }}
227 Create a MariaDB instance via mariadb-operator
229 {{- define "common.mariadbOpInstance" -}}
230 {{- $dot := default . .dot -}}
231 {{- $global := $dot.Values.global -}}
232 {{- $dbinst := include "common.name" $dot -}}
233 {{- $dbrootsecret := tpl (default (include "common.mariadb.secret.rootPassSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.rootUser.externalSecret) $dot -}}
234 {{- $dbusersecret := tpl (default (include "common.mariadb.secret.userCredentialsSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.db.externalSecret) $dot -}}
236 apiVersion: mariadb.mmontes.io/v1alpha1
246 {{ if .Values.podAnnotations -}}
247 annotations: {{ toYaml .Values.podAnnotations | nindent 6 }}
251 version: {{ .Values.mariadbOperator.appVersion }}
252 rootPasswordSecretKeyRef:
253 name: {{ $dbrootsecret }}
255 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.mariadbOperator.image }}:{{ $dot.Values.mariadbOperator.appVersion }}
256 imagePullPolicy: IfNotPresent
258 - name: {{ include "common.namespace" . }}-docker-registry-key
260 replicas: {{ $dot.Values.replicaCount }}
261 {{- if $dot.Values.mariadbOperator.galera.enabled }}
267 image: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ .Values.mariadbOperator.galera.agentImage }}:{{ $dot.Values.mariadbOperator.galera.agentVersion }}
268 imagePullPolicy: IfNotPresent
272 authDelegatorRoleName: {{ $dbinst }}-auth
273 gracefulShutdownTimeout: 5s
276 clusterHealthyTimeout: 5m0s
277 clusterBootstrapTimeout: 10m0s
278 podRecoveryTimeout: 5m0s
279 podSyncTimeout: 10m0s
281 image: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ $dot.Values.mariadbOperator.galera.initImage }}:{{ $dot.Values.mariadbOperator.galera.initVersion }}
282 imagePullPolicy: IfNotPresent
284 {{- if .Values.mariadbOperator.storageClassName }}
285 storageClassName: {{ .Values.mariadbOperator.storageClassName }}
298 - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;"
299 initialDelaySeconds: 20
307 - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;"
308 initialDelaySeconds: 20
313 requiredDuringSchedulingIgnoredDuringExecution:
314 - topologyKey: kubernetes.io/hostname
316 - key: mariadb.mmontes.io/ha
325 # bind-address=0.0.0.0
326 # default_storage_engine=InnoDB
328 # innodb_autoinc_lock_mode=2
329 # max_allowed_packet=256M
330 # lower_case_table_names = 1
333 # collation_server=utf8_unicode_ci
334 # init_connect='SET NAMES utf8'
335 # character_set_server=utf8
337 myCnfConfigMapKeyRef:
339 name: {{ printf "%s-configuration" (include "common.fullname" $dot) }}
340 resources: {{ include "common.resources" . | nindent 4 }}
342 {{- if $dot.Values.mariadbOperator.storageClassName }}
343 storageClassName: {{ $dot.Values.mariadbOperator.storageClassName }}
347 storage: {{ $dot.Values.mariadbOperator.persistence.size | quote }}
350 {{- if $dot.Values.db.user }}
351 {{ include "common.mariadbOpUser" (dict "dot" . "dbuser" $dot.Values.db.user "dbinst" $dbinst "dbsecret" $dbusersecret) }}
353 {{- if $dot.Values.db.name }}
354 {{ include "common.mariadbOpDatabase" (dict "dot" . "dbname" $dot.Values.db.name "dbinst" $dbinst) }}
356 {{- if and $dot.Values.db.user $dot.Values.db.name }}
357 {{ include "common.mariadbOpGrants" (dict "dot" . "dbuser" $dot.Values.db.user "dbname" $dot.Values.db.name "dbinst" $dbinst) }}