-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontroller-test.sh
executable file
·120 lines (113 loc) · 4.9 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
#!/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'
KIND_NAME=chart-testing
# echo -e "${GREEN}Create aergia kind cluster${NOCOLOR}"
# kind create cluster --image kindest/node:v1.21.1 --name aergia --config test-resources/kind-cluster.yaml
# kubectl cluster-info --context kind-aergia
# kubectl config use-context kind-aergia
tear_down () {
echo -e "${GREEN}============= TEAR DOWN =============${NOCOLOR}"
kubectl -n aergia-backend logs $(kubectl get pods -n aergia-backend --no-headers | awk '{print $1}') -c manager
kubectl get pods --all-namespaces
kind delete cluster --name ${KIND_NAME}
}
echo -e "${GREEN}Install custom backend handler${NOCOLOR}"
kubectl apply -f test-resources/aergia-backend.yaml
NUM_PODS=$(kubectl -n ingress-nginx get pods | grep -ow "Running"| wc -l | tr -d " ")
if [ $NUM_PODS -ne 1 ]; then
echo -e "${GREEN}Install ingress-nginx${NOCOLOR}"
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
kubectl create namespace ingress-nginx
## Pinning to 3.36.0 whilst https://github.com/kubernetes/ingress-nginx/releases/tag/controller-v1.0.0 is an issue
helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 4.0.16
kubectl get pods --all-namespaces
echo -e "${GREEN}Wait for ingress-nginx to become ready${NOCOLOR}"
sleep 60
else
echo -e "${GREEN}Ingress-nginx is ready${NOCOLOR}"
fi
echo -e "${GREEN}Install example-nginx app with 0 replicas set${NOCOLOR}"
kubectl apply -f test-resources/example-nginx.yaml
sleep 15
echo -e "${GREEN}Check there are no example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 503)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "503 Service"; then
sleep 15
echo -e "${GREEN}Check there are 3 example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 200)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "200 OK"; then
echo -e "${GREEN}Unidled${NOCOLOR}"
else
echo -e "${RED}Curl did not return 200${NOCOLOR}"
tear_down
exit 1
fi
else
echo -e "${RED}Curl did not return 503${NOCOLOR}"
tear_down
exit 1
fi
echo -e "${GREEN}Check that force-idle label idles an environment${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 200)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "200 OK"; then
kubectl patch namespace example-nginx --type=merge --patch '{"metadata":{"labels":{"idling.amazee.io/force-idled":"true"}}}'
sleep 15
echo -e "${GREEN}Check there are 0 example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 503)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "503 Service"; then
sleep 15
echo -e "${GREEN}Check there are 3 example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 200)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "200 OK"; then
echo -e "${GREEN}Unidled${NOCOLOR}"
else
echo -e "${RED}Curl did not return 200${NOCOLOR}"
tear_down
exit 1
fi
else
echo -e "${RED}Curl did not return 503${NOCOLOR}"
tear_down
exit 1
fi
else
echo -e "${RED}Curl did not return 503${NOCOLOR}"
tear_down
exit 1
fi
echo -e "${GREEN}Check that an idled environment can be unidled by label${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 200)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "200 OK"; then
kubectl patch namespace example-nginx --type=merge --patch '{"metadata":{"labels":{"idling.amazee.io/force-idled":"true"}}}'
sleep 15
echo -e "${GREEN}Check there are 0 example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
kubectl patch namespace example-nginx --type=merge --patch '{"metadata":{"labels":{"idling.amazee.io/unidle":"true"}}}'
sleep 15
echo -e "${GREEN}Check there are 3 example-nginx pods${NOCOLOR}"
kubectl -n example-nginx get pods
echo -e "${GREEN}Request example-nginx app (should be 200)${NOCOLOR}"
if curl -s -I -H "Host: aergia.localhost" http://localhost:8090/| grep -q "200 OK"; then
echo -e "${GREEN}Unidled${NOCOLOR}"
else
echo -e "${RED}Curl did not return 200${NOCOLOR}"
tear_down
exit 1
fi
else
echo -e "${RED}Curl did not return 503${NOCOLOR}"
tear_down
exit 1
fi
tear_down