Merge "[AAF] v1.16+ compatible templates"
[oom.git] / kubernetes / common / cassandra / templates / statefulset.yaml
1 # Copyright © 2018 Amdocs, AT&T, Bell Canada
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 apiVersion: apps/v1
16 kind: StatefulSet
17 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
18 spec:
19   selector: {{- include "common.selectors" . | nindent 4 }}
20   serviceName: {{ include "common.servicename" . }}
21   replicas: {{ .Values.replicaCount }}
22   podManagementPolicy: {{ .Values.podManagementPolicy }}
23   updateStrategy:
24     type: {{ .Values.updateStrategy.type }}
25   template:
26     metadata: {{- include "common.templateMetadata" . | nindent 6 }}
27     spec:
28       hostNetwork: {{ .Values.hostNetwork }}
29       containers:
30       - name: {{ include "common.name" . }}
31         image: "{{ include "common.repository" . }}/{{ .Values.image }}"
32         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
33         ports: {{ include "common.containerPorts" . | nindent 8  }}
34         volumeMounts:
35           - name: {{ include "common.fullname" . }}-data
36             mountPath: /var/lib/cassandra
37           - name: localtime
38             mountPath: /etc/localtime
39             readOnly: true
40           - name: cassandra-entrypoint
41             mountPath: /docker-entrypoint.sh
42             subPath: docker-entrypoint.sh
43           {{- range $key, $value := .Values.configOverrides }}
44           - name: cassandra-config-{{ $key | replace "." "-" }}
45             mountPath: /etc/cassandra/{{ $key }}
46             subPath: {{ $key }}
47           {{- end }}
48         {{- if eq .Values.liveness.enabled true }}
49         livenessProbe:
50           exec:
51            command:
52             - /bin/bash
53             - -c
54             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
55           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
56           periodSeconds: {{ .Values.liveness.periodSeconds }}
57           timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
58           successThreshold: {{ .Values.liveness.successThreshold }}
59           failureThreshold: {{ .Values.liveness.failureThreshold }}
60         {{ end }}
61         readinessProbe:
62           exec:
63             command:
64             - /bin/bash
65             - -c
66             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
67           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
68           periodSeconds: {{ .Values.readiness.periodSeconds }}
69           timeoutSeconds: {{ .Values.readiness.timeoutSeconds }}
70           successThreshold: {{ .Values.readiness.successThreshold }}
71           failureThreshold: {{ .Values.readiness.failureThreshold }}
72         env:
73           {{- $seed_size := default 1 .Values.replicaCount | int -}}
74           {{- $global := . }}
75           - name: CASSANDRA_SEEDS
76           {{- if .Values.hostNetwork }}
77             value: {{ required "You must fill \".Values.config.seeds\" with list of Cassandra seeds when hostNetwork is set to true" .Values.config.seeds | quote }}
78           {{- else }}
79             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 }}"
80           {{- end }}
81           - name: MAX_HEAP_SIZE
82             value: {{ .Values.config.heap.max }}
83           - name: HEAP_NEWSIZE
84             value: {{ .Values.config.heap.min }}
85           - name: JVM_OPTS
86             value: {{ .Values.config.jvmOpts | quote }}
87           - name: CASSANDRA_CLUSTER_NAME
88             value: {{ .Values.config.clusterName | quote }}
89           - name: CASSANDRA_DC
90             value: {{ .Values.config.dataCenter | quote }}
91           - name: CASSANDRA_RACK
92             value: {{ .Values.config.rackName | quote }}
93           - name: CASSANDRA_AUTO_BOOTSTRAP
94             value: {{ .Values.config.autoBootstrap | quote }}
95           - name: CASSANDRA_START_RPC
96             value: {{ default "true" .Values.config.start_rpc | quote }}
97           - name: CASSANDRA_ENDPOINT_SNITCH
98             value: {{ default "GossipingPropertyFileSnitch" .Values.config.endpoint_snitch | quote }}
99           - name: CASSANDRA_AUTHENTICATOR
100             value: {{ default "PasswordAuthenticator" .Values.config.authenticator | quote }}
101           - name: POD_IP
102             valueFrom:
103               fieldRef:
104                 fieldPath: status.podIP
105         lifecycle:
106           preStop:
107             exec:
108         {{- if not .Values.persistence.enabled }}
109               command: ["/bin/sh", "-c", "exec nodetool decommission"]
110         {{- else }}
111               command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
112         {{- end }}
113         resources:
114 {{ toYaml .Values.resources | indent 10 }}
115       {{- if .Values.nodeSelector }}
116       nodeSelector:
117 {{ toYaml .Values.nodeSelector | indent 8 }}
118       {{- end -}}
119       {{- if .Values.affinity }}
120       affinity:
121 {{ toYaml .Values.affinity | indent 8 }}
122       {{- end }}
123       volumes:
124       - name: localtime
125         hostPath:
126           path: /etc/localtime
127       {{- range $key, $value := .Values.configOverrides }}
128       - name: cassandra-config-{{ $key | replace "." "-" }}
129         configMap:
130           name: {{ include "common.fullname" . }}-configOverrides
131       {{- end }}
132       - name: cassandra-entrypoint
133         configMap:
134           name: {{ include "common.fullname" . }}-entrypoint
135           defaultMode: 0755
136   {{- if not .Values.persistence.enabled }}
137       - name: {{ include "common.fullname" . }}-data
138         emptyDir: {}
139   {{- else }}
140   volumeClaimTemplates:
141     - metadata:
142         name: {{ include "common.fullname" . }}-data
143         labels:
144           name: {{ include "common.fullname" . }}
145           chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
146           release: "{{ include "common.release" . }}"
147           heritage: "{{ .Release.Service }}"
148       spec:
149         accessModes:
150         {{- if .Values.backup.enabled }}
151         - ReadWriteMany
152         {{- else }}
153         - ReadWriteOnce
154         {{- end }}
155         storageClassName: {{ include "common.storageClass" . }}
156         resources:
157           requests:
158             storage: {{ .Values.persistence.size | quote }}
159   {{- end }}