updating helm/docker files and database config files
[it/otf.git] / otf-helm / otf / charts / databases / mongodb / templates / statefulset-primary-rs.yaml
1 {{- if .Values.replicaSet.enabled }}
2 apiVersion: apps/v1
3 kind: StatefulSet
4 metadata:
5   name: {{ template "mongodb.fullname" . }}-primary
6   namespace: {{.Values.namespace }}
7   labels:
8     app: {{ template "mongodb.name" . }}
9     chart: {{ template "mongodb.chart" . }}
10     heritage: {{ .Release.Service }}
11     release: {{ .Release.Name }}
12     {{- with .Values.labels }}
13 {{ toYaml . | indent 4 }}
14     {{- end }}
15   {{- with .Values.annotations }}
16   annotations:
17 {{ toYaml . | indent 4 }}
18   {{- end }}
19 spec:
20   serviceName: {{ template "mongodb.fullname" . }}-headless
21   replicas: 1
22   updateStrategy:
23     type: {{ .Values.updateStrategy.type }}
24     {{- if (eq "Recreate" .Values.updateStrategy.type) }}
25     rollingUpdate: null
26     {{- end }}
27   selector:
28     matchLabels:
29       app: {{ template "mongodb.name" . }}
30       release: {{ .Release.Name }}
31       component: primary
32   template:
33     metadata:
34       labels:
35         app: {{ template "mongodb.name" . }}
36         chart: {{ template "mongodb.chart" . }}
37         release: {{ .Release.Name }}
38         component: primary
39       {{- if .Values.podLabels }}
40 {{ toYaml .Values.podLabels | indent 8 }}
41       {{- end }}
42       {{- if or .Values.podAnnotations .Values.metrics.enabled }}
43       annotations:
44 {{- if .Values.podAnnotations }}
45 {{ toYaml .Values.podAnnotations | indent 8 }}
46 {{- end }}
47 {{- if .Values.metrics.enabled }}
48 {{ toYaml .Values.metrics.podAnnotations | indent 8 }}
49 {{- end }}
50       {{- end }}
51     spec:
52       {{- if .Values.schedulerName }}
53       schedulerName: "{{ .Values.schedulerName }}"
54       {{- end }}
55       {{- if .Values.priorityClassName }}
56       priorityClassName: {{ .Values.priorityClassName }}
57       {{- end }}
58       {{- if .Values.securityContext.enabled }}
59       securityContext:
60         fsGroup: {{ .Values.securityContext.fsGroup }}
61       {{- end }}
62       {{- if .Values.affinity }}
63       affinity:
64 {{ toYaml .Values.affinity | indent 8 }}
65       {{- end -}}
66       {{- if .Values.nodeSelector }}
67       nodeSelector:
68 {{ toYaml .Values.nodeSelector | indent 8 }}
69       {{- end }}
70       {{- if .Values.tolerations }}
71       tolerations:
72 {{ toYaml .Values.tolerations | indent 8 }}
73       {{- end }}
74 {{- include "mongodb.imagePullSecrets" . | indent 6 }}
75       initContainers:
76       {{- if .Values.extraInitContainers }}
77 {{ tpl .Values.extraInitContainers . | indent 6}}
78       {{- end }}
79       {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
80       - name: volume-permissions
81         image: {{ template "mongodb.volumePermissions.image" . }}
82         imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
83         command: ["chown", "-R", "{{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }}", "{{ .Values.persistence.mountPath }}"]
84         securityContext:
85           runAsUser: 0
86         resources: {{ toYaml .Values.volumePermissions.resources | nindent 10 }}
87         volumeMounts:
88         - name: datadir
89           mountPath: {{ .Values.persistence.mountPath }}
90       {{- end }}
91       containers:
92         - name: {{ template "mongodb.name" . }}-primary
93           image: {{ template "mongodb.image" . }}
94           imagePullPolicy: {{ .Values.image.pullPolicy }}
95           {{- if .Values.securityContext.enabled }}
96           securityContext:
97             runAsNonRoot: true
98             runAsUser: {{ .Values.securityContext.runAsUser }}
99           {{- end }}
100           ports:
101           - containerPort: {{ .Values.service.port }}
102             name: mongodb
103           env:
104           {{- if .Values.image.debug}}
105           - name: BITNAMI_DEBUG
106             value: "true"
107           {{- end }}
108           - name: MONGODB_SYSTEM_LOG_VERBOSITY
109             value: {{ .Values.mongodbSystemLogVerbosity | quote }}
110           - name: MONGODB_DISABLE_SYSTEM_LOG
111             {{- if .Values.mongodbDisableSystemLog }}
112             value: "yes"
113             {{- else }}
114             value: "no"
115             {{- end }}
116           - name: MONGODB_POD_NAME
117             valueFrom:
118               fieldRef:
119                 fieldPath: metadata.name
120           - name: MONGODB_REPLICA_SET_MODE
121             value: "primary"
122           - name: MONGODB_REPLICA_SET_NAME
123             value: {{ .Values.replicaSet.name | quote }}
124             {{- if .Values.replicaSet.useHostnames }}
125           - name: MONGODB_ADVERTISED_HOSTNAME
126             value: "$(MONGODB_POD_NAME).{{ template "mongodb.fullname" . }}-headless.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}"
127             {{- end }}
128           {{- if .Values.mongodbUsername }}
129           - name: MONGODB_USERNAME
130             value: {{ .Values.mongodbUsername | quote }}
131           {{- end }}
132           {{- if .Values.mongodbDatabase }}
133           - name: MONGODB_DATABASE
134             value: {{ .Values.mongodbDatabase | quote }}
135           {{- end }}
136             {{- if .Values.usePassword }}
137             {{- if and .Values.mongodbUsername .Values.mongodbDatabase }}
138           - name: MONGODB_PASSWORD
139             valueFrom:
140               secretKeyRef:
141                 name: {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{- else }}{{ template "mongodb.fullname" . }}{{- end }}
142                 key: mongodb-password
143             {{- end }}
144           - name: MONGODB_ROOT_PASSWORD
145             valueFrom:
146               secretKeyRef:
147                 name: {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{- else }}{{ template "mongodb.fullname" . }}{{- end }}
148                 key: mongodb-root-password
149           - name: MONGODB_REPLICA_SET_KEY
150             valueFrom:
151               secretKeyRef:
152                 name: {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{- else }}{{ template "mongodb.fullname" . }}{{- end }}
153                 key: mongodb-replica-set-key
154             {{- end }}
155           - name: MONGODB_ENABLE_IPV6
156           {{- if .Values.mongodbEnableIPv6 }}
157             value: "yes"
158           {{- else }}
159             value: "no"
160           {{- end }}
161           - name: MONGODB_ENABLE_DIRECTORY_PER_DB
162           {{- if .Values.mongodbDirectoryPerDB }}
163             value: "yes"
164           {{- else }}
165             value: "no"
166           {{- end }}
167           {{- if .Values.mongodbExtraFlags }}
168           - name: MONGODB_EXTRA_FLAGS
169             value: {{ .Values.mongodbExtraFlags | join " " | quote }}
170           {{- end }}
171           {{- if .Values.extraEnvVars }}
172           {{- include "mongodb.tplValue" ( dict "value" .Values.extraEnvVars "context" $ ) | nindent 10 }}
173           {{- end }}
174           {{- if .Values.livenessProbe.enabled }}
175           livenessProbe:
176             exec:
177               command:
178                 - pgrep
179                 - mongod
180             initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
181             periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
182             timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
183             successThreshold: {{ .Values.livenessProbe.successThreshold }}
184             failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
185           {{- end }}
186           {{- if .Values.readinessProbe.enabled }}
187           readinessProbe:
188             exec:
189               command:
190                 - mongo
191                 - --eval
192                 - "db.adminCommand('ping')"
193             initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
194             periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
195             timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
196             successThreshold: {{ .Values.readinessProbe.successThreshold }}
197             failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
198           {{- end }}
199           volumeMounts:
200             - name: datadir
201               mountPath: {{ .Values.persistence.mountPath }}
202               subPath: {{ .Values.persistence.subPath }}
203             {{- if  or (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js|json]") (.Values.initConfigMap) }}
204             - name: custom-init-scripts
205               mountPath: /docker-entrypoint-initdb.d
206             {{- end }}
207             {{- if .Values.configmap }}
208             - name: config
209               mountPath: /opt/bitnami/mongodb/conf/mongodb.conf
210               subPath: mongodb.conf
211             {{- end }}
212           {{- if .Values.extraVolumeMounts }}
213 {{ toYaml .Values.extraVolumeMounts | indent 12}}
214           {{- end }}
215           resources:
216 {{ toYaml .Values.resources | indent 12 }}
217 {{- if .Values.metrics.enabled }}
218         - name: metrics
219           image: {{ template "mongodb.metrics.image" . }}
220           imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
221           {{- if .Values.securityContext.enabled }}
222           securityContext:
223             runAsNonRoot: true
224             runAsUser: {{ .Values.securityContext.runAsUser }}
225           {{- end }}
226           env:
227           {{- if .Values.usePassword }}
228           - name: MONGODB_ROOT_PASSWORD
229             valueFrom:
230               secretKeyRef:
231                 name: {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{- else }}{{ template "mongodb.fullname" . }}{{- end }}
232                 key: mongodb-root-password
233           command: [ 'sh', '-c', '/bin/mongodb_exporter --mongodb.uri mongodb://root:${MONGODB_ROOT_PASSWORD}@localhost:{{ .Values.service.port }}/admin {{ .Values.metrics.extraArgs }}' ]
234           {{- else }}
235           command: [ 'sh', '-c', '/bin/mongodb_exporter --mongodb.uri mongodb://localhost:{{ .Values.service.port }} {{ .Values.metrics.extraArgs }}' ]
236           {{- end }}
237           ports:
238           - name: metrics
239             containerPort: 9216
240           {{- if .Values.metrics.livenessProbe.enabled }}
241           livenessProbe:
242             httpGet:
243               path: /metrics
244               port: metrics
245             initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }}
246             periodSeconds: {{ .Values.metrics.livenessProbe.periodSeconds }}
247             timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }}
248             failureThreshold: {{ .Values.metrics.livenessProbe.failureThreshold }}
249             successThreshold: {{ .Values.metrics.livenessProbe.successThreshold }}
250           {{- end }}
251           {{- if .Values.metrics.readinessProbe.enabled }}
252           readinessProbe:
253             httpGet:
254               path: /metrics
255               port: metrics
256             initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }}
257             periodSeconds: {{ .Values.metrics.readinessProbe.periodSeconds }}
258             timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }}
259             failureThreshold: {{ .Values.metrics.readinessProbe.failureThreshold }}
260             successThreshold: {{ .Values.metrics.readinessProbe.successThreshold }}
261           {{- end }}
262           resources:
263 {{ toYaml .Values.metrics.resources | indent 12 }}
264 {{- end }}
265 {{- if .Values.sidecars }}
266 {{ toYaml .Values.sidecars | indent 8 }}
267 {{- end }}
268       volumes:
269         {{- if (.Files.Glob "files/docker-entrypoint-initdb.d/*[sh|js|json]") }}
270         - name: custom-init-scripts
271           configMap:
272             name: {{ template "mongodb.fullname" . }}-init-scripts
273         {{- end }}
274         {{- if (.Values.initConfigMap) }}
275         - name: custom-init-scripts
276           configMap:
277             name: {{ .Values.initConfigMap.name }}
278         {{- end }}
279         {{- if .Values.configmap }}
280         - name: config
281           configMap:
282             name: {{ template "mongodb.fullname" . }}
283         {{- end }}
284         {{- if .Values.extraVolumes }}
285 {{ toYaml .Values.extraVolumes | indent 8}}
286         {{- end }}
287 {{- if .Values.persistence.enabled }}
288   volumeClaimTemplates:
289     - metadata:
290         name: datadir
291         annotations:
292         {{- range $key, $value := .Values.persistence.annotations }}
293           {{ $key }}: "{{ $value }}"
294         {{- end }}
295       spec:
296         accessModes:
297         {{- range .Values.persistence.accessModes }}
298           - {{ . | quote }}
299         {{- end }}
300         resources:
301           requests:
302             storage: {{ .Values.persistence.size | quote }}
303         {{ include "mongodb.storageClass" . }}
304 {{- else }}
305         - name: datadir
306           emptyDir: {}
307 {{- end }}
308 {{- end }}