This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller-test.sh
executable file
·286 lines (262 loc) · 9.73 KB
/
controller-test.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
NOCOLOR='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
MAGENTA='\033[1;35m'
DIOSCURI_IMAGE=amazeeiolocal/dioscuri:test-tag
DIOSCURI_NS=dioscuri-controller
CHECK_TIMEOUT=10
KIND_NAME=chart-testing
check_dioscuri_log () {
echo -e "${GREEN}========= FULL DIOSCURI LOG =========${NOCOLOR}"
kubectl -n ${DIOSCURI_NS} logs $(kubectl get pods -n ${DIOSCURI_NS} --no-headers | awk '{print $1}') -c manager
}
tear_down () {
echo -e "${GREEN}============= TEAR DOWN =============${NOCOLOR}"
kind delete cluster --name ${KIND_NAME}
}
build_deploy_dioscuri () {
echo -e "${GREEN}==>${NOCOLOR} Build and deploy dioscuri"
# make docker-build IMG=${DIOSCURI_IMAGE}
# kind load docker-image ${DIOSCURI_IMAGE} --name ${KIND_NAME}
make deploy IMG=${DIOSCURI_IMAGE}
CHECK_COUNTER=1
echo -e "${GREEN}==>${NOCOLOR} Ensure dioscuri is running"
until $(kubectl get pods -n ${DIOSCURI_NS} --no-headers | grep -q "Running")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "dioscuri not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for dioscuri startup reached"
check_dioscuri_log
tear_down
exit 1
fi
done
}
echo -e "${GREEN}==>${NOCOLOR} Create dioscuri kind cluster"
# kind create cluster --image kindest/node:v1.21.1 --name ${KIND_NAME} --config test-resources/kind-cluster.yaml
# kubectl cluster-info --context kind-${KIND_NAME}
# kubectl config use-context kind-${KIND_NAME}
NUM_PODS=$(kubectl -n ingress-nginx get pods | grep -ow "Running"| wc -l | tr -d " ")
if [ $NUM_PODS -ne 1 ]; then
echo -e "${GREEN}===>${NOCOLOR} Install ingress-nginx"
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
kubectl create namespace ingress-nginx
helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 4.0.16
else
echo -e "${GREEN}===>${NOCOLOR} Ingress-nginx is installed"
fi
CHECK_COUNTER=1
echo -e "${GREEN}==>${NOCOLOR} Ensure ingress-nginx is running"
until $(kubectl get pods -n ingress-nginx --no-headers | grep -q "Running")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "ingress-nginx not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for ingress-nginx startup reached"
tear_down
exit 1
fi
done
build_deploy_dioscuri
echo -e "${GREEN}==>${NOCOLOR} Build and push nginx test images"
docker build -t amazeeio/nginx-test:ns1 -f test-resources/ns1.Dockerfile test-resources/
docker build -t amazeeio/nginx-test:ns2 -f test-resources/ns2.Dockerfile test-resources/
kind load docker-image amazeeio/nginx-test:ns1 --name ${KIND_NAME}
kind load docker-image amazeeio/nginx-test:ns2 --name ${KIND_NAME}
echo -e "${GREEN}==>${NOCOLOR} Install nginx test apps and associated ingress"
kubectl apply -f test-resources/test-ns1.yaml
kubectl apply -f test-resources/test-ns2.yaml
echo -e "${GREEN}==>${NOCOLOR} Testing ingress is in test-ns1"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1.localhost" http://localhost:8090/ | grep -q "test-ns1"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns1 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns1 not running"
curl -s -H "Host: test1.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Testing ingress is in test-ns2"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1-standby.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1-standby.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "test-ns2"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns2 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns2 not running"
curl -s -H "Host: test1-standby.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Get ingresses"
kubectl get ingress --all-namespaces
echo -e "${GREEN}==>${NOCOLOR} Run the migration"
kubectl apply -f test-resources/hostmigration-ns1.yaml
sleep 5
MIGRATION_CHECK_TIMEOUT=20
CHECK_COUNTER=1
until $(kubectl get hostmigration -n test-ns1 active-standby -o json | jq -r '.status.conditions[].type' | grep -q "completed")
do
if kubectl get hostmigration -n test-ns1 active-standby -o json | jq -r '.status.conditions[].type' | grep -q "failed"; then
kubectl get hostmigration -n test-ns1 active-standby -o yaml
tear_down
exit 1
fi
if [ $CHECK_COUNTER -lt $MIGRATION_CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "hostmigration not complete yet"
sleep 5
else
echo "Timeout of $MIGRATION_CHECK_TIMEOUT for hostmigration completion reached"
kubectl get hostmigration -n test-ns1 active-standby -o yaml
tear_down
exit 1
fi
done
echo -e "${GREEN}==>${NOCOLOR} Get ingresses"
kubectl get ingress --all-namespaces
echo -e "${GREEN}==>${NOCOLOR} Testing ingress moved to test-ns2"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1.localhost" http://localhost:8090/ | grep -q "test-ns2"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns2 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns2 not running"
curl -s -H "Host: test1.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Testing standby ingress moved to test-ns1"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1-standby.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1-standby.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "test-ns1"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns1 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns1 not running"
curl -s -H "Host: test1-standby.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Run the migration again to make sure they go back"
kubectl apply -f test-resources/hostmigration-ns2.yaml
sleep 5
MIGRATION_CHECK_TIMEOUT=20
CHECK_COUNTER=1
until $(kubectl get hostmigration -n test-ns2 active-standby -o json | jq -r '.status.conditions[].type' | grep -q "completed")
do
if kubectl get hostmigration -n test-ns2 active-standby -o json | jq -r '.status.conditions[].type' | grep -q "failed"; then
kubectl get hostmigration -n test-ns2 active-standby -o yaml
tear_down
exit 1
fi
if [ $CHECK_COUNTER -lt $MIGRATION_CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "hostmigration not complete yet"
sleep 5
else
echo "Timeout of $MIGRATION_CHECK_TIMEOUT for hostmigration completion reached"
kubectl get hostmigration -n test-ns1 active-standby -o yaml
tear_down
exit 1
fi
done
echo -e "${GREEN}==>${NOCOLOR} Get ingresses"
kubectl get ingress --all-namespaces
echo -e "${GREEN}==>${NOCOLOR} Testing ingress is in test-ns1"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1.localhost" http://localhost:8090/ | grep -q "test-ns1"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns1 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns1 not running"
curl -s -H "Host: test1.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Testing ingress is in test-ns2"
CHECK_COUNTER=1
until $(curl -s -I -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "200 OK")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "test1-standby.localhost not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for test1-standby.localhost startup reached"
tear_down
exit 1
fi
done
if curl -s -H "Host: test1-standby.localhost" http://localhost:8090/ | grep -q "test-ns2"; then
echo -e "${GREEN}===>${NOCOLOR} test-ns2 running"
else
echo -e "${YELLOW}===>${NOCOLOR} test-ns2 not running"
curl -s -H "Host: test1-standby.localhost" http://localhost:8090/
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Clean up"
tear_down