1 # Copyright © 2019 Intel Corporation Inc
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 apiVersion: apps/v1beta1
18 name: {{ include "common.fullname" . }}
20 heritage: "{{ .Release.Service }}"
21 release: "{{ .Release.Name }}"
22 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
23 app: {{ include "common.name" . }}
25 serviceName: {{ include "common.servicename" .}}
26 replicas: {{ .Values.replicaCount }}
30 heritage: "{{ .Release.Service }}"
31 release: "{{ .Release.Name }}"
32 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
33 app: {{ include "common.name" . }}
35 {{- if .Values.affinity }}
37 {{ toYaml .Values.affinity | indent 8 }}
39 {{- if .Values.nodeSelector }}
41 {{ toYaml .Values.nodeSelector | indent 8 }}
43 {{- if .Values.tolerations }}
45 {{ toYaml .Values.tolerations | indent 8 }}
48 - name: {{ include "common.fullname" . }}
49 image: "{{ .Values.repository }}/{{ .Values.image }}"
50 imagePullPolicy: "{{ .Values.pullPolicy }}"
52 - containerPort: {{ .Values.service.peerInternalPort }}
53 name: {{ .Values.service.peerPortName }}
54 - containerPort: {{ .Values.service.clientInternalPort }}
55 name: {{ .Values.service.clientPortName }}
56 {{- if eq .Values.liveness.enabled true }}
59 command: ["/bin/sh", "-c", "etcdctl cluster-health | grep -w healthy" ]
60 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
61 periodSeconds: {{ .Values.liveness.periodSeconds }}
62 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
66 command: ["/bin/sh", "-c", "etcdctl cluster-health | grep -w healthy" ]
67 initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
68 periodSeconds: {{ .Values.readiness.periodSeconds }}
70 {{ include "common.resources" . | indent 10 }}
72 - name: INITIAL_CLUSTER_SIZE
73 value: {{ .Values.replicaCount | quote }}
75 value: {{ include "common.fullname" . }}
77 value: {{ include "common.servicename" . }}
78 {{- if .Values.extraEnv }}
79 {{ toYaml .Values.extraEnv | indent 8 }}
89 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
90 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
96 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
99 SET_ID=${HOSTNAME##*[^0-9]}
101 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
102 echo "Removing ${HOSTNAME} from etcd cluster"
103 ETCDCTL_ENDPOINT=${EPS} etcdctl member remove $(member_hash)
104 if [ $? -eq 0 ]; then
105 # Remove everything otherwise the cluster will no longer scale-up
106 rm -rf /var/run/etcd/*
115 # store member id into PVC for later member replacement
117 while ! etcdctl member list &>/dev/null; do sleep 1; done
118 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1 > /var/run/etcd/member_id
124 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
125 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
131 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
134 # we should wait for other pods to be up before trying to join
135 # otherwise we got "no such host" errors when trying to resolve other members
136 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
138 echo "Waiting for ${SET_NAME}-${i}.${SERVICE_NAME} to come up"
139 ping -W 1 -c 1 ${SET_NAME}-${i}.${SERVICE_NAME} > /dev/null && break
144 # re-joining after failure?
145 if [ -e /var/run/etcd/default.etcd ]; then
146 echo "Re-joining etcd member"
147 member_id=$(cat /var/run/etcd/member_id)
150 ETCDCTL_ENDPOINT=$(eps) etcdctl member update ${member_id} http://${HOSTNAME}.${SERVICE_NAME}:2380 | true
151 exec etcd --name ${HOSTNAME} \
152 --listen-peer-urls http://0.0.0.0:2380 \
153 --listen-client-urls http://0.0.0.0:2379\
154 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
155 --data-dir /var/run/etcd/default.etcd
159 SET_ID=${HOSTNAME##*[^0-9]}
161 # adding a new member to existing cluster (assuming all initial pods are available)
162 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
163 export ETCDCTL_ENDPOINT=$(eps)
165 # member already added?
166 MEMBER_HASH=$(member_hash)
167 if [ -n "${MEMBER_HASH}" ]; then
168 # the member hash exists but for some reason etcd failed
169 # as the datadir has not be created, we can remove the member
170 # and retrieve new hash
171 etcdctl member remove ${MEMBER_HASH}
174 echo "Adding new member"
175 etcdctl member add ${HOSTNAME} http://${HOSTNAME}.${SERVICE_NAME}:2380 | grep "^ETCD_" > /var/run/etcd/new_member_envs
177 if [ $? -ne 0 ]; then
179 rm -f /var/run/etcd/new_member_envs
183 cat /var/run/etcd/new_member_envs
184 source /var/run/etcd/new_member_envs
188 exec etcd --name ${HOSTNAME} \
189 --listen-peer-urls http://0.0.0.0:2380 \
190 --listen-client-urls http://0.0.0.0:2379 \
191 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
192 --data-dir /var/run/etcd/default.etcd \
193 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
194 --initial-cluster ${ETCD_INITIAL_CLUSTER} \
195 --initial-cluster-state ${ETCD_INITIAL_CLUSTER_STATE}
199 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
200 PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SERVICE_NAME}:2380"
206 exec etcd --name ${HOSTNAME} \
207 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
208 --listen-peer-urls http://0.0.0.0:2380 \
209 --listen-client-urls http://0.0.0.0:2379 \
210 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
211 --initial-cluster-token etcd-cluster-1 \
212 --initial-cluster ${PEERS} \
213 --initial-cluster-state new \
214 --data-dir /var/run/etcd/default.etcd
216 - name: {{ include "common.fullname" . }}-data
217 mountPath: /var/run/etcd
218 {{- if .Values.persistence.enabled }}
219 volumeClaimTemplates:
221 name: {{ include "common.fullname" . }}-data
224 - "{{ .Values.persistence.accessMode }}"
227 # upstream recommended max is 700M
228 storage: "{{ .Values.persistence.storage }}"
229 storageClassName: {{ include "common.fullname" . }}-data
232 - name: {{ include "common.fullname" . }}-data
233 {{- if .Values.memoryMode }}