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 {{- index .Values "mariadb-galera" "nameOverride" -}}
79 {{- .Values.global.mariadbGalera.service -}}
84 Choose the value of mariadb port to use.
86 {{- define "common.mariadbPort" -}}
87 {{- if .Values.global.mariadbGalera.localCluster -}}
88 {{- index .Values "mariadb-galera" "service" "internalPort" -}}
90 {{- .Values.global.mariadbGalera.internalPort -}}
95 Choose the value of secret to retrieve user value.
97 {{- define "common.mariadbSecret" -}}
98 {{- if .Values.global.mariadbGalera.localCluster -}}
99 {{ printf "%s-%s-db-user-credentials" (include "common.fullname" .) (index .Values "mariadb-galera" "nameOverride") -}}
101 {{ printf "%s-%s-%s" ( include "common.release" .) (index .Values "mariadb-init" "nameOverride") (index .Values "mariadb-init" "config" "mysqlDatabase" ) -}}
106 Choose the value of secret param to retrieve user value.
108 {{- define "common.mariadbSecretParam" -}}
109 {{ printf "password" -}}
113 Create MariDB Database via mariadb-operator
115 {{- define "common.mariadbOpDatabase" -}}
116 {{- $dot := default . .dot -}}
117 {{- $dbname := (required "'dbame' param, is required." .dbname) -}}
118 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
120 apiVersion: mariadb.mmontes.io/v1alpha1
128 collate: utf8_general_ci
132 Create MariaDB User via mariadb-operator
134 {{- define "common.mariadbOpUser" -}}
135 {{- $dot := default . .dot -}}
136 {{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}}
137 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
138 {{- $dbsecret := (required "'dbsecret' param, is required." .dbsecret) -}}
140 apiVersion: mariadb.mmontes.io/v1alpha1
145 # If you want the user to be created with a different name than the resource name
149 passwordSecretKeyRef:
150 name: {{ $dbsecret }}
152 # This field is immutable and defaults to 10
153 maxUserConnections: 100
157 Grant rights to a MariaDB User via mariadb-operator
159 {{- define "common.mariadbOpGrants" -}}
160 {{- $dot := default . .dot -}}
161 {{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}}
162 {{- $dbname := (required "'dbame' param, is required." .dbname) -}}
163 {{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}}
165 apiVersion: mariadb.mmontes.io/v1alpha1
168 name: {{ $dbuser }}-{{ $dbname }}-{{ $dbinst }}
174 database: {{ $dbname }}
176 username: {{ $dbuser }}
181 MariaDB Backup via mariadb-operator
183 {{- define "common.mariadbOpBackup" -}}
184 {{- $dot := default . .dot -}}
185 {{- $dbinst := include "common.name" $dot -}}
188 name: backup-scheduled
197 persistentVolumeClaim:
201 {{- if .Values.mariadbOperator.storageClassName }}
202 storageClassName: {{ .Values.mariadbOperator.storageClassName }}
216 Create a MariaDB instance via mariadb-operator
218 {{- define "common.mariadbOpInstance" -}}
219 {{- $dot := default . .dot -}}
220 {{- $global := $dot.Values.global -}}
221 {{- $dbinst := include "common.name" $dot -}}
222 {{- $dbrootsecret := tpl (default (include "common.mariadb.secret.rootPassSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.rootUser.externalSecret) $dot -}}
223 {{- $dbusersecret := tpl (default (include "common.mariadb.secret.userCredentialsSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.db.externalSecret) $dot -}}
225 apiVersion: mariadb.mmontes.io/v1alpha1
235 {{ if .Values.podAnnotations -}}
236 annotations: {{ toYaml .Values.podAnnotations | nindent 6 }}
240 version: {{ .Values.mariadbOperator.appVersion }}
241 rootPasswordSecretKeyRef:
242 name: {{ $dbrootsecret }}
245 repository: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.mariadbOperator.image }}
246 tag: {{ $dot.Values.mariadbOperator.appVersion }}
247 pullPolicy: IfNotPresent
249 - name: {{ include "common.namespace" . }}-docker-registry-key
251 replicas: {{ $dot.Values.replicaCount }}
253 {{- if eq (int $dot.Values.replicaCount) 1 }}
256 enabled: {{ $dot.Values.mariadbOperator.galera.enabled }}
262 repository: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ .Values.mariadbOperator.galera.agentImage }}
263 tag: {{ $dot.Values.mariadbOperator.galera.agentVersion }}
264 pullPolicy: IfNotPresent
268 authDelegatorRoleName: {{ $dbinst }}-auth
269 gracefulShutdownTimeout: 5s
272 clusterHealthyTimeout: 5m
273 clusterBootstrapTimeout: 10m
274 podRecoveryTimeout: 5m
278 repository: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ $dot.Values.mariadbOperator.galera.initImage }}
279 tag: {{ $dot.Values.mariadbOperator.galera.initVersion }}
280 pullPolicy: IfNotPresent
292 - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;"
293 initialDelaySeconds: 20
301 - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;"
302 initialDelaySeconds: 20
307 requiredDuringSchedulingIgnoredDuringExecution:
308 - topologyKey: kubernetes.io/hostname
310 - key: mariadb.mmontes.io/ha
319 # bind-address=0.0.0.0
320 # default_storage_engine=InnoDB
322 # innodb_autoinc_lock_mode=2
323 # max_allowed_packet=256M
324 # lower_case_table_names = 1
327 # collation_server=utf8_unicode_ci
328 # init_connect='SET NAMES utf8'
329 # character_set_server=utf8
331 myCnfConfigMapKeyRef:
333 name: {{ printf "%s-configuration" (include "common.fullname" $dot) }}
334 resources: {{ include "common.resources" . | nindent 4 }}
336 {{- if $dot.Values.mariadbOperator.storageClassName }}
337 storageClassName: {{ $dot.Values.k8ssandraOperator.persistence.storageClassName }}
341 storage: {{ $dot.Values.persistence.size | quote }}
344 {{- if $dot.Values.db.user }}
345 {{ include "common.mariadbOpUser" (dict "dot" . "dbuser" $dot.Values.db.user "dbinst" $dbinst "dbsecret" $dbusersecret) }}
347 {{- if $dot.Values.db.name }}
348 {{ include "common.mariadbOpDatabase" (dict "dot" . "dbname" $dot.Values.db.name "dbinst" $dbinst) }}
350 {{- if and $dot.Values.db.user $dot.Values.db.name }}
351 {{ include "common.mariadbOpGrants" (dict "dot" . "dbuser" $dot.Values.db.user "dbname" $dot.Values.db.name "dbinst" $dbinst) }}