blob: 22832c936db5eb8226f807a9a219fb0b8687ed21 [file] [log] [blame]
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +01001{{/*
a.sreekumarcf3133d2021-09-10 14:41:30 +01002# Copyright © 2018 Amdocs
3# Copyright © 2018,2021 Bell Canada
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +01004# Copyright © 2019 Samsung Electronics
5# Copyright © 2019-2020 Orange
6# Copyright © 2020 Bitnami
vaibhavjayasea9aee02018-08-31 06:22:26 +00007#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010019*/}}
vaibhavjayasea9aee02018-08-31 06:22:26 +000020
milaszki804afe72020-07-07 12:23:07 +000021apiVersion: apps/v1
vitalied1e5876c2018-03-29 10:24:27 -050022kind: StatefulSet
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010023metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
vitalied1e5876c2018-03-29 10:24:27 -050024spec:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010025 podManagementPolicy: {{ .Values.podManagementPolicy }}
vitalied1e5876c2018-03-29 10:24:27 -050026 replicas: {{ .Values.replicaCount }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010027 selector: {{- include "common.selectors" . | nindent 4 }}
28 serviceName: {{ include "common.servicename" . }}-headless
29 updateStrategy:
30 type: {{ .Values.updateStrategy.type }}
31 {{- if (eq "Recreate" .Values.updateStrategy.type) }}
32 rollingUpdate: null
vitalied1e5876c2018-03-29 10:24:27 -050033 {{- end }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010034 template:
35 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
36 spec:
37 {{ include "common.podSecurityContext" . | indent 6 | trim }}
38 initContainers:
39 # we shouldn't need this but for unknown reason, it's fsGroup is not
40 # applied
41 - name: fix-permission
42 command:
43 - /bin/sh
44 args:
45 - -c
46 - |
47 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /data
48 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /bootstrap/
49 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /tmp/
50 {{- if .Values.mariadbConfiguration }}
51 cp /config/my.cnf /actual/my.cnf
52 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /actual
53 {{- end }}
54 image: {{ include "repositoryGenerator.image.busybox" . }}
55 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
56 securityContext:
57 runAsUser: 0
58 volumeMounts:
59 - name: previous-boot
60 mountPath: /bootstrap
61 - name: mariadb-tmp-folder
62 mountPath: /tmp
63 - name: {{ include "common.fullname" . }}
64 mountPath: /data
65 {{- if .Values.mariadbConfiguration }}
66 - name: mariadb-galera-starting-config
67 mountPath: /config/my.cnf
68 subPath: my.cnf
69 - name: mariadb-galera-actual-config
70 mountPath: /actual
71 {{- end }}
vitalied1e5876c2018-03-29 10:24:27 -050072 containers:
pramod47b1b822018-08-28 15:41:45 +000073 - name: {{ include "common.name" . }}
Sylvain Desbureaux41066142020-11-19 17:12:46 +010074 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
vitalied1e5876c2018-03-29 10:24:27 -050075 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010076 command:
77 - bash
78 - -ec
79 - |
80 {{- if (not (empty (.Values.galera.bootstrap.bootstrapFromNode | quote)))}}
Jozsef Csongvaiebc553b2022-03-04 16:08:26 -050081 {{- $fullname := include "common.fullname" . }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010082 {{- $bootstrapFromNode := int .Values.galera.bootstrap.bootstrapFromNode }}
83 # Bootstrap from the indicated node
84 NODE_ID="${MY_POD_NAME#"{{ $fullname }}-"}"
85 if [[ "$NODE_ID" -eq "{{ $bootstrapFromNode }}" ]]; then
86 export MARIADB_GALERA_CLUSTER_BOOTSTRAP=yes
87 export MARIADB_GALERA_FORCE_SAFETOBOOTSTRAP={{ ternary "yes" "no" .Values.galera.bootstrap.forceSafeToBootstrap }}
88 fi
89 {{- end }}
90 exec /opt/bitnami/scripts/mariadb-galera/entrypoint.sh /opt/bitnami/scripts/mariadb-galera/run.sh
vitalied1e5876c2018-03-29 10:24:27 -050091 env:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010092 - name: MY_POD_NAME
vitalied1e5876c2018-03-29 10:24:27 -050093 valueFrom:
94 fieldRef:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010095 fieldPath: metadata.name
96 - name: BITNAMI_DEBUG
97 value: {{ ternary "true" "false" .Values.debug | quote }}
Sylvain Desbureauxdb1a6722021-01-04 14:45:11 +010098 - name: MARIADB_INIT_SLEEP_TIME
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010099 value: {{ .Values.init_sleep_time | quote }}
100 - name: MARIADB_GALERA_CLUSTER_NAME
101 value: {{ .Values.galera.name | quote }}
102 - name: MARIADB_GALERA_CLUSTER_ADDRESS
103 value: "gcomm://{{ template "common.name" . }}-headless.{{ include "common.namespace" . }}.svc.{{ .Values.global.clusterDomain }}"
Sylvain Desbureauxcded1102021-01-18 14:53:55 +0100104 # Bitnami init script don't behave well in dual stack env.
105 # set it here as long as https://github.com/bitnami/charts/issues/4077 is not solved.
106 - name: MARIADB_GALERA_NODE_ADDRESS
107 valueFrom:
108 fieldRef:
109 fieldPath: status.podIP
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100110 - name: MARIADB_ROOT_USER
111 value: {{ .Values.rootUser.user | quote }}
112 - name: MARIADB_ROOT_PASSWORD
113 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 14 }}
114 - name: MARIADB_USER
115 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "login") | indent 14 }}
116 - name: MARIADB_PASSWORD
117 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "password") | indent 14 }}
118 - name: MARIADB_DATABASE
119 value: {{ .Values.db.name | quote }}
120 - name: MARIADB_GALERA_MARIABACKUP_USER
121 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.backupCredentialsUID" .) "key" "login") | indent 14 }}
122 - name: MARIADB_GALERA_MARIABACKUP_PASSWORD
123 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.backupCredentialsUID" .) "key" "password") | indent 14 }}
124 {{- if .Values.extraFlags }}
125 - name: MARIADB_EXTRA_FLAGS
126 value: {{ .Values.extraFlags | quote }}
127 {{- end }}
128 ports: {{ include "common.containerPorts" . | nindent 12 }}
129 {{- if .Values.livenessProbe.enabled }}
130 livenessProbe:
131 exec:
132 command:
Sylvain Desbureaux7f09e762021-05-05 09:20:18 +0200133 - sh
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100134 - -ec
135 - |
136 exec mysqladmin status -u$MARIADB_ROOT_USER -p$MARIADB_ROOT_PASSWORD
137 initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
138 periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
139 timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
140 successThreshold: {{ .Values.livenessProbe.successThreshold }}
141 failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
142 {{- end }}
143 {{- if .Values.readinessProbe.enabled }}
vitalied1e5876c2018-03-29 10:24:27 -0500144 readinessProbe:
145 exec:
146 command:
Sylvain Desbureaux7f09e762021-05-05 09:20:18 +0200147 - sh
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100148 - -ec
149 - |
150 exec mysqladmin status -u$MARIADB_ROOT_USER -p$MARIADB_ROOT_PASSWORD
151 initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
152 periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
153 timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
154 successThreshold: {{ .Values.readinessProbe.successThreshold }}
155 failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
156 {{- end }}
Sylvain Desbureaux7f09e762021-05-05 09:20:18 +0200157 {{- if .Values.startupProbe.enabled }}
158 startupProbe:
159 exec:
160 command:
161 - sh
162 - -ec
163 - |
164 exec mysqladmin status -u$MARIADB_ROOT_USER -p$MARIADB_ROOT_PASSWORD
165 initialDelaySeconds: {{ .Values.startupProbe.initialDelaySeconds }}
166 periodSeconds: {{ .Values.startupProbe.periodSeconds }}
167 timeoutSeconds: {{ .Values.startupProbe.timeoutSeconds }}
168 successThreshold: {{ .Values.startupProbe.successThreshold }}
169 failureThreshold: {{ .Values.startupProbe.failureThreshold }}
170 {{- end }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100171 resources: {{ include "common.resources" . | nindent 12 }}
172 volumeMounts:
173 - name: previous-boot
174 mountPath: /opt/bitnami/mariadb/.bootstrap
175 - name: {{ include "common.fullname" . }}
176 mountPath: /bitnami/mariadb
177 - name: mariadb-tmp-folder
178 mountPath: /opt/bitnami/mariadb/tmp
179 {{- if .Values.mariadbConfiguration }}
180 - name: mariadb-galera-actual-config
181 mountPath: /opt/bitnami/mariadb/conf
182 {{- end }}
183 {{- if default false .Values.global.metrics.enabled }}
184 - name: {{ include "common.name" . }}-metrics
185 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.metrics.image }}
186 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.metrics.pullPolicy | quote}}
187 env:
188 - name: MARIADB_METRICS_EXTRA_FLAGS
189 value: {{ default "" (join " " .Values.metrics.extraFlags) | quote }}
190 - name: MARIADB_ROOT_USER
191 value: {{ .Values.rootUser.user | quote }}
192 - name: MARIADB_ROOT_PASSWORD
193 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 14}}
194 command:
195 - sh
196 - -c
197 - |
198 DATA_SOURCE_NAME="$MARIADB_ROOT_USER:$MARIADB_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter $MARIADB_METRICS_EXTRA_FLAGS
199 ports:
200 - name: metrics
201 containerPort: 9104
vitalied1e5876c2018-03-29 10:24:27 -0500202 livenessProbe:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100203 httpGet:
204 path: /metrics
205 port: metrics
a.sreekumarcf3133d2021-09-10 14:41:30 +0100206 initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }}
207 periodSeconds: {{ .Values.metrics.livenessProbe.periodSeconds }}
208 timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }}
209 successThreshold: {{ .Values.metrics.livenessProbe.successThreshold }}
210 failureThreshold: {{ .Values.metrics.livenessProbe.failureThreshold }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100211 readinessProbe:
212 httpGet:
213 path: /metrics
214 port: metrics
a.sreekumarcf3133d2021-09-10 14:41:30 +0100215 initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }}
216 periodSeconds: {{ .Values.metrics.readinessProbe.periodSeconds }}
217 timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }}
218 successThreshold: {{ .Values.metrics.readinessProbe.successThreshold }}
219 failureThreshold: {{ .Values.metrics.readinessProbe.failureThreshold }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100220 {{ include "common.containerSecurityContext" . | indent 10 | trim }}
221 resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
222 {{- end }}
223 imagePullSecrets:
224 - name: {{ include "common.namespace" . }}-docker-registry-key
225 {{- if .Values.schedulerName }}
226 schedulerName: {{ .Values.schedulerName | quote }}
vitalied1e5876c2018-03-29 10:24:27 -0500227 {{- end }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100228 {{- if .Values.priorityClassName }}
229 priorityClassName: {{ .Values.priorityClassName }}
230 {{- end }}
231 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
232 {{- if .Values.affinity }}
Prabhjot Singh Sethie4629f32021-08-21 11:31:59 +0530233 affinity: {{- include "common.tplValue" ( dict "value" .Values.affinity "context" $) | nindent 8 }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100234 {{- else }}
235 affinity:
236 podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset "context" $) | nindent 10 }}
237 podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset "context" $) | nindent 10 }}
238 nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values) | nindent 10 }}
239 {{- end }}
240 {{- if .Values.nodeSelector }}
Prabhjot Singh Sethie4629f32021-08-21 11:31:59 +0530241 nodeSelector: {{- include "common.tplValue" ( dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100242 {{- end }}
243 {{- if .Values.tolerations }}
Prabhjot Singh Sethie4629f32021-08-21 11:31:59 +0530244 tolerations: {{- include "common.tplValue" (dict "value" .Values.tolerations "context" .) | nindent 8 }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100245 {{- end }}
246 volumes:
247 - name: previous-boot
248 emptyDir: {}
249 - name: mariadb-tmp-folder
250 emptyDir: {}
251 {{- if .Values.mariadbConfiguration }}
252 - name: mariadb-galera-actual-config
253 emptyDir: {}
254 - name: mariadb-galera-starting-config
255 configMap:
256 name: {{ printf "%s-configuration" (include "common.fullname" .) }}
257 {{- end }}
258{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
259 - name: {{ include "common.fullname" . }}
260 persistentVolumeClaim:
261 claimName: {{ .Values.persistence.existingClaim }}
262{{- else if not .Values.persistence.enabled }}
263 - name: {{ include "common.fullname" . }}
264 emptyDir: {}
265{{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
vitalied1e5876c2018-03-29 10:24:27 -0500266 volumeClaimTemplates:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100267 - {{ include "common.PVCTemplate" (dict "dot" . "suffix" "data" "persistenceInfos" .Values.persistence) | indent 6 | trim }}
BorislavGdf11cd52018-05-06 12:55:20 +0000268{{- end }}