forked from svrc/kubo-release
-
Notifications
You must be signed in to change notification settings - Fork 1
/
post-start.erb
82 lines (67 loc) · 2.25 KB
/
post-start.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash -e
[ -z "$DEBUG" ] || set -x
kubectl="/var/vcap/packages/kubernetes/bin/kubectl --kubeconfig=/var/vcap/jobs/kubelet/config/kubeconfig"
DOCKER_SOCKET=unix:///var/vcap/sys/run/docker/docker.sock
CONTAINER_IMAGE_DIR=/var/vcap/packages/kubernetes/container-images
load_container() {
path=$1
echo "loading cached container: ${path}"
if sudo /var/vcap/jobs/kubelet/packages/docker/bin/docker -H ${DOCKER_SOCKET} load < "${path}"; then
echo "successfully loaded container: ${path}"
else
echo "failed to load container: ${path}"
exit 1
fi
}
load_cached_containers() {
for img in ${CONTAINER_IMAGE_DIR}/*.tgz; do
load_container ${img}
done
}
delete_admin_kubeconfig() {
rm /var/vcap/jobs/kubelet/config/admin-kubeconfig
}
load_cached_containers
TIMEOUT=120
if timeout "$TIMEOUT" /var/vcap/jobs/kubelet/bin/ensure_kubelet_up_and_running
then
delete_admin_kubeconfig
node_name=$($kubectl get nodes -o wide -L spec.ip | grep "<%= spec.ip %>$" | grep ' Ready' | awk '{print $1}')
${kubectl} uncordon ${node_name}
${kubectl} get nodes ${node_name} | grep -e ' Ready '
echo "kubelet post-start checks succeeded"
else
echo "kubelet failed post-start checks after $TIMEOUT seconds"
exit 1
fi
if [ $($kubectl get nodes ${node_name} -o jsonpath='{.status.conditions[?(@.type=="NetworkUnavailable")].status}') == "True" ]
then
echo "Need to patch network availability"
v="$(cat <<-EOF
{
"status":{
"conditions": [
{
"type": "NetworkUnavailable",
"status": "False",
"reason": "NetworkProvidedByFlannel",
"message": "Status manually modified by CFCR kubelet post-start"
}
]
}
}
EOF
)"
CLIENT_CERT=$($kubectl config view -o jsonpath='{.users[?(@.name == "default-auth")].user.client-certificate}')
CLIENT_KEY=$($kubectl config view -o jsonpath='{.users[?(@.name == "default-auth")].user.client-key}')
/usr/bin/curl -sS \
--cert ${CLIENT_CERT} \
--key ${CLIENT_KEY} \
--cacert /var/vcap/jobs/kubelet/config/ca.pem \
-H "Accept: application/json" \
-H "Content-Type: application/strategic-merge-patch+json" \
-X PATCH \
-d "$v" \
https://master.cfcr.internal:8443/api/v1/nodes/${node_name}/status
echo "Successfully patched network availability"
fi