[COMMON] Harmonize resource settings
[oom.git] / kubernetes / common / mongo / templates / statefulset.yaml
1 {{/*
2 # Copyright © 2018 Orange
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/v1
18 kind: StatefulSet
19 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
20 spec:
21   selector: {{- include "common.selectors" . | nindent 4 }}
22   serviceName: {{ include "common.servicename" . }}
23   replicas: {{ .Values.replicaCount }}
24   template:
25     metadata: {{- include "common.templateMetadata" . | nindent 6 }}
26     spec:
27 {{ include "common.podSecurityContext" . | indent 6 }}
28       imagePullSecrets:
29       - name: "{{ include "common.namespace" . }}-docker-registry-key"
30       initContainers:
31         # we shouldn't need this but for unknown reason, it's fsGroup is not
32         # applied
33         - name: fix-permission
34           command:
35             - /bin/sh
36           args:
37             - -c
38             - |
39               chown -R {{ .Values.securityContext.user_id }}:{{ .Values.securityContext.group_id }} /data
40           image: {{ include "repositoryGenerator.image.busybox" . }}
41           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
42           securityContext:
43             runAsUser: 0
44           volumeMounts:
45             - name: {{ include "common.fullname" . }}-data
46               mountPath: /data
47       containers:
48         - name: {{ include "common.name" . }}
49           image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
50           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
51           command:
52           - docker-entrypoint.sh
53           args:
54           - --nounixsocket
55           env:
56             - name: MONGO_INITDB_DATABASE
57               value: "{{ .Values.config.dbName }}"
58           ports:
59           - containerPort: {{ .Values.service.internalPort }}
60             name: {{ .Values.service.portName }}
61           # disable liveness probe when breakpoints set in debugger
62           # so K8s doesn't restart unresponsive container
63           {{- if eq .Values.liveness.enabled true }}
64           livenessProbe:
65             exec:
66               command:
67                 - mongo
68                 - --eval
69                 - "db.adminCommand('ping')"
70             initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
71             periodSeconds: {{ .Values.liveness.periodSeconds }}
72             timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
73           {{end -}}
74           readinessProbe:
75             tcpSocket:
76               port: {{ .Values.service.internalPort }}
77             initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
78             periodSeconds: {{ .Values.readiness.periodSeconds }}
79           volumeMounts:
80           - name: {{ include "common.fullname" . }}-data
81             mountPath: /data/db
82           resources: {{ include "common.resources" . | nindent 12 }}
83 {{ include "common.containerSecurityContext" . | indent 10 }}
84         {{- if .Values.nodeSelector }}
85         nodeSelector:
86 {{ toYaml .Values.nodeSelector | indent 10 }}
87         {{- end -}}
88         {{- if .Values.affinity }}
89         affinity:
90 {{ toYaml .Values.affinity | indent 10 }}
91         {{- end }}
92       volumes:
93       - name: localtime
94         hostPath:
95           path: /etc/localtime
96   {{- if .Values.persistence.enabled }}
97   volumeClaimTemplates:
98   - metadata:
99       name: {{ include "common.fullname" . }}-data
100       labels:
101         name: {{ include "common.fullname" . }}
102         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
103         release: "{{ include "common.release" . }}"
104         heritage: "{{ .Release.Service }}"
105     spec:
106       accessModes:
107       - {{ .Values.persistence.accessMode | quote }}
108       storageClassName: {{ include "common.storageClass" . }}
109       resources:
110         requests:
111           storage: {{ .Values.persistence.size | quote }}
112   {{- else }}
113       volumes:
114       - name: {{ include "common.fullname" . }}-data
115         emptyDir: {}
116   {{- end }}