Merge "[OOM] Update Cassandra in common with service account"
[oom.git] / kubernetes / common / cassandra / templates / statefulset.yaml
1 {{/*
2 # Copyright © 2018 Amdocs, AT&T, Bell Canada
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   podManagementPolicy: {{ .Values.podManagementPolicy }}
25   updateStrategy:
26     type: {{ .Values.updateStrategy.type }}
27   template:
28     metadata: {{- include "common.templateMetadata" . | nindent 6 }}
29     spec:
30       hostNetwork: {{ .Values.hostNetwork }}
31       containers:
32       - name: {{ include "common.name" . }}
33         image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
34         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
35         ports: {{ include "common.containerPorts" . | nindent 8  }}
36         volumeMounts:
37           - name: {{ include "common.fullname" . }}-data
38             mountPath: /var/lib/cassandra
39           - name: localtime
40             mountPath: /etc/localtime
41             readOnly: true
42           - name: cassandra-entrypoint
43             mountPath: /docker-entrypoint.sh
44             subPath: docker-entrypoint.sh
45           {{- range $key, $value := .Values.configOverrides }}
46           - name: cassandra-config-{{ $key | replace "." "-" }}
47             mountPath: /etc/cassandra/{{ $key }}
48             subPath: {{ $key }}
49           {{- end }}
50         {{- if eq .Values.liveness.enabled true }}
51         livenessProbe:
52           exec:
53             command:
54             - /bin/bash
55             - -c
56             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
57           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
58           periodSeconds: {{ .Values.liveness.periodSeconds }}
59           timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
60           successThreshold: {{ .Values.liveness.successThreshold }}
61           failureThreshold: {{ .Values.liveness.failureThreshold }}
62         {{ end }}
63         readinessProbe:
64           exec:
65             command:
66             - /bin/bash
67             - -c
68             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
69           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
70           periodSeconds: {{ .Values.readiness.periodSeconds }}
71           timeoutSeconds: {{ .Values.readiness.timeoutSeconds }}
72           successThreshold: {{ .Values.readiness.successThreshold }}
73           failureThreshold: {{ .Values.readiness.failureThreshold }}
74         startupProbe:
75           exec:
76             command:
77             - /bin/bash
78             - -c
79             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
80           initialDelaySeconds: {{ .Values.startup.initialDelaySeconds }}
81           periodSeconds: {{ .Values.startup.periodSeconds }}
82           timeoutSeconds: {{ .Values.startup.timeoutSeconds }}
83           successThreshold: {{ .Values.startup.successThreshold }}
84           failureThreshold: {{ .Values.startup.failureThreshold }}
85         env:
86           {{- $seed_size := default 1 .Values.replicaCount | int -}}
87           {{- $global := . }}
88           - name: CASSANDRA_SEEDS
89           {{- if .Values.hostNetwork }}
90             value: {{ required "You must fill \".Values.config.seeds\" with list of Cassandra seeds when hostNetwork is set to true" .Values.config.seeds | quote }}
91           {{- else }}
92             value: "{{- range $i, $e := until $seed_size }}{{ template "common.fullname" $global }}-{{ $i }}.{{ template "common.servicename" $global }}.{{ $global.Release.Namespace }}.svc.{{ $global.Values.config.cluster_domain }}{{- if (lt ( add1 $i ) $seed_size ) }},{{- end }}{{- end }}"
93           {{- end }}
94           - name: MAX_HEAP_SIZE
95             value: {{ .Values.config.heap.max }}
96           - name: HEAP_NEWSIZE
97             value: {{ .Values.config.heap.min }}
98           - name: JVM_OPTS
99             value: {{ .Values.config.jvmOpts | quote }}
100           - name: CASSANDRA_CLUSTER_NAME
101             value: {{ .Values.config.clusterName | quote }}
102           - name: CASSANDRA_DC
103             value: {{ .Values.config.dataCenter | quote }}
104           - name: CASSANDRA_RACK
105             value: {{ .Values.config.rackName | quote }}
106           - name: CASSANDRA_AUTO_BOOTSTRAP
107             value: {{ .Values.config.autoBootstrap | quote }}
108           - name: CASSANDRA_START_RPC
109             value: {{ default "true" .Values.config.start_rpc | quote }}
110           - name: CASSANDRA_ENDPOINT_SNITCH
111             value: {{ default "GossipingPropertyFileSnitch" .Values.config.endpoint_snitch | quote }}
112           - name: CASSANDRA_AUTHENTICATOR
113             value: {{ default "PasswordAuthenticator" .Values.config.authenticator | quote }}
114           - name: POD_IP
115             valueFrom:
116               fieldRef:
117                 fieldPath: status.podIP
118         lifecycle:
119           preStop:
120             exec:
121         {{- if not .Values.persistence.enabled }}
122               command: ["/bin/sh", "-c", "exec nodetool decommission"]
123         {{- else }}
124               command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
125         {{- end }}
126         resources: {{ toYaml .Values.resources | nindent 10 }}
127       {{- if .Values.nodeSelector }}
128       nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
129       {{- end -}}
130       {{- if .Values.affinity }}
131       affinity: {{ toYaml .Values.affinity | nindent 8 }}
132       {{- end }}
133       serviceAccountName: {{ include "common.fullname" (dict "suffix" "nothing" "dot" . )}}
134       volumes:
135       - name: localtime
136         hostPath:
137           path: /etc/localtime
138       {{- range $key, $value := .Values.configOverrides }}
139       - name: cassandra-config-{{ $key | replace "." "-" }}
140         configMap:
141           name: {{ include "common.fullname" . }}-configOverrides
142       {{- end }}
143       - name: cassandra-entrypoint
144         configMap:
145           name: {{ include "common.fullname" . }}-entrypoint
146           defaultMode: 0755
147   {{- if not .Values.persistence.enabled }}
148       - name: {{ include "common.fullname" . }}-data
149         emptyDir: {}
150   {{- else }}
151   volumeClaimTemplates:
152     - metadata:
153         name: {{ include "common.fullname" . }}-data
154         labels:
155           name: {{ include "common.fullname" . }}
156           chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
157           release: "{{ include "common.release" . }}"
158           heritage: "{{ .Release.Service }}"
159       spec:
160         accessModes:
161         {{- if .Values.backup.enabled }}
162         - ReadWriteMany
163         {{- else }}
164         - ReadWriteOnce
165         {{- end }}
166         storageClassName: {{ include "common.storageClass" . }}
167         resources:
168           requests:
169             storage: {{ .Values.persistence.size | quote }}
170   {{- end }}