[COMMON] Optimize common secret template
[oom.git] / kubernetes / common / mariadb-galera / templates / statefulset.yaml
1 {{/*
2 # Copyright © 2019 Amdocs, Bell Canada, Orange, Samsung Electronics
3 #
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
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 */}}
16
17 apiVersion: apps/v1beta1
18 kind: StatefulSet
19 metadata:
20   name: {{ include "common.fullname" . }}
21   namespace: {{ include "common.namespace" . }}
22   labels:
23     app: {{ include "common.fullname" . }}
24     chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
25     release: "{{ include "common.release" . }}"
26     heritage: "{{ .Release.Service }}"
27 spec:
28   serviceName: {{ .Values.service.name }}
29   replicas: {{ .Values.replicaCount }}
30   template:
31     metadata:
32       labels:
33         app: {{ include "common.fullname" . }}
34         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
35         release: "{{ include "common.release" . }}"
36         heritage: "{{ .Release.Service }}"
37       annotations:
38         pod.alpha.kubernetes.io/initialized: "true"
39     spec:
40     {{- if .Values.nodeSelector }}
41       nodeSelector:
42 {{ toYaml .Values.nodeSelector | indent 8 }}
43     {{- end }}
44       volumes:
45       {{- if .Values.externalConfig }}
46         - name: config
47           configMap:
48             name: {{ include "common.fullname" . }}-external-config
49       {{- end}}
50         - name: localtime
51           hostPath:
52             path: /etc/localtime
53       imagePullSecrets:
54       - name: {{ include "common.namespace" . }}-docker-registry-key
55       containers:
56         - name: {{ include "common.name" . }}
57           image: "{{ include "common.repository" . }}/{{ .Values.image }}"
58           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
59           env:
60             - name: POD_NAMESPACE
61               valueFrom:
62                 fieldRef:
63                   apiVersion: v1
64                   fieldPath: metadata.namespace
65             - name: MYSQL_USER
66               {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "login") | indent 14}}
67             - name: MYSQL_PASSWORD
68               {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.userCredentialsUID" .) "key" "password") | indent 14}}
69             - name: MYSQL_DATABASE
70               value: {{ default "" .Values.config.mysqlDatabase | quote }}
71             - name: MYSQL_ROOT_PASSWORD
72               {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 14}}
73           ports:
74           - containerPort: {{ .Values.service.internalPort }}
75             name: {{ .Values.service.portName }}
76           - containerPort: {{ .Values.service.sstPort }}
77             name: {{ .Values.service.sstPortName }}
78           - containerPort: {{ .Values.service.replicationPort }}
79             name: {{ .Values.service.replicationName }}
80           - containerPort: {{ .Values.service.istPort }}
81             name: {{ .Values.service.istPortName }}
82           readinessProbe:
83             exec:
84               command:
85               - /usr/share/container-scripts/mysql/readiness-probe.sh
86             initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
87             periodSeconds: {{ .Values.readiness.periodSeconds }}
88             timeoutSeconds: {{ .Values.readiness.timeoutSeconds }}
89       {{- if eq .Values.liveness.enabled true }}
90           livenessProbe:
91             exec:
92               command: ["mysqladmin", "ping"]
93             initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
94             periodSeconds: {{ .Values.liveness.periodSeconds }}
95             timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
96       {{- end }}
97           resources:
98 {{ include "common.resources" . | indent 12 }}
99           volumeMounts:
100         {{- if .Values.externalConfig }}
101           - mountPath: /etc/config
102             name: config
103         {{- end}}
104           - mountPath: /etc/localtime
105             name: localtime
106             readOnly: true
107 {{- if .Values.persistence.enabled }}
108           - mountPath: /var/lib/mysql
109             name: {{ include "common.fullname" . }}-data
110       initContainers:
111         - name: {{ include "common.name" . }}-prepare
112           image: "{{ include "common.repository" . }}/{{ .Values.imageInit }}"
113           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
114           command: ["sh", "-c", "chown -R 27:27 /var/lib/mysql"]
115           volumeMounts:
116             - name: {{ include "common.fullname" . }}-data
117               mountPath: /var/lib/mysql
118   volumeClaimTemplates:
119   - metadata:
120       name: {{ include "common.fullname" . }}-data
121       labels:
122         name: {{ include "common.fullname" . }}
123         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
124         release: "{{ include "common.release" . }}"
125         heritage: "{{ .Release.Service }}"
126     spec:
127       accessModes:
128       - {{ .Values.persistence.accessMode | quote }}
129       storageClassName: {{ include "common.storageClass" . }}
130       resources:
131         requests:
132           storage: {{ .Values.persistence.size | quote }}
133 {{- end }}