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.
18 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
20 selector: {{- include "common.selectors" . | nindent 4 }}
21 serviceName: {{ include "common.servicename" . }}
22 replicas: {{ .Values.replicaCount }}
24 metadata: {{- include "common.templateMetadata" . | nindent 6 }}
26 {{- if .Values.affinity }}
28 {{ toYaml .Values.affinity | indent 8 }}
30 {{- if .Values.nodeSelector }}
32 {{ toYaml .Values.nodeSelector | indent 8 }}
34 {{- if .Values.tolerations }}
36 {{ toYaml .Values.tolerations | indent 8 }}
39 - name: "{{ include "common.namespace" . }}-docker-registry-key"
41 - name: {{ include "common.name" . }}
42 image: {{ include "repositoryGenerator.googleK8sRepository" . }}/{{ .Values.image }}
43 imagePullPolicy: "{{ .Values.pullPolicy }}"
45 - containerPort: {{ .Values.service.peerInternalPort }}
46 name: {{ .Values.service.peerPortName }}
47 - containerPort: {{ .Values.service.clientInternalPort }}
48 name: {{ .Values.service.clientPortName }}
49 {{- if eq .Values.liveness.enabled true }}
52 port: {{ .Values.service.clientInternalPort }}
53 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
54 periodSeconds: {{ .Values.liveness.periodSeconds }}
55 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
57 resources: {{ include "common.resources" . | nindent 10 }}
59 - name: INITIAL_CLUSTER_SIZE
60 value: {{ .Values.replicaCount | quote }}
62 value: {{ include "common.fullname" . }}
64 value: {{ include "common.servicename" . }}.{{ include "common.namespace" . }}.svc.{{ .Values.global.clusterName }}
65 {{- if .Values.extraEnv }}
66 {{ toYaml .Values.extraEnv | indent 8 }}
76 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
77 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
83 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
86 SET_ID=${HOSTNAME##*[^0-9]}
88 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
89 echo "Removing ${HOSTNAME} from etcd cluster"
90 ETCDCTL_ENDPOINT=${EPS} etcdctl member remove $(member_hash)
92 # Remove everything otherwise the cluster will no longer scale-up
93 rm -rf /var/run/etcd/*
102 # store member id into PVC for later member replacement
104 while ! etcdctl member list &>/dev/null; do sleep 1; done
105 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1 > /var/run/etcd/member_id
111 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
112 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
118 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
121 # we should wait for other pods to be up before trying to join
122 # otherwise we got "no such host" errors when trying to resolve other members
123 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
124 if [ "${SET_NAME}-${i}" == "${HOSTNAME}" ]; then
125 echo "Skipping self-checking"
129 echo "Waiting for ${SET_NAME}-${i}.${SERVICE_NAME} to come up"
130 ping -W 1 -c 1 ${SET_NAME}-${i}.${SERVICE_NAME} > /dev/null && break
135 # re-joining after failure?
136 if [[ -e /var/run/etcd/default.etcd && -f /var/run/etcd/member_id ]]; then
137 echo "Re-joining etcd member"
138 member_id=$(cat /var/run/etcd/member_id)
141 ETCDCTL_ENDPOINT=$(eps) etcdctl member update ${member_id} http://${HOSTNAME}.${SERVICE_NAME}:2380 | true
142 exec etcd --name ${HOSTNAME} \
143 --listen-peer-urls http://0.0.0.0:2380 \
144 --listen-client-urls http://0.0.0.0:2379\
145 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
146 --data-dir /var/run/etcd/default.etcd
150 SET_ID=${HOSTNAME##*[^0-9]}
152 # adding a new member to existing cluster (assuming all initial pods are available)
153 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
154 export ETCDCTL_ENDPOINT=$(eps)
156 # member already added?
157 MEMBER_HASH=$(member_hash)
158 if [ -n "${MEMBER_HASH}" ]; then
159 # the member hash exists but for some reason etcd failed
160 # as the datadir has not be created, we can remove the member
161 # and retrieve new hash
162 etcdctl member remove ${MEMBER_HASH}
165 echo "Adding new member"
166 etcdctl member add ${HOSTNAME} http://${HOSTNAME}.${SERVICE_NAME}:2380 | grep "^ETCD_" > /var/run/etcd/new_member_envs
168 if [ $? -ne 0 ]; then
170 rm -f /var/run/etcd/new_member_envs
174 cat /var/run/etcd/new_member_envs
175 . /var/run/etcd/new_member_envs
179 exec etcd --name ${HOSTNAME} \
180 --listen-peer-urls http://0.0.0.0:2380 \
181 --listen-client-urls http://0.0.0.0:2379 \
182 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
183 --data-dir /var/run/etcd/default.etcd \
184 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
185 --initial-cluster ${ETCD_INITIAL_CLUSTER} \
186 --initial-cluster-state ${ETCD_INITIAL_CLUSTER_STATE}
190 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
191 PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SERVICE_NAME}:2380"
197 exec etcd --name ${HOSTNAME} \
198 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
199 --listen-peer-urls http://0.0.0.0:2380 \
200 --listen-client-urls http://0.0.0.0:2379 \
201 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
202 --initial-cluster-token etcd-cluster-1 \
203 --initial-cluster ${PEERS} \
204 --initial-cluster-state new \
205 --data-dir /var/run/etcd/default.etcd
207 - name: {{ include "common.fullname" . }}-data
208 mountPath: /var/run/etcd
209 {{- if .Values.persistence.enabled }}
210 volumeClaimTemplates:
212 name: {{ include "common.fullname" . }}-data
214 name: {{ include "common.fullname" . }}
215 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
216 release: "{{ include "common.release" . }}"
217 heritage: "{{ .Release.Service }}"
220 - "{{ .Values.persistence.accessMode }}"
221 storageClassName: {{ include "common.storageClass" . }}
224 # upstream recommended max is 700M
225 storage: "{{ .Values.persistence.storage }}"
228 - name: {{ include "common.fullname" . }}-data
229 {{- if .Values.memoryMode }}