Merge "[POMBA] Use global storage templates for PVC"
[oom.git] / kubernetes / common / mariadb-galera / templates / statefulset.yaml
1 # Copyright © 2019 Amdocs, Bell Canada, Orange, Samsung Electronics
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 apiVersion: apps/v1beta1
16 kind: StatefulSet
17 metadata:
18   name: {{ include "common.fullname" . }}
19   namespace: {{ include "common.namespace" . }}
20   labels:
21     app: {{ include "common.fullname" . }}
22     chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
23     release: "{{ .Release.Name }}"
24     heritage: "{{ .Release.Service }}"
25 spec:
26   serviceName: {{ .Values.service.name }}
27   replicas: {{ .Values.replicaCount }}
28   template:
29     metadata:
30       labels:
31         app: {{ include "common.fullname" . }}
32         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
33         release: "{{ .Release.Name }}"
34         heritage: "{{ .Release.Service }}"
35       annotations:
36         pod.alpha.kubernetes.io/initialized: "true"
37     spec:
38     {{- if .Values.nodeSelector }}
39       nodeSelector:
40 {{ toYaml .Values.nodeSelector | indent 8 }}
41     {{- end }}
42       volumes:
43       {{- if .Values.externalConfig }}
44         - name: config
45           configMap:
46             name: {{ include "common.fullname" . }}-external-config
47       {{- end}}
48         - name: localtime
49           hostPath:
50             path: /etc/localtime
51       imagePullSecrets:
52       - name: {{ include "common.namespace" . }}-docker-registry-key
53       containers:
54         - name: {{ include "common.name" . }}
55           image: "{{ include "common.repository" . }}/{{ .Values.image }}"
56           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
57           env:
58             - name: POD_NAMESPACE
59               valueFrom:
60                 fieldRef:
61                   apiVersion: v1
62                   fieldPath: metadata.namespace
63             - name: MYSQL_USER
64               {{- include "common.secret.envFromSecret" (dict "global" . "uid" "db-user-credentials" "key" "login") | indent 14}}
65             - name: MYSQL_PASSWORD
66               {{- include "common.secret.envFromSecret" (dict "global" . "uid" "db-user-credentials" "key" "password") | indent 14}}
67             - name: MYSQL_DATABASE
68               value: {{ default "" .Values.config.mysqlDatabase | quote }}
69             - name: MYSQL_ROOT_PASSWORD
70               {{- include "common.secret.envFromSecret" (dict "global" . "uid" "db-root-password" "key" "password") | indent 14}}
71           ports:
72           - containerPort: {{ .Values.service.internalPort }}
73             name: {{ .Values.service.portName }}
74           - containerPort: {{ .Values.service.sstPort }}
75             name: {{ .Values.service.sstPortName }}
76           - containerPort: {{ .Values.service.replicationPort }}
77             name: {{ .Values.service.replicationName }}
78           - containerPort: {{ .Values.service.istPort }}
79             name: {{ .Values.service.istPortName }}
80           readinessProbe:
81             exec:
82               command:
83               - /usr/share/container-scripts/mysql/readiness-probe.sh
84             initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
85             periodSeconds: {{ .Values.readiness.periodSeconds }}
86             timeoutSeconds: {{ .Values.readiness.timeoutSeconds }}
87       {{- if eq .Values.liveness.enabled true }}
88           livenessProbe:
89             exec:
90               command: ["mysqladmin", "ping"]
91             initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
92             periodSeconds: {{ .Values.liveness.periodSeconds }}
93             timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
94       {{- end }}
95           resources:
96 {{ include "common.resources" . | indent 12 }}
97           volumeMounts:
98         {{- if .Values.externalConfig }}
99           - mountPath: /etc/config
100             name: config
101         {{- end}}
102           - mountPath: /etc/localtime
103             name: localtime
104             readOnly: true
105 {{- if .Values.persistence.enabled }}
106           - mountPath: /var/lib/mysql
107             name: {{ include "common.fullname" . }}-data
108       initContainers:
109         - name: {{ include "common.name" . }}-prepare
110           image: "{{ include "common.repository" . }}/{{ .Values.imageInit }}"
111           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
112           command: ["sh", "-c", "chown -R 27:27 /var/lib/mysql"]
113           volumeMounts:
114             - name: {{ include "common.fullname" . }}-data
115               mountPath: /var/lib/mysql
116   volumeClaimTemplates:
117   - metadata:
118       name: {{ include "common.fullname" . }}-data
119       labels:
120         name: {{ include "common.fullname" . }}
121         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
122         release: "{{ .Release.Name }}"
123         heritage: "{{ .Release.Service }}"
124     spec:
125       accessModes:
126       - {{ .Values.persistence.accessMode | quote }}
127       storageClassName: {{ include "common.storageClass" . }}
128       resources:
129         requests:
130           storage: {{ .Values.persistence.size | quote }}
131 {{- end }}