-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.sh
executable file
·186 lines (174 loc) · 4.74 KB
/
run.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
BANNER=kubernetes
for i in $(seq 1 $DEPTH); do
BANNER=$(printf "kubernetes in %s\n" "$BANNER")
done
echo
echo -e "\033[00;36m###############################################\033[00m"
echo -e "\033[00;32m$BANNER\033[00m"
echo -e "\033[00;31mSTAGE: $DEPTH\033[00m"
echo -e "\033[00;36m###############################################\033[00m"
echo
sleep 3
echo
echo -e "\033[00;36m####### LAUNCH DOCKER DAEMON #######\033[00m"
echo
nohup dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 > dockerd.log 2>&1 &
wait=0
while true; do
docker ps -q > /dev/null 2>&1 && break
if [[ ${wait} -lt 10 ]]; then
wait=$((wait+1))
echo "waiting for docker ..."
sleep ${wait}
else
echo "docker is broken ..."
exit 1
fi
done
echo
echo -e "\033[00;36m####### CREATE KIND CLUSTER #######\033[00m"
echo
kind create cluster
kind get kubeconfig > file
cat file
# waiting admission controller
wait=0;
while true; do
kubectl --kubeconfig=/kube/file get sa default && break
if [[ ${wait} -lt 10 ]]; then
wait=$((wait+1))
echo "waiting for creating sa ..."
sleep ${wait}
else
echo "sa is not ready ..."
exit 1
fi
done
# confirm creating kube-system component
# From https://github.com/groundnuty/k8s-wait-for/blob/master/wait_for.sh
wait=0;
while true; do
STATUS=$(kubectl --kubeconfig=/kube/file get pods -n kube-system -o go-template='
{{- define "checkStatus" -}}
{{- $rootStatus := .status }}
{{- $hasReadyStatus := false }}
{{- range .status.conditions -}}
{{- if eq .type "Ready" -}}
{{- $hasReadyStatus = true }}
{{- if eq .status "False" -}}
{{- if .reason -}}
{{- if ne .reason "PodCompleted" -}}
{{ .status }}
{{- range $rootStatus.containerStatuses -}}
{{- if .state.terminated.reason -}}
:{{ .state.terminated.reason }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{ .status }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- printf "No resources found.\n" -}}
{{- end -}}
{{- if ne $hasReadyStatus true -}}
{{- printf "False" -}}
{{- end -}}
{{- end -}}
{{- if .items -}}
{{- range .items -}}
{{ template "checkStatus" . }}
{{- end -}}
{{- else -}}
{{ template "checkStatus" . }}
{{- end -}}')
if [[ "$STATUS" == "" ]] ; then
break
fi
if [[ ${wait} -lt 10 ]]; then
wait=$((wait+1))
echo "waiting for kube-system component ..."
sleep ${wait}
else
echo "one of kube-system component is broken ..."
exit 1
fi
done
echo
echo -e "\033[00;36m####### REBIRTH KIND POD #######\033[00m"
echo
NEWDEPTH=$((DEPTH+1))
sed -i "s/value:.*$/value: \"$NEWDEPTH\"/g" /kube/create-kind.yaml
kubectl --kubeconfig=/kube/file apply -f /kube/create-kind.yaml || :
# sometime kind api is not ready for getting pods log
# it return empty logs with 200
# so before finding a cause just sleep some seconds
echo "sleep 10 secs for waiting pod ..."
sleep 10
# confirm creating kind pod
wait=0;
while true; do
STATUS=$(kubectl --kubeconfig=/kube/file get pods -o go-template='
{{- define "checkStatus" -}}
{{- $rootStatus := .status }}
{{- $hasReadyStatus := false }}
{{- range .status.conditions -}}
{{- if eq .type "Ready" -}}
{{- $hasReadyStatus = true }}
{{- if eq .status "False" -}}
{{- if .reason -}}
{{- if ne .reason "PodCompleted" -}}
{{ .status }}
{{- range $rootStatus.containerStatuses -}}
{{- if .state.terminated.reason -}}
:{{ .state.terminated.reason }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{ .status }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- printf "No resources found.\n" -}}
{{- end -}}
{{- if ne $hasReadyStatus true -}}
{{- printf "False" -}}
{{- end -}}
{{- end -}}
{{- if .items -}}
{{- range .items -}}
{{ template "checkStatus" . }}
{{- end -}}
{{- else -}}
{{ template "checkStatus" . }}
{{- end -}}')
if [[ "$STATUS" == "" ]] ; then
break
fi
if [[ ${wait} -lt 10 ]]; then
wait=$((wait+1))
echo "waiting for kind ..."
sleep ${wait}
else
echo "newer kind is broken ..."
exit 1
fi
done
wait=0;
while true; do
kubectl --kubeconfig=/kube/file logs kubeinception > /dev/null && break
if [[ ${wait} -lt 10 ]]; then
wait=$((wait+1))
echo "waiting for creating pod ..."
sleep ${wait}
else
echo "pod is not ready ..."
exit 1
fi
done
kubectl --kubeconfig=/kube/file logs kubeinception -f