Skip to content

Commit

Permalink
Merge pull request #94 from wnxn/ensure-updating-eip
Browse files Browse the repository at this point in the history
ensure updating eip
  • Loading branch information
Wiley Wang authored Aug 6, 2019
2 parents 88ea006 + e992006 commit a6aceb0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/config/cluster.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"role": "master",
"container": {
"type": "kvm",
"image": "img-83n37lwx",
"image": "img-tpwxmn8b",
"zone": "sh1a"
},
"instance_class": {{cluster.master.instance_class}},
Expand Down Expand Up @@ -102,7 +102,7 @@
"role": "node_perf",
"container": {
"type": "kvm",
"image": "img-83n37lwx",
"image": "img-tpwxmn8b",
"zone": "sh1a"
},
"instance_class": 0,
Expand Down Expand Up @@ -171,7 +171,7 @@
"role": "node_super_perf",
"container": {
"type": "kvm",
"image": "img-83n37lwx",
"image": "img-tpwxmn8b",
"zone": "sh1a"
},
"instance_class": 1,
Expand Down Expand Up @@ -240,7 +240,7 @@
"role": "client",
"container": {
"type": "kvm",
"image": "img-83n37lwx",
"image": "img-tpwxmn8b",
"zone": "sh1a"
},
"instance_class": {{cluster.client.instance_class}},
Expand Down
40 changes: 40 additions & 0 deletions confd/templates/k8s/2-reload-cmd-kubeadm-eip.sh.tmpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
#!/bin/bash
export PATH="$PATH:/usr/local/bin"
KUBEADM_FILE=/etc/kubernetes/kubeadm-eip.yaml

function retry {
local n=1
local max=5
local delay=1
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
echo "The command has failed after $n attempts."
return 1
fi
}
done
}

function get_eip_from_kubeadm {
if [ "$(cat ${KUBEADM_FILE}|shyaml get-length apiServer.certSANs)" == "2" ] && [ "$(cat /etc/kubernetes/kubeadm-eip.yaml |shyaml get-value apiServer.certSANs.1)" != "" ]; then
echo $(cat /etc/kubernetes/kubeadm-eip.yaml |shyaml get-value apiServer.certSANs.1)
else
echo ""
fi
}

function is_valid {
kubeadm_eip=$(get_eip_from_kubeadm)
if [ "{{getv "/env/kubernetes_eip"}}" == "${kubeadm_eip}" ]; then
return 0
else
return 1
fi
}

echo {{getv "/env/kubernetes_eip"}}
retry is_valid
/opt/kubernetes/script/reload-kubeadm-eip.sh
4 changes: 4 additions & 0 deletions script/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ source "${K8S_HOME}/version"
set -o nounset
set -o pipefail

function fail {
echo $1 >&2
exit 1
}

function log {
logger -t appctl $@
Expand Down
9 changes: 4 additions & 5 deletions script/reload-kubeadm-eip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ then
replace_kubeadm_eip_lb_ip
fi

log "remove apiserver.crt"
rm -rf /etc/kubernetes/pki/apiserver.crt
log "remove apiserver.key"
rm -rf /etc/kubernetes/pki/apiserver.key

if [ "${HOST_ROLE}" == "master" ]
then
log "remove apiserver.crt"
rm -rf /etc/kubernetes/pki/apiserver.crt
log "remove apiserver.key"
rm -rf /etc/kubernetes/pki/apiserver.key
log "create apiserver certs with eip"
kubeadm init phase certs apiserver --config ${KUBEADM_EIP_PATH}
log "restart kubernetes apiserver"
Expand Down

0 comments on commit a6aceb0

Please sign in to comment.