forked from oliviabarrick/flux-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration-test.sh
executable file
·133 lines (98 loc) · 3.86 KB
/
integration-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
#!/bin/bash
set -e
echo "$SSH_KEY" > /tmp/ssh_key
function cr {
BRANCH="${DRONE_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}"
sed "s#gitBranch: master#gitBranch: $BRANCH#g" $1
}
# return 1 if the command returns 0, otherwise return 0
function not {
! $@
}
# wait for up to $1 seconds for some command to return true
function wait_for {
set +x
set +e
max_tries=$1
count=0
ret=1
while [ $count -lt $max_tries ] && [ $ret -ne 0 ]; do
${@:2}
ret=$?
sleep 1
count=$(($count + 1))
done
set -e
set -x
return $ret
}
# clean up resources
function cleanup {
set +e
kubectl get all
echo Clean up helm and testing resources before exiting
cr deploy/cr-namespaced.yaml |kubectl delete -f -
cr deploy/cr-cluster.yaml |kubectl delete -f -
kubectl delete -f deploy/
kubectl delete secrets --all
kubectl delete configmaps --all
kubectl delete statefulsets --all
kubectl delete deployments --all
kubectl delete services --all
kubectl delete namespace lol
}
trap cleanup EXIT
set -x
MAXIMUM_TIMEOUT=600
echo Waiting for docker.
wait_for $MAXIMUM_TIMEOUT docker ps
echo Building Docker image.
docker build -t justinbarrick/flux-operator:latest .
echo Creating Flux resources.
kubectl create namespace lol
kubectl create secret generic flux-git-example-deploy --from-file=identity=/tmp/ssh_key
./fluxopctl |kubectl apply -f -
cr deploy/cr-namespaced.yaml | kubectl apply -f -
kubectl get deployments
kubectl get pods
echo Waiting for Flux to start up.
echo Confirming that all expected resources exist
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-example
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-example-memcached
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-operator
wait_for $MAXIMUM_TIMEOUT kubectl get fluxhelmreleases memcached
kubectl logs $(kubectl get pods -l name=flux -o 'go-template={{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}' |head -n1)
wait_for $MAXIMUM_TIMEOUT kubectl get deployment nginx
not kubectl get deployment -n lol nginx2
echo Enabling the helm-operator
cr deploy/cr-namespaced.yaml |sed 's/enabled: false/enabled: true/g' \
|sed 's/k8s-namespace-whitelist: default/k8s-namespace-whitelist: ""/g' |kubectl apply -f -
echo Waiting for helm-operator and tiller to start.
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-example-fluxcloud
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-example-helm-operator
wait_for $MAXIMUM_TIMEOUT kubectl get deployment flux-example-tiller-deploy
echo Waiting for flux to create resources.
wait_for $MAXIMUM_TIMEOUT kubectl get deployment -n lol nginx2
echo Waiting for helm-operator to create resources.
wait_for $MAXIMUM_TIMEOUT kubectl get statefulset memcached-memcached
echo Disabling helm-operator
cr deploy/cr-namespaced.yaml |kubectl apply -f -
echo Waiting for helm-operator to go away.
wait_for $MAXIMUM_TIMEOUT not kubectl get deployment flux-example-helm-operator
cr deploy/cr-namespaced.yaml |kubectl delete -f -
./fluxopctl |kubectl delete -f -
kubectl delete deployment nginx
echo Waiting for resources to clean up
wait_for $MAXIMUM_TIMEOUT not kubectl get deployment flux-operator
wait_for $MAXIMUM_TIMEOUT not kubectl get deployment flux-example
wait_for $MAXIMUM_TIMEOUT not kubectl get deployment flux-example-memcached
wait_for $MAXIMUM_TIMEOUT not kubectl get deployment flux-example-tiller-deploy
echo Starting cluster scoped flux
./fluxopctl -cluster |kubectl apply -f -
cr deploy/cr-cluster.yaml | kubectl apply -f -
wait_for $MAXIMUM_TIMEOUT kubectl get deployment nginx
wait_for $MAXIMUM_TIMEOUT kubectl get deployment -n lol nginx2
kubectl delete secret flux-git-example-deploy
echo "######################################################"
echo "############## Exiting with success! #################"
echo "######################################################"