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.
17 name: {{ include "common.fullname" . }}
19 heritage: "{{ .Release.Service }}"
20 release: "{{ include "common.release" . }}"
21 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
22 app: {{ include "common.name" . }}
24 serviceName: {{ include "common.servicename" .}}
25 replicas: {{ .Values.replicaCount }}
28 app: {{ include "common.name" . }}
32 heritage: "{{ .Release.Service }}"
33 release: "{{ include "common.release" . }}"
34 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
35 app: {{ include "common.name" . }}
37 {{- if .Values.affinity }}
39 {{ toYaml .Values.affinity | indent 8 }}
41 {{- if .Values.nodeSelector }}
43 {{ toYaml .Values.nodeSelector | indent 8 }}
45 {{- if .Values.tolerations }}
47 {{ toYaml .Values.tolerations | indent 8 }}
50 - name: {{ include "common.fullname" . }}
51 image: "{{ .Values.repository }}/{{ .Values.image }}"
52 imagePullPolicy: "{{ .Values.pullPolicy }}"
54 - containerPort: {{ .Values.service.peerInternalPort }}
55 name: {{ .Values.service.peerPortName }}
56 - containerPort: {{ .Values.service.clientInternalPort }}
57 name: {{ .Values.service.clientPortName }}
58 {{- if eq .Values.liveness.enabled true }}
61 port: {{ .Values.service.clientInternalPort }}
62 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
63 periodSeconds: {{ .Values.liveness.periodSeconds }}
64 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
67 {{ include "common.resources" . | indent 10 }}
69 - name: INITIAL_CLUSTER_SIZE
70 value: {{ .Values.replicaCount | quote }}
72 value: {{ include "common.fullname" . }}
74 value: {{ include "common.servicename" . }}
75 {{- if .Values.extraEnv }}
76 {{ toYaml .Values.extraEnv | indent 8 }}
86 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
87 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
93 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
96 SET_ID=${HOSTNAME##*[^0-9]}
98 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
99 echo "Removing ${HOSTNAME} from etcd cluster"
100 ETCDCTL_ENDPOINT=${EPS} etcdctl member remove $(member_hash)
101 if [ $? -eq 0 ]; then
102 # Remove everything otherwise the cluster will no longer scale-up
103 rm -rf /var/run/etcd/*
112 # store member id into PVC for later member replacement
114 while ! etcdctl member list &>/dev/null; do sleep 1; done
115 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1 > /var/run/etcd/member_id
121 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
122 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
128 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
131 # we should wait for other pods to be up before trying to join
132 # otherwise we got "no such host" errors when trying to resolve other members
133 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
135 echo "Waiting for ${SET_NAME}-${i}.${SERVICE_NAME} to come up"
136 ping -W 1 -c 1 ${SET_NAME}-${i}.${SERVICE_NAME} > /dev/null && break
141 # re-joining after failure?
142 if [[ -e /var/run/etcd/default.etcd && -f /var/run/etcd/member_id ]]; then
143 echo "Re-joining etcd member"
144 member_id=$(cat /var/run/etcd/member_id)
147 ETCDCTL_ENDPOINT=$(eps) etcdctl member update ${member_id} http://${HOSTNAME}.${SERVICE_NAME}:2380 | true
148 exec etcd --name ${HOSTNAME} \
149 --listen-peer-urls http://0.0.0.0:2380 \
150 --listen-client-urls http://0.0.0.0:2379\
151 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
152 --data-dir /var/run/etcd/default.etcd
156 SET_ID=${HOSTNAME##*[^0-9]}
158 # adding a new member to existing cluster (assuming all initial pods are available)
159 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
160 export ETCDCTL_ENDPOINT=$(eps)
162 # member already added?
163 MEMBER_HASH=$(member_hash)
164 if [ -n "${MEMBER_HASH}" ]; then
165 # the member hash exists but for some reason etcd failed
166 # as the datadir has not be created, we can remove the member
167 # and retrieve new hash
168 etcdctl member remove ${MEMBER_HASH}
171 echo "Adding new member"
172 etcdctl member add ${HOSTNAME} http://${HOSTNAME}.${SERVICE_NAME}:2380 | grep "^ETCD_" > /var/run/etcd/new_member_envs
174 if [ $? -ne 0 ]; then
176 rm -f /var/run/etcd/new_member_envs
180 cat /var/run/etcd/new_member_envs
181 source /var/run/etcd/new_member_envs
185 exec etcd --name ${HOSTNAME} \
186 --listen-peer-urls http://0.0.0.0:2380 \
187 --listen-client-urls http://0.0.0.0:2379 \
188 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
189 --data-dir /var/run/etcd/default.etcd \
190 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
191 --initial-cluster ${ETCD_INITIAL_CLUSTER} \
192 --initial-cluster-state ${ETCD_INITIAL_CLUSTER_STATE}
196 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
197 PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SERVICE_NAME}:2380"
203 exec etcd --name ${HOSTNAME} \
204 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
205 --listen-peer-urls http://0.0.0.0:2380 \
206 --listen-client-urls http://0.0.0.0:2379 \
207 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
208 --initial-cluster-token etcd-cluster-1 \
209 --initial-cluster ${PEERS} \
210 --initial-cluster-state new \
211 --data-dir /var/run/etcd/default.etcd
213 - name: {{ include "common.fullname" . }}-data
214 mountPath: /var/run/etcd
215 {{- if .Values.persistence.enabled }}
216 volumeClaimTemplates:
218 name: {{ include "common.fullname" . }}-data
220 name: {{ include "common.fullname" . }}
221 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
222 release: "{{ include "common.release" . }}"
223 heritage: "{{ .Release.Service }}"
226 - "{{ .Values.persistence.accessMode }}"
227 storageClassName: {{ include "common.storageClass" . }}
230 # upstream recommended max is 700M
231 storage: "{{ .Values.persistence.storage }}"
234 - name: {{ include "common.fullname" . }}-data
235 {{- if .Values.memoryMode }}