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 }}
38 {{- include "common.imagePullSecrets" . | nindent 6 }}
40 - name: {{ include "common.name" . }}
41 image: {{ include "repositoryGenerator.googleK8sRepository" . }}/{{ .Values.image }}
42 imagePullPolicy: "{{ .Values.pullPolicy }}"
44 - containerPort: {{ .Values.service.peerInternalPort }}
45 name: {{ .Values.service.peerPortName }}
46 - containerPort: {{ .Values.service.clientInternalPort }}
47 name: {{ .Values.service.clientPortName }}
48 {{- if eq .Values.liveness.enabled true }}
51 port: {{ .Values.service.clientInternalPort }}
52 initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
53 periodSeconds: {{ .Values.liveness.periodSeconds }}
54 timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
56 resources: {{ include "common.resources" . | nindent 10 }}
58 - name: INITIAL_CLUSTER_SIZE
59 value: {{ .Values.replicaCount | quote }}
61 value: {{ include "common.fullname" . }}
63 value: {{ include "common.servicename" . }}.{{ include "common.namespace" . }}.svc.{{ .Values.global.clusterName }}
64 {{- if .Values.extraEnv }}
65 {{ toYaml .Values.extraEnv | indent 8 }}
75 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
76 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
82 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
85 SET_ID=${HOSTNAME##*[^0-9]}
87 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
88 echo "Removing ${HOSTNAME} from etcd cluster"
89 ETCDCTL_ENDPOINT=${EPS} etcdctl member remove $(member_hash)
91 # Remove everything otherwise the cluster will no longer scale-up
92 rm -rf /var/run/etcd/*
101 # store member id into PVC for later member replacement
103 while ! etcdctl member list &>/dev/null; do sleep 1; done
104 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1 > /var/run/etcd/member_id
110 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
111 EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SERVICE_NAME}:2379"
117 etcdctl member list | grep http://${HOSTNAME}.${SERVICE_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
120 # we should wait for other pods to be up before trying to join
121 # otherwise we got "no such host" errors when trying to resolve other members
122 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
123 if [ "${SET_NAME}-${i}" == "${HOSTNAME}" ]; then
124 echo "Skipping self-checking"
128 echo "Waiting for ${SET_NAME}-${i}.${SERVICE_NAME} to come up"
129 ping -W 1 -c 1 ${SET_NAME}-${i}.${SERVICE_NAME} > /dev/null && break
134 # re-joining after failure?
135 if [[ -e /var/run/etcd/default.etcd && -f /var/run/etcd/member_id ]]; then
136 echo "Re-joining etcd member"
137 member_id=$(cat /var/run/etcd/member_id)
140 ETCDCTL_ENDPOINT=$(eps) etcdctl member update ${member_id} http://${HOSTNAME}.${SERVICE_NAME}:2380 | true
141 exec etcd --name ${HOSTNAME} \
142 --listen-peer-urls http://0.0.0.0:2380 \
143 --listen-client-urls http://0.0.0.0:2379\
144 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
145 --data-dir /var/run/etcd/default.etcd
149 SET_ID=${HOSTNAME##*[^0-9]}
151 # adding a new member to existing cluster (assuming all initial pods are available)
152 if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
153 export ETCDCTL_ENDPOINT=$(eps)
155 # member already added?
156 MEMBER_HASH=$(member_hash)
157 if [ -n "${MEMBER_HASH}" ]; then
158 # the member hash exists but for some reason etcd failed
159 # as the datadir has not be created, we can remove the member
160 # and retrieve new hash
161 etcdctl member remove ${MEMBER_HASH}
164 echo "Adding new member"
165 etcdctl member add ${HOSTNAME} http://${HOSTNAME}.${SERVICE_NAME}:2380 | grep "^ETCD_" > /var/run/etcd/new_member_envs
167 if [ $? -ne 0 ]; then
169 rm -f /var/run/etcd/new_member_envs
173 cat /var/run/etcd/new_member_envs
174 . /var/run/etcd/new_member_envs
178 exec etcd --name ${HOSTNAME} \
179 --listen-peer-urls http://0.0.0.0:2380 \
180 --listen-client-urls http://0.0.0.0:2379 \
181 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
182 --data-dir /var/run/etcd/default.etcd \
183 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
184 --initial-cluster ${ETCD_INITIAL_CLUSTER} \
185 --initial-cluster-state ${ETCD_INITIAL_CLUSTER_STATE}
189 for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
190 PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=http://${SET_NAME}-${i}.${SERVICE_NAME}:2380"
196 exec etcd --name ${HOSTNAME} \
197 --initial-advertise-peer-urls http://${HOSTNAME}.${SERVICE_NAME}:2380 \
198 --listen-peer-urls http://0.0.0.0:2380 \
199 --listen-client-urls http://0.0.0.0:2379 \
200 --advertise-client-urls http://${HOSTNAME}.${SERVICE_NAME}:2379 \
201 --initial-cluster-token etcd-cluster-1 \
202 --initial-cluster ${PEERS} \
203 --initial-cluster-state new \
204 --data-dir /var/run/etcd/default.etcd
206 - name: {{ include "common.fullname" . }}-data
207 mountPath: /var/run/etcd
208 {{- if .Values.persistence.enabled }}
209 volumeClaimTemplates:
211 name: {{ include "common.fullname" . }}-data
213 name: {{ include "common.fullname" . }}
214 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
215 release: "{{ include "common.release" . }}"
216 heritage: "{{ .Release.Service }}"
219 - "{{ .Values.persistence.accessMode }}"
220 storageClassName: {{ include "common.storageClass" . }}
223 # upstream recommended max is 700M
224 storage: "{{ .Values.persistence.storage }}"
227 - name: {{ include "common.fullname" . }}-data
228 {{- if .Values.memoryMode }}