Merge "Set aai&music Cassandra readiness periodSeconds"
[oom.git] / kubernetes / aai / charts / aai-cassandra / templates / statefulset.yaml
1 # Copyright © 2018 Amdocs, Bell Canada, AT&T
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/v1beta1
16 kind: StatefulSet
17 metadata:
18   name: {{ include "common.fullname" . }}
19   namespace: {{ include "common.namespace" . }}
20   labels:
21     app: {{ include "common.name" . }}
22     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
23     release: {{ .Release.Name }}
24     heritage: {{ .Release.Service }}
25 spec:
26   serviceName: {{ include "common.servicename" . }}
27   replicas: {{ .Values.replicaCount }}
28   podManagementPolicy: {{ .Values.podManagementPolicy }}
29   updateStrategy:
30     type: {{ .Values.updateStrategy.type }}
31   template:
32     metadata:
33       labels:
34         app: {{ include "common.name" . }}
35         release: {{ .Release.Name }}
36       name: {{ include "common.name" . }}
37     spec:
38       containers:
39       - name: {{ include "common.name" . }}
40         image: {{ .Values.image }}
41         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
42         ports:
43         - containerPort: {{ .Values.service.internalPort }}
44         - containerPort: {{ .Values.service.internalPort2 }}
45         - containerPort: {{ .Values.service.internalPort3 }}
46         {{- if eq .Values.liveness.enabled true }}
47         livenessProbe:
48           exec:
49            command:
50             - /bin/bash
51             - -c
52             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
53           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
54           periodSeconds: {{ .Values.liveness.periodSeconds }}
55         {{ end -}}
56         readinessProbe:
57           exec:
58             command:
59             - /bin/bash
60             - -c
61             - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }'
62           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
63           periodSeconds: {{ .Values.readiness.periodSeconds }}
64         lifecycle:
65           preStop:
66             exec:
67               command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
68         env:
69         {{- $seed_size := default 1 .Values.replicaCount | int -}}
70         {{- $global := . }}
71           - name: MAX_HEAP_SIZE
72             value: {{ .Values.config.heap.max }}
73           - name: HEAP_NEWSIZE
74             value: {{ .Values.config.heap.min }}
75           - name: CASSANDRA_SEEDS
76             value: "{{- range $i, $e := until $seed_size }}{{ template "common.fullname" $global }}-{{ $i }}.{{ include "common.servicename" $global }},{{- end }}"
77           - name: JVM_OPTS
78             value: {{ .Values.config.jvmOpts | quote }}
79           - name: CASSANDRA_CLUSTER_NAME
80             value: {{ .Values.config.clusterName | quote }}
81           - name: CASSANDRA_DC
82             value: {{ .Values.config.dataCenter | quote }}
83           - name: CASSANDRA_RACK
84             value: {{ .Values.config.rackName | quote }}
85           - name: CASSANDRA_AUTO_BOOTSTRAP
86             value: {{ .Values.config.autoBootstrap | quote }}
87           - name: POD_IP
88             valueFrom:
89               fieldRef:
90                 fieldPath: status.podIP
91         volumeMounts:
92           - name: cassandra-data
93             mountPath: /var/lib/cassandra
94         resources:
95 {{ include "common.resources" . | indent 10 }}
96       {{- if .Values.nodeSelector }}
97       nodeSelector:
98 {{ toYaml .Values.nodeSelector | indent 8 }}
99       {{- end -}}
100       {{- if .Values.affinity }}
101       affinity:
102 {{ toYaml .Values.affinity | indent 8 }}
103       {{- end }}
104       volumes:
105       - name: localtime
106         hostPath:
107           path: /etc/localtime
108   {{- if not .Values.persistence.enabled }}
109       - name: cassandra-data
110         emptyDir: {}
111   {{- else }}
112   volumeClaimTemplates:
113     - metadata:
114         name: cassandra-data
115         labels:
116           app: {{ template "common.fullname" . }}
117           chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
118           release: "{{ .Release.Name }}"
119           heritage: "{{ .Release.Service }}"
120       annotations:
121         volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass }}
122       spec:
123         accessModes:
124           - {{ .Values.persistence.accessMode | quote }}
125         resources:
126           requests:
127             storage: {{ .Values.persistence.size | quote }}
128         selector:
129           matchLabels:
130             app: {{ include "common.name" . }}
131             release: "{{ .Release.Name }}"
132   {{- end }}