blob: bde971ffe700fd1b88ca4c5f1033fe6520811db4 [file] [log] [blame]
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +01001{{/*
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +01002# Copyright © 2018 Amdocs, Bell Canada
3# Copyright © 2019 Samsung Electronics
4# Copyright © 2019-2020 Orange
5# Copyright © 2020 Bitnami
vaibhavjayasea9aee02018-08-31 06:22:26 +00006#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010018*/}}
vaibhavjayasea9aee02018-08-31 06:22:26 +000019
milaszki804afe72020-07-07 12:23:07 +000020apiVersion: apps/v1
vitalied1e5876c2018-03-29 10:24:27 -050021kind: StatefulSet
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010022metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
vitalied1e5876c2018-03-29 10:24:27 -050023spec:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010024 podManagementPolicy: {{ .Values.podManagementPolicy }}
vitalied1e5876c2018-03-29 10:24:27 -050025 replicas: {{ .Values.replicaCount }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010026 selector: {{- include "common.selectors" . | nindent 4 }}
27 serviceName: {{ include "common.servicename" . }}-headless
28 updateStrategy:
29 type: {{ .Values.updateStrategy.type }}
30 {{- if (eq "Recreate" .Values.updateStrategy.type) }}
31 rollingUpdate: null
vitalied1e5876c2018-03-29 10:24:27 -050032 {{- end }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010033 template:
34 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
35 spec:
36 {{ include "common.podSecurityContext" . | indent 6 | trim }}
37 initContainers:
38 # we shouldn't need this but for unknown reason, it's fsGroup is not
39 # applied
40 - name: fix-permission
41 command:
42 - /bin/sh
43 args:
44 - -c
45 - |
46 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /data
47 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /bootstrap/
48 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /tmp/
49 {{- if .Values.mariadbConfiguration }}
50 cp /config/my.cnf /actual/my.cnf
51 chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /actual
52 {{- end }}
53 image: {{ include "repositoryGenerator.image.busybox" . }}
54 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
55 securityContext:
56 runAsUser: 0
57 volumeMounts:
58 - name: previous-boot
59 mountPath: /bootstrap
60 - name: mariadb-tmp-folder
61 mountPath: /tmp
62 - name: {{ include "common.fullname" . }}
63 mountPath: /data
64 {{- if .Values.mariadbConfiguration }}
65 - name: mariadb-galera-starting-config
66 mountPath: /config/my.cnf
67 subPath: my.cnf
68 - name: mariadb-galera-actual-config
69 mountPath: /actual
70 {{- end }}
vitalied1e5876c2018-03-29 10:24:27 -050071 containers:
pramod47b1b822018-08-28 15:41:45 +000072 - name: {{ include "common.name" . }}
Sylvain Desbureaux41066142020-11-19 17:12:46 +010073 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
vitalied1e5876c2018-03-29 10:24:27 -050074 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010075 command:
76 - bash
77 - -ec
78 - |
79 {{- if (not (empty (.Values.galera.bootstrap.bootstrapFromNode | quote)))}}
80 {{- $fullname := include "common.names.fullname" . }}
81 {{- $bootstrapFromNode := int .Values.galera.bootstrap.bootstrapFromNode }}
82 # Bootstrap from the indicated node
83 NODE_ID="${MY_POD_NAME#"{{ $fullname }}-"}"
84 if [[ "$NODE_ID" -eq "{{ $bootstrapFromNode }}" ]]; then
85 export MARIADB_GALERA_CLUSTER_BOOTSTRAP=yes
86 export MARIADB_GALERA_FORCE_SAFETOBOOTSTRAP={{ ternary "yes" "no" .Values.galera.bootstrap.forceSafeToBootstrap }}
87 fi
88 {{- end }}
89 exec /opt/bitnami/scripts/mariadb-galera/entrypoint.sh /opt/bitnami/scripts/mariadb-galera/run.sh
vitalied1e5876c2018-03-29 10:24:27 -050090 env:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010091 - name: MY_POD_NAME
vitalied1e5876c2018-03-29 10:24:27 -050092 valueFrom:
93 fieldRef:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010094 fieldPath: metadata.name
95 - name: BITNAMI_DEBUG
96 value: {{ ternary "true" "false" .Values.debug | quote }}
Sylvain Desbureauxdb1a6722021-01-04 14:45:11 +010097 - name: MARIADB_INIT_SLEEP_TIME
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +010098 value: {{ .Values.init_sleep_time | quote }}
99 - name: MARIADB_GALERA_CLUSTER_NAME
100 value: {{ .Values.galera.name | quote }}
101 - name: MARIADB_GALERA_CLUSTER_ADDRESS
102 value: "gcomm://{{ template "common.name" . }}-headless.{{ include "common.namespace" . }}.svc.{{ .Values.global.clusterDomain }}"
Sylvain Desbureauxcded1102021-01-18 14:53:55 +0100103 # Bitnami init script don't behave well in dual stack env.
104 # set it here as long as https://github.com/bitnami/charts/issues/4077 is not solved.
105 - name: MARIADB_GALERA_NODE_ADDRESS
106 valueFrom:
107 fieldRef:
108 fieldPath: status.podIP
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100109 - name: MARIADB_ROOT_USER
110 value: {{ .Values.rootUser.user | quote }}
111 - name: MARIADB_ROOT_PASSWORD
112 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 14 }}
113 - name: MARIADB_USER
114 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "login") | indent 14 }}
115 - name: MARIADB_PASSWORD
116 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "password") | indent 14 }}
117 - name: MARIADB_DATABASE
118 value: {{ .Values.db.name | quote }}
119 - name: MARIADB_GALERA_MARIABACKUP_USER
120 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.backupCredentialsUID" .) "key" "login") | indent 14 }}
121 - name: MARIADB_GALERA_MARIABACKUP_PASSWORD
122 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.backupCredentialsUID" .) "key" "password") | indent 14 }}
123 {{- if .Values.extraFlags }}
124 - name: MARIADB_EXTRA_FLAGS
125 value: {{ .Values.extraFlags | quote }}
126 {{- end }}
127 ports: {{ include "common.containerPorts" . | nindent 12 }}
128 {{- if .Values.livenessProbe.enabled }}
129 livenessProbe:
130 exec:
131 command:
132 - bash
133 - -ec
134 - |
135 exec mysqladmin status -u$MARIADB_ROOT_USER -p$MARIADB_ROOT_PASSWORD
136 initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
137 periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
138 timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
139 successThreshold: {{ .Values.livenessProbe.successThreshold }}
140 failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
141 {{- end }}
142 {{- if .Values.readinessProbe.enabled }}
vitalied1e5876c2018-03-29 10:24:27 -0500143 readinessProbe:
144 exec:
145 command:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100146 - bash
147 - -ec
148 - |
149 exec mysqladmin status -u$MARIADB_ROOT_USER -p$MARIADB_ROOT_PASSWORD
150 initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
151 periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
152 timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
153 successThreshold: {{ .Values.readinessProbe.successThreshold }}
154 failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
155 {{- end }}
156 resources: {{ include "common.resources" . | nindent 12 }}
157 volumeMounts:
158 - name: previous-boot
159 mountPath: /opt/bitnami/mariadb/.bootstrap
160 - name: {{ include "common.fullname" . }}
161 mountPath: /bitnami/mariadb
162 - name: mariadb-tmp-folder
163 mountPath: /opt/bitnami/mariadb/tmp
164 {{- if .Values.mariadbConfiguration }}
165 - name: mariadb-galera-actual-config
166 mountPath: /opt/bitnami/mariadb/conf
167 {{- end }}
168 {{- if default false .Values.global.metrics.enabled }}
169 - name: {{ include "common.name" . }}-metrics
170 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.metrics.image }}
171 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.metrics.pullPolicy | quote}}
172 env:
173 - name: MARIADB_METRICS_EXTRA_FLAGS
174 value: {{ default "" (join " " .Values.metrics.extraFlags) | quote }}
175 - name: MARIADB_ROOT_USER
176 value: {{ .Values.rootUser.user | quote }}
177 - name: MARIADB_ROOT_PASSWORD
178 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 14}}
179 command:
180 - sh
181 - -c
182 - |
183 DATA_SOURCE_NAME="$MARIADB_ROOT_USER:$MARIADB_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter $MARIADB_METRICS_EXTRA_FLAGS
184 ports:
185 - name: metrics
186 containerPort: 9104
vitalied1e5876c2018-03-29 10:24:27 -0500187 livenessProbe:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100188 httpGet:
189 path: /metrics
190 port: metrics
191 initialDelaySeconds: 30
192 timeoutSeconds: 5
193 readinessProbe:
194 httpGet:
195 path: /metrics
196 port: metrics
197 initialDelaySeconds: 5
198 timeoutSeconds: 1
199 {{ include "common.containerSecurityContext" . | indent 10 | trim }}
200 resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
201 {{- end }}
202 imagePullSecrets:
203 - name: {{ include "common.namespace" . }}-docker-registry-key
204 {{- if .Values.schedulerName }}
205 schedulerName: {{ .Values.schedulerName | quote }}
vitalied1e5876c2018-03-29 10:24:27 -0500206 {{- end }}
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100207 {{- if .Values.priorityClassName }}
208 priorityClassName: {{ .Values.priorityClassName }}
209 {{- end }}
210 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
211 {{- if .Values.affinity }}
212 affinity: {{- include "common.tplvalues" ( dict "value" .Values.affinity "context" $) | nindent 8 }}
213 {{- else }}
214 affinity:
215 podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset "context" $) | nindent 10 }}
216 podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset "context" $) | nindent 10 }}
217 nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values) | nindent 10 }}
218 {{- end }}
219 {{- if .Values.nodeSelector }}
220 nodeSelector: {{- include "common.tplvalues" ( dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
221 {{- end }}
222 {{- if .Values.tolerations }}
223 tolerations: {{- include "common.tplvalues" (dict "value" .Values.tolerations "context" .) | nindent 8 }}
224 {{- end }}
225 volumes:
226 - name: previous-boot
227 emptyDir: {}
228 - name: mariadb-tmp-folder
229 emptyDir: {}
230 {{- if .Values.mariadbConfiguration }}
231 - name: mariadb-galera-actual-config
232 emptyDir: {}
233 - name: mariadb-galera-starting-config
234 configMap:
235 name: {{ printf "%s-configuration" (include "common.fullname" .) }}
236 {{- end }}
237{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
238 - name: {{ include "common.fullname" . }}
239 persistentVolumeClaim:
240 claimName: {{ .Values.persistence.existingClaim }}
241{{- else if not .Values.persistence.enabled }}
242 - name: {{ include "common.fullname" . }}
243 emptyDir: {}
244{{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
vitalied1e5876c2018-03-29 10:24:27 -0500245 volumeClaimTemplates:
Sylvain Desbureaux93a5b492020-11-27 11:07:42 +0100246 - {{ include "common.PVCTemplate" (dict "dot" . "suffix" "data" "persistenceInfos" .Values.persistence) | indent 6 | trim }}
BorislavGdf11cd52018-05-06 12:55:20 +0000247{{- end }}