1a18f4a3abd9d02c0ba8757483ba66d79d682bba
[osm/devops.git] / installers / helm / osm / templates / mysql / mysql-statefulset.yaml
1 {{- if .Values.mysql.enabled -}}
2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
18 apiVersion: apps/v1
19 kind: StatefulSet
20 metadata:
21   name: mysql
22   labels:
23     {{- include "osm.labels" . | nindent 4 }}
24 spec:
25   replicas: {{ .Values.mysql.replicaCount | default .Values.global.replicaCount }}
26   serviceName: mysql
27   selector:
28     matchLabels:
29       app.kubernetes.io/component: mysql
30       {{- include "osm.selectorLabels" . | nindent 6 }}
31   template:
32     metadata:
33       {{- with .Values.global.podAnnotations }}
34       annotations:
35         {{- toYaml . | nindent 8 }}
36       {{- end }}
37       labels:
38         app.kubernetes.io/component: mysql
39         {{- include "osm.selectorLabels" . | nindent 8 }}
40     spec:
41       {{- with .Values.global.imagePullSecrets }}
42       imagePullSecrets:
43         {{- toYaml . | nindent 8 }}
44       {{- end }}
45       serviceAccountName: {{ include "osm.serviceAccountName" . }}
46       containers:
47         - name: mysql
48           securityContext:
49             # readOnlyRootFilesystem: true
50             allowPrivilegeEscalation: false
51             # runAsNonRoot: true
52           image: mysql:8.0.34
53           imagePullPolicy: {{ .Values.global.image.pullPolicy }}
54           ports:
55             - containerPort: 3306
56               protocol: TCP
57               name: mysql
58           volumeMounts:
59             - name: mysql-db
60               mountPath: /var/lib/mysql
61           resources:
62             limits:
63               memory: 1024Mi
64             requests:
65               memory: 128Mi
66           envFrom:
67           {{- if not .Values.mysql.useOsmSecret }}
68             - secretRef:
69                 name: {{ .Values.mysql.secretName | default "ro-db-secret" }}
70           {{- else }}
71           env:
72             - name: MYSQL_ROOT_PASSWORD
73               valueFrom:
74                 secretKeyRef:
75                   name: {{ include "osm.fullname" . }}-secret
76                   key: OSM_MYSQL_ROOT_PASSWORD
77           {{- end }}
78       {{- with .Values.global.nodeSelector }}
79       nodeSelector:
80         {{- toYaml . | nindent 8 }}
81       {{- end }}
82       {{- with .Values.global.affinity }}
83       affinity:
84         {{- toYaml . | nindent 8 }}
85       {{- end }}
86       {{- with .Values.global.tolerations }}
87       tolerations:
88         {{- toYaml . | nindent 8 }}
89       {{- end }}
90       volumes:
91         - name: mysql-db
92           hostPath:
93             path: {{ .Values.mysql.dbHostPath | default "/var/lib/osm/{{ .Release.Namespace }}/osm_ro_db/_data" }}
94 {{- end }}