Skip to content

Instantly share code, notes, and snippets.

@hiddeco
Created February 26, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiddeco/f2f6d355f23512214caecc0222caad6a to your computer and use it in GitHub Desktop.
Save hiddeco/f2f6d355f23512214caecc0222caad6a to your computer and use it in GitHub Desktop.
From 9ef5198b4fdd96931b218e119f75c6f8f53ee416 Mon Sep 17 00:00:00 2001
From: Hidde Beydals <hello@hidde.co>
Date: Mon, 26 Feb 2018 10:45:38 +0100
Subject: [PATCH] Namespace
---
incubator/etcd/templates/statefulset.yaml | 38 +++++++++++++++++--------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/incubator/etcd/templates/statefulset.yaml b/incubator/etcd/templates/statefulset.yaml
index 6b39e042be4d..c7de4265ddb0 100644
--- a/incubator/etcd/templates/statefulset.yaml
+++ b/incubator/etcd/templates/statefulset.yaml
@@ -49,6 +49,10 @@ spec:
value: "1"
- name: SET_NAME
value: {{ template "etcd.fullname" . }}
+ - name: NAMESPACE
+ valueFrom:
+ fieldRef:
+ fieldPath: metadata.namespace
volumeMounts:
- name: datadir
mountPath: /etcd
@@ -68,14 +72,14 @@ spec:
{{- end }}
EPS=""
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
- EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}:2379"
+ EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}.${NAMESPACE}:2379"
done
HOSTNAME=$(hostname)
ETCD_DIR="/etcd"
member_hash() {
- etcdctl member list | grep ${PROTO}://${HOSTNAME}.${SET_NAME}:2380 | cut -d':' -f1 | cut -d'[' -f1
+ etcdctl member list | grep ${PROTO}://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2380 | cut -d':' -f1 | cut -d'[' -f1
}
echo "Removing ${HOSTNAME} from etcd cluster"
@@ -101,7 +105,7 @@ spec:
# store member id into PVC for later member replacement
collect_member() {
while ! etcdctl member list &>/dev/null; do sleep 1; done
- etcdctl member list | grep http://${HOSTNAME}.${SET_NAME}:2379 | cut -d':' -f1 | cut -d'[' -f1 > /etcd/member_id
+ etcdctl member list | grep http://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2379 | cut -d':' -f1 | cut -d'[' -f1 > /etcd/member_id
exit 0
}
@@ -110,9 +114,9 @@ spec:
EPS=""
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
if [ "$SKIP_SELF" = true ]; then
- [ "$SET_ID" != "$i" ] && EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}:2379"
+ [ "$SET_ID" != "$i" ] && EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}.${NAMESPACE}:2379"
else
- EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}:2379"
+ EPS="${EPS}${EPS:+,}http://${SET_NAME}-${i}.${SET_NAME}.${NAMESPACE}:2379"
fi
done
echo ${EPS}
@@ -120,7 +124,7 @@ spec:
member_hash() {
- etcdctl member list | grep http://${HOSTNAME}.${SET_NAME}:2379 | cut -d':' -f1 | cut -d'[' -f1
+ etcdctl member list | grep http://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2379 | cut -d':' -f1 | cut -d'[' -f1
}
wait_member() {
@@ -151,7 +155,7 @@ spec:
echo "Adding [${HOSTNAME}] as new member"
STR_ENV="ETCD_"
- ETCD_PREFIX=$(etcdctl --endpoints ${EPS} member add ${HOSTNAME} ${PROTO}://${HOSTNAME}.${SET_NAME}:2380 | \
+ ETCD_PREFIX=$(etcdctl --endpoints ${EPS} member add ${HOSTNAME} ${PROTO}://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2380 | \
{
while read i
do
@@ -169,12 +173,12 @@ spec:
echo "Start etcd daemon"
exec etcd \
--listen-peer-urls ${PROTO}://${IP}:2380 \
- --initial-advertise-peer-urls ${PROTO}://${HOSTNAME}.${SET_NAME}:2380 \
+ --initial-advertise-peer-urls ${PROTO}://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2380 \
--listen-client-urls http://${IP}:2379,http://127.0.0.1:2379 \
{{- if .Values.PeerTLS }}
--peer-auto-tls \
{{- end }}
- --advertise-client-urls http://${HOSTNAME}.${SET_NAME}:2379
+ --advertise-client-urls http://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2379
}
@@ -188,7 +192,7 @@ spec:
member_id=$(cat /etcd/member_id)
- wait_member ${HOSTNAME}.${SET_NAME}
+ wait_member ${HOSTNAME}.${SET_NAME}.${NAMESPACE}
EPS=$(eps true)
set +e
@@ -205,7 +209,7 @@ spec:
echo "This member_id is still listed in the cluster, join with member_id and existing data"
- etcdctl --endpoints ${EPS} member update ${member_id} ${PROTO}://${HOSTNAME}.${SET_NAME}:2380
+ etcdctl --endpoints ${EPS} member update ${member_id} ${PROTO}://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2380
exec etcd --name ${HOSTNAME} \
--listen-peer-urls ${PROTO}://${IP}:2380 \
@@ -215,7 +219,7 @@ spec:
{{- if .Values.PeerTLS }}
--peer-auto-tls \
{{- end }}
- --advertise-client-urls http://${HOSTNAME}.${SET_NAME}:2379
+ --advertise-client-urls http://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2379
else
echo "This member_id is not listed in the cluster"
add_to_cluster
@@ -225,26 +229,26 @@ spec:
# adding a new member to existing cluster (assuming all initial pods are available)
if [ "${SET_ID}" -ge ${INITIAL_CLUSTER_SIZE} ]; then
echo "Adding an extra member.."
- wait_member ${HOSTNAME}.${SET_NAME}
+ wait_member ${HOSTNAME}.${SET_NAME}.${NAMESPACE}
add_to_cluster
fi
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
- wait_member ${SET_NAME}-${i}.${SET_NAME}
+ wait_member ${SET_NAME}-${i}.${SET_NAME}.${NAMESPACE}
done
PEERS=""
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
- PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=${PROTO}://${SET_NAME}-${i}.${SET_NAME}:2380"
+ PEERS="${PEERS}${PEERS:+,}${SET_NAME}-${i}=${PROTO}://${SET_NAME}-${i}.${SET_NAME}.${NAMESPACE}:2380"
done
collect_member &
echo "Add [${HOSTNAME}] as member to a NEW cluster"
rm -Rf /etcd/*
exec etcd --name ${HOSTNAME} \
- --initial-advertise-peer-urls ${PROTO}://${HOSTNAME}.${SET_NAME}:2380 \
+ --initial-advertise-peer-urls ${PROTO}://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2380 \
--listen-peer-urls ${PROTO}://${IP}:2380 \
--listen-client-urls http://${IP}:2379,http://127.0.0.1:2379 \
- --advertise-client-urls http://${HOSTNAME}.${SET_NAME}:2379 \
+ --advertise-client-urls http://${HOSTNAME}.${SET_NAME}.${NAMESPACE}:2379 \
--initial-cluster ${PEERS} \
{{- if .Values.PeerTLS }}
--peer-auto-tls \
--
2.16.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment