Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / elasticsearch / components / data / templates / statefulset.yaml
1 {{/*
2 # Copyright © 2020 Bitnami, AT&T, Amdocs, Bell Canada, highstreet technologies
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 apiVersion: apps/v1
17 kind: StatefulSet
18 {{ $role := "data" -}}
19 {{ $suffix := $role -}}
20 {{ $labels := (dict "role" $role "discovery" .Values.cluster_name) -}}
21 metadata: {{- include "common.resourceMetadata" (dict "suffix" $suffix "labels" $labels "dot" . )| nindent 2 }}
22 spec:
23   updateStrategy:
24     type: {{ .Values.updateStrategy.type }}
25     {{- if (eq "OnDelete" .Values.updateStrategy.type) }}
26     rollingUpdate: null
27     {{- else if .Values.updateStrategy.rollingUpdatePartition }}
28     rollingUpdate:
29       partition: {{ .Values.updateStrategy.rollingUpdatePartition }}
30     {{- end }}
31   selector: {{- include "common.selectors" (dict "matchLabels" $labels "dot" .) | nindent 4 }}
32   serviceName: {{ include "common.fullname" . }}-data
33   replicas: {{ .Values.replicaCount }}
34   template:
35     metadata: {{- include "common.templateMetadata" (dict "labels" $labels "dot" .) | nindent 6 }}
36     spec:
37       {{- include "common.imagePullSecrets" . | nindent 6 }}
38       {{- if .Values.affinity }}
39       affinity: {{- include "common.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
40       {{- end }}
41       {{- if .Values.nodeSelector }}
42       nodeSelector: {{- include "common.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
43       {{- end }}
44       {{- if .Values.tolerations }}
45       tolerations: {{- include "common.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
46       {{- end }}
47       {{- if .Values.securityContext.enabled }}
48       securityContext:
49         fsGroup: {{ .Values.securityContext.fsGroup }}
50       {{- end }}
51       {{- if or .Values.sysctlImage.enabled (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
52       initContainers:
53         {{- if .Values.sysctlImage.enabled }}
54         ## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
55         - name: sysctl
56           image: {{ include "repositoryGenerator.image.busybox" . }}
57           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
58           command:
59             - /bin/sh
60             - -c
61             - |
62               set -o errexit
63               set -o pipefail
64               set -o nounset
65               sysctl -w vm.max_map_count=262144 && sysctl -w fs.file-max=65536
66           securityContext:
67             privileged: true
68         {{- end }}
69         {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
70         - name: volume-permissions
71           image: {{ include "repositoryGenerator.image.busybox" . }}
72           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
73           command:
74             - /bin/sh
75             - -c
76             - |
77               chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} //bitnami/elasticsearch/data
78           securityContext:
79             runAsUser: 0
80           {{- if .Values.volumePermissions.resource }}
81           resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
82           {{- end }}
83           volumeMounts:
84             - name: data
85               mountPath: "/bitnami/elasticsearch/data"
86         {{- end }}
87       {{- end }}
88       containers:
89         - name: {{ include "common.name" . }}-data
90           image: {{ printf "%s/%s" (include "repositoryGenerator.dockerHubRepository" .)  .Values.image }}
91           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
92           {{- if .Values.securityContext.enabled }}
93           securityContext:
94             runAsUser: {{ .Values.securityContext.runAsUser }}
95           {{- end }}
96           env:
97             - name: BITNAMI_DEBUG
98               value: {{ ternary "true" "false" .Values.debug | quote }}
99             - name: ELASTICSEARCH_CLUSTER_NAME
100               value: {{ .Values.cluster_name }}
101             - name: ELASTICSEARCH_CLUSTER_HOSTS
102               value: {{ include "common.name" . }}-discovery
103             {{- if .Values.plugins }}
104             - name: ELASTICSEARCH_PLUGINS
105               value: {{ .Values.plugins | quote }}
106             {{- end }}
107             - name: ELASTICSEARCH_HEAP_SIZE
108               value: {{ .Values.heapSize | quote }}
109             - name: ELASTICSEARCH_IS_DEDICATED_NODE
110               value: "yes"
111             - name: ELASTICSEARCH_NODE_TYPE
112               value: "data"
113             - name: network.bind_host
114               value: 127.0.0.1
115             - name: network.publish_host
116               valueFrom:
117                 fieldRef:
118                   fieldPath: status.podIP
119           ports: {{- include "common.containerPorts" . |indent 12 }}
120           {{- if .Values.livenessProbe.enabled }}
121           livenessProbe:
122             initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
123             periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
124             timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
125             successThreshold: {{ .Values.livenessProbe.successThreshold }}
126             failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
127             httpGet:
128               path: /_cluster/health?local=true
129               port: 9200
130           {{- end }}
131           {{- if .Values.readinessProbe.enabled }}
132           readinessProbe:
133             initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
134             periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
135             timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
136             successThreshold: {{ .Values.livenessProbe.successThreshold }}
137             failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
138             httpGet:
139               path: /_cluster/health?local=true
140               port: 9200
141           {{- end }}
142           {{- if .Values.resources }}
143           resources: {{- toYaml .Values.resources | nindent 12 }}
144           {{- end }}
145           volumeMounts:
146             {{- if .Values.config }}
147             - mountPath: /opt/bitnami/elasticsearch/config/elasticsearch.yml
148               name: "config"
149               subPath: elasticsearch.yml
150             {{- end }}
151             - name: "data"
152               mountPath: "/bitnami/elasticsearch/data"
153             {{- if .Values.extraVolumeMounts }}
154             {{- toYaml .Values.extraVolumeMounts | nindent 12 }}
155             {{- end }}
156       volumes:
157         {{- if .Values.config }}
158         - name: "config"
159           configMap:
160             name: {{ template "common.fullname" . }}
161         {{- end }}
162         {{- if .Values.extraVolumes }}
163         {{- toYaml .Values.extraVolumes | nindent 8 }}
164         {{- end }}
165 {{- if not .Values.persistence.enabled }}
166         - name: "data"
167           emptyDir: {}
168 {{- else }}
169   volumeClaimTemplates:
170     - metadata:
171         name: "data"
172         {{- if .Values.persistence.annotations }}
173         annotations: {{- toYaml .Values.persistence.annotations | nindent 10 }}
174         {{- end }}
175       spec:
176         accessModes:
177           - {{ .Values.persistence.accessMode }}
178         storageClassName: {{ include "common.storageClass" (dict "dot" . "suffix" .Values.persistence.suffix) }}
179         resources:
180           requests:
181             storage: {{ .Values.persistence.size | quote }}
182 {{- end }}