2 # Copyright © 2019 Intel Corporation Inc
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 name: {{ include "common.fullname" . }}
21 heritage: "{{ .Release.Service }}"
22 release: "{{ include "common.release" . }}"
23 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
24 app: {{ include "common.name" . }}
26 serviceName: {{ include "common.servicename" .}}
27 replicas: {{ .Values.replicaCount }}
30 app: {{ include "common.name" . }}
34 heritage: "{{ .Release.Service }}"
35 release: "{{ include "common.release" . }}"
36 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
37 app: {{ include "common.name" . }}
39 {{- if .Values.affinity }}
41 {{ toYaml .Values.affinity | indent 8 }}
43 {{- if .Values.nodeSelector }}
45 {{ toYaml .Values.nodeSelector | indent 8 }}
47 {{- if .Values.tolerations }}
49 {{ toYaml .Values.tolerations | indent 8 }}
52 - name: {{ include "common.fullname" . }}
53 image: "{{ .Values.repository }}/{{ .Values.image }}"
54 imagePullPolicy: "{{ .Values.pullPolicy }}"
56 - containerPort: {{ .Values.service.peerInternalPort }}
57 name: {{ .Values.service.peerPortName }}
58 - containerPort: {{ .Values.service.clientInternalPort }}
59 name: {{ .Values.service.clientPortName }}
60 {{- if eq .Values.liveness.enabled true }}
63 port: {{ .Values.service.clientInternalPort }}
64 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
65 periodSeconds: {{ .Values.liveness.periodSeconds }}
66 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
69 {{ include "common.resources" . | indent 10 }}
71 - name: INITIAL_CLUSTER_SIZE
72 value: {{ .Values.replicaCount | quote }}
74 value: {{ include "common.fullname" . }}
76 value: {{ include "common.servicename" . }}
77 {{- if .Values.extraEnv }}
78 {{ toYaml .Values.extraEnv | indent 8 }}
88 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
89 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
95 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
98 SET_ID=${HOSTNAME##*[^0-9]}
100 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
101 echo "Removing ${HOSTNAME} from etcd cluster"
102 ETCDCTL_ENDPOINT=${EPS} etcdctl member remove $(member_hash)
103 if [ $? -eq 0 ]; then
104 # Remove everything otherwise the cluster will no longer scale-up
105 rm -rf /var/run/etcd/*
114 # store member id into PVC for later member replacement
116 while ! etcdctl member list &>/dev/null; do sleep 1; done
117 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1 > /var/run/etcd/member_id
123 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
124 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
130 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
133 # we should wait for other pods to be up before trying to join
134 # otherwise we got "no such host" errors when trying to resolve other members
135 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
137 echo "Waiting for ${SET_NAME}-${i}.${SERVICE_NAME} to come up"
138 ping -W 1 -c 1 ${SET_NAME}-${i}.${SERVICE_NAME} > /dev/null && break
143 # re-joining after failure?
144 if [[ -e /var/run/etcd/default.etcd && -f /var/run/etcd/member_id ]]; then
145 echo "Re-joining etcd member"
146 member_id=$(cat /var/run/etcd/member_id)
149 ETCDCTL_ENDPOINT=$(eps) etcdctl member update ${member_id} http://${HOSTNAME}.${SERVICE_NAME}:2380 | true
150 exec etcd --name ${HOSTNAME} \
151 --listen-peer-urls http://0.0.0.0:2380 \
152 --listen-client-urls http://0.0.0.0:2379\
153 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
154 --data-dir /var/run/etcd/default.etcd
158 SET_ID=${HOSTNAME##*[^0-9]}
160 # adding a new member to existing cluster (assuming all initial pods are available)
161 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
162 export ETCDCTL_ENDPOINT=$(eps)
164 # member already added?
165 MEMBER_HASH=$(member_hash)
166 if [ -n "${MEMBER_HASH}" ]; then
167 # the member hash exists but for some reason etcd failed
168 # as the datadir has not be created, we can remove the member
169 # and retrieve new hash
170 etcdctl member remove ${MEMBER_HASH}
173 echo "Adding new member"
174 etcdctl member add ${HOSTNAME} http://${HOSTNAME}.${SERVICE_NAME}:2380 | grep "^ETCD_" > /var/run/etcd/new_member_envs
176 if [ $? -ne 0 ]; then
178 rm -f /var/run/etcd/new_member_envs
182 cat /var/run/etcd/new_member_envs
183 source /var/run/etcd/new_member_envs
187 exec etcd --name ${HOSTNAME} \
188 --listen-peer-urls http://0.0.0.0:2380 \
189 --listen-client-urls http://0.0.0.0:2379 \
190 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
191 --data-dir /var/run/etcd/default.etcd \
192 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
193 --initial-cluster ${ETCD_INITIAL_CLUSTER} \
194 --initial-cluster-state ${ETCD_INITIAL_CLUSTER_STATE}
198 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
199 PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SERVICE_NAME}:2380"
205 exec etcd --name ${HOSTNAME} \
206 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
207 --listen-peer-urls http://0.0.0.0:2380 \
208 --listen-client-urls http://0.0.0.0:2379 \
209 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
210 --initial-cluster-token etcd-cluster-1 \
211 --initial-cluster ${PEERS} \
212 --initial-cluster-state new \
213 --data-dir /var/run/etcd/default.etcd
215 - name: {{ include "common.fullname" . }}-data
216 mountPath: /var/run/etcd
217 {{- if .Values.persistence.enabled }}
218 volumeClaimTemplates:
220 name: {{ include "common.fullname" . }}-data
222 name: {{ include "common.fullname" . }}
223 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
224 release: "{{ include "common.release" . }}"
225 heritage: "{{ .Release.Service }}"
228 - "{{ .Values.persistence.accessMode }}"
229 storageClassName: {{ include "common.storageClass" . }}
232 # upstream recommended max is 700M
233 storage: "{{ .Values.persistence.storage }}"
236 - name: {{ include "common.fullname" . }}-data
237 {{- if .Values.memoryMode }}