8b33f611b91f90032e2d773af8e3de8ac98fd999
[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/v1beta1
18 kind: StatefulSet
19 metadata:
20   name: {{ include "common.fullname" . }}
21   namespace: {{ include "common.namespace" . }}
22   labels:
23     app: {{ include "common.name" . }}
24     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25     release: {{ .Release.Name }}
26     heritage: {{ .Release.Service }}
27 spec:
28   serviceName: {{ .Values.service.name }}
29   replicas: {{ .Values.replicaCount }}
30   template:
31     metadata:
32       labels:
33         app: {{ include "common.name" . }}
34         release: {{ .Release.Name }}
35     spec:
36       initContainers:
37 #{{ if not .Values.disableNfsProvisioner }}
38       - name: {{ include "common.name" . }}-readiness
39         command:
40         - /root/ready.py
41         args:
42         - --container-name
43         - {{ .Values.nfsprovisionerPrefix }}-nfs-provisioner
44         env:
45         - name: NAMESPACE
46           valueFrom:
47             fieldRef:
48               apiVersion: v1
49               fieldPath: metadata.namespace
50         image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
51         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
52 #{{ end }}
53
54       containers:
55         - name: {{ include "common.name" . }}
56           image: "{{ .Values.dockerHubRepository }}/{{ .Values.image }}"
57           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
58           env:
59             - name: MONGO_INITDB_DATABASE
60               value: "{{ .Values.config.dbName }}"
61           ports:
62           - containerPort: {{ .Values.service.internalPort }}
63           # disable liveness probe when breakpoints set in debugger
64           # so K8s doesn't restart unresponsive container
65           {{- if eq .Values.liveness.enabled true }}
66           livenessProbe:
67             exec:
68               command:
69                 - mongo
70                 - --eval
71                 - "db.adminCommand('ping')"
72             initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
73             periodSeconds: {{ .Values.liveness.periodSeconds }}
74             timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
75           {{end -}}
76           readinessProbe:
77             tcpSocket:
78               port: {{ .Values.service.internalPort }}
79             initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
80             periodSeconds: {{ .Values.readiness.periodSeconds }}
81           volumeMounts:
82           - mountPath: /var/lib/mongo
83             name: {{ include "common.fullname" . }}-data
84           resources:
85 {{ toYaml .Values.resources | indent 12 }}
86         {{- if .Values.nodeSelector }}
87         nodeSelector:
88 {{ toYaml .Values.nodeSelector | indent 10 }}
89         {{- end -}}
90         {{- if .Values.affinity }}
91         affinity:
92 {{ toYaml .Values.affinity | indent 10 }}
93         {{- end }}
94       volumes:
95       - name: localtime
96         hostPath:
97           path: /etc/localtime
98       - name: {{ include "common.fullname" . }}-data
99 #{{ if .Values.persistence.enabled }}
100         persistentVolumeClaim:
101           claimName: {{ include "common.fullname" . }}-data
102 #{{ else }}
103         emptyDir: {}
104 #{{ end }}