Merge "Upgrade APPC to use common mariadb galera charts"
[oom.git] / kubernetes / common / mariadb-galera / templates / statefulset.yaml
1 # Copyright © 2018 Amdocs, Bell Canada
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       annotations:
33         pod.alpha.kubernetes.io/initialized: "true"
34     spec:
35     {{- if .Values.nodeSelector }}
36       nodeSelector:
37 {{ toYaml .Values.nodeSelector | indent 8 }}
38     {{- end }}
39       volumes:
40       {{- if .Values.externalConfig }}
41         - name: config
42           configMap:
43             name: {{ include "common.fullname" . }}-externalConfig
44       {{- end}}
45         - name: localtime
46           hostPath:
47             path: /etc/localtime
48       imagePullSecrets:
49       - name: {{ include "common.namespace" . }}-docker-registry-key
50       containers:
51         - name: {{ include "common.name" . }}
52           image: "{{ include "common.repository" . }}/{{ .Values.image }}"
53           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy | quote}}
54           env:
55             - name: POD_NAMESPACE
56               valueFrom:
57                 fieldRef:
58                   apiVersion: v1
59                   fieldPath: metadata.namespace
60             - name: MYSQL_USER
61               value: {{ default "" .Values.config.userName | quote }}
62             - name: MYSQL_PASSWORD
63               valueFrom:
64                 secretKeyRef:
65                   name: {{ template "common.fullname" . }}
66                   key: user-password
67             - name: MYSQL_DATABASE
68               value: {{ default "" .Values.config.mysqlDatabase | quote }}
69             - name: MYSQL_ROOT_PASSWORD
70               valueFrom:
71                 secretKeyRef:
72                   name: {{ template "common.fullname" . }}
73                   key: db-root-password
74           ports:
75           - containerPort: {{ .Values.service.internalPort }}
76             name: {{ .Values.service.name }}
77           - containerPort: {{ .Values.service.sstPort }}
78             name: {{ .Values.service.sstName }}
79           - containerPort: {{ .Values.service.replicationPort }}
80             name: {{ .Values.service.replicationName }}
81           - containerPort: {{ .Values.service.istPort }}
82             name: {{ .Values.service.istName }}
83           readinessProbe:
84             exec:
85               command:
86               - /usr/share/container-scripts/mysql/readiness-probe.sh
87             initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
88             periodSeconds: {{ .Values.readiness.periodSeconds }}
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 {{ toYaml .Values.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: mariadb-galera-prepare
112           image: "{{ include "common.repository" . }}/{{ .Values.imageInit }}"
113           command: ["sh", "-c", "chown -R 27:27 /var/lib/mysql"]
114           volumeMounts:
115             - name: {{ include "common.fullname" . }}-data
116               mountPath: /var/lib/mysql
117   volumeClaimTemplates:
118   - metadata:
119       name: {{ include "common.fullname" . }}-data
120       labels:
121         name: {{ include "common.fullname" . }}
122     spec:
123       accessModes:
124       - {{ .Values.persistence.accessMode | quote }}
125       storageClassName: {{ include "common.fullname" . }}-data
126       resources:
127         requests:
128           storage: {{ .Values.persistence.size | quote }}
129 {{- end }}