27
27
# See the License for the specific language governing permissions and
28
28
# limitations under the License.
29
29
30
- export ROOT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) /..
30
+ export ROOT_DIR=" $( dirname " $( dirname " $( readlink -fm " $0 " ) " ) " ) "
31
31
export LOG_LEVEL=3
32
- export CLEANUP_CLUSTER=${CLEANUP_CLUSTER:- 1 }
32
+ export CLEANUP_CLUSTER=${CLEANUP_CLUSTER:- " true " }
33
33
export CLUSTER_CONTEXT=" --name test"
34
34
# Using older image due to older version of kubernetes cluster"
35
- export IMAGE_NGINX=" nginx:1.15.12"
36
- export IMAGE_ECHOSERVER=" k8s.gcr.io/echoserver:1.4"
35
+ export IMAGE_ECHOSERVER=" kicbase/echo-server:1.0"
37
36
export KIND_OPT=${KIND_OPT:= " --config ${ROOT_DIR} /hack/e2e-kind-config.yaml" }
38
37
export KA_BIN=_output/bin
39
38
export WAIT_TIME=" 20s"
40
39
export IMAGE_REPOSITORY_MCAD=" ${1} "
41
40
export IMAGE_TAG_MCAD=" ${2} "
42
41
export MCAD_IMAGE_PULL_POLICY=" ${3-Always} "
43
42
export IMAGE_MCAD=" ${IMAGE_REPOSITORY_MCAD} :${IMAGE_TAG_MCAD} "
43
+ CLUSTER_STARTED=" false"
44
44
45
45
function update_test_host {
46
46
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
@@ -54,7 +54,7 @@ function update_test_host {
54
54
sudo curl -o /usr/local/bin/kind -L https://github.com/kubernetes-sigs/kind/releases/download/v0.11.0/kind-linux-amd64
55
55
sudo chmod +x /usr/local/bin/kind
56
56
57
- # Installing helm3
57
+ # Installing helm3
58
58
curl -fsSL -o ${ROOT_DIR} /get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
59
59
chmod 700 ${ROOT_DIR} /get_helm.sh
60
60
${ROOT_DIR} /get_helm.sh
@@ -65,19 +65,19 @@ function update_test_host {
65
65
function check-prerequisites {
66
66
echo " checking prerequisites"
67
67
which kind > /dev/null 2>&1
68
- if [[ $? -ne 0 ] ]; then
68
+ if [ $? -ne 0 ]; then
69
69
echo " kind not installed, exiting."
70
70
exit 1
71
71
else
72
72
echo -n " found kind, version: " && kind version
73
73
fi
74
74
75
75
which kubectl > /dev/null 2>&1
76
- if [[ $? -ne 0 ] ]; then
76
+ if [ $? -ne 0 ]; then
77
77
echo " kubectl not installed, exiting."
78
78
exit 1
79
79
else
80
- echo -n " found kubectl, " && kubectl version --short --client
80
+ echo -n " found kubectl, " && kubectl version
81
81
fi
82
82
83
83
if [[ $IMAGE_REPOSITORY_MCAD == " " ]]
@@ -93,7 +93,7 @@ function check-prerequisites {
93
93
fi
94
94
95
95
which helm > /dev/null 2>&1
96
- if [[ $? -ne 0 ] ]
96
+ if [ $? -ne 0 ]
97
97
then
98
98
echo " helm not installed, exiting."
99
99
exit 1
@@ -106,43 +106,44 @@ function check-prerequisites {
106
106
function kind-up-cluster {
107
107
echo " Running kind: [kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT} ]"
108
108
kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT} --wait ${WAIT_TIME}
109
+ if [ $? -ne 0 ]
110
+ then
111
+ echo " Failed to start kind cluster"
112
+ exit 1
113
+ fi
114
+ CLUSTER_STARTED=" true"
109
115
110
- docker images
111
116
docker pull ${IMAGE_ECHOSERVER}
112
- docker pull ${IMAGE_NGINX}
113
117
if [[ " $MCAD_IMAGE_PULL_POLICY " = " Always" ]]
114
118
then
115
119
docker pull ${IMAGE_MCAD}
116
120
fi
117
121
docker images
118
-
119
- kind load docker-image ${IMAGE_NGINX} ${CLUSTER_CONTEXT}
120
- if [[ $? -ne 0 ]]
121
- then
122
- echo " Failed to load image ${IMAGE_NGINX} in cluster"
123
- exit 1
124
- fi
125
-
122
+
126
123
kind load docker-image ${IMAGE_ECHOSERVER} ${CLUSTER_CONTEXT}
127
- if [[ $? -ne 0 ] ]
124
+ if [ $? -ne 0 ]
128
125
then
129
126
echo " Failed to load image ${IMAGE_ECHOSERVER} in cluster"
130
127
exit 1
131
128
fi
132
129
133
130
kind load docker-image ${IMAGE_MCAD} ${CLUSTER_CONTEXT}
134
- if [[ $? -ne 0 ] ]
131
+ if [ $? -ne 0 ]
135
132
then
136
133
echo " Failed to load image ${IMAGE_MCAD} in cluster"
137
134
exit 1
138
- fi
135
+ fi
139
136
}
140
137
141
138
# clean up
142
139
function cleanup {
143
140
echo " ==========================>>>>> Cleaning up... <<<<<=========================="
144
141
echo " "
145
-
142
+ if [[ ${CLUSTER_STARTED} == " false" ]]
143
+ then
144
+ echo " Cluster was not started, nothing more to do."
145
+ return
146
+ fi
146
147
147
148
echo " Custom Resource Definitions..."
148
149
echo " kubectl get crds"
@@ -185,8 +186,13 @@ function cleanup {
185
186
echo " kubectl logs ${mcad_pod} -n kube-system"
186
187
kubectl logs ${mcad_pod} -n kube-system
187
188
fi
188
- kind delete cluster ${CLUSTER_CONTEXT}
189
189
rm -rf ${ROOT_DIR} /get_helm.sh
190
+ if [[ $CLEANUP_CLUSTER == " true" ]]
191
+ then
192
+ kind delete cluster ${CLUSTER_CONTEXT}
193
+ else
194
+ echo " Cluster requested to stay up, not deleting cluster"
195
+ fi
190
196
}
191
197
192
198
debug_function () {
@@ -231,7 +237,7 @@ spec:
231
237
spec:
232
238
containers:
233
239
- name: hellodiana-2-test-0
234
- image: k8s.gcr.io/echoserver:1.4
240
+ image: ${IMAGE_ECHOSERVER}
235
241
imagePullPolicy: Always
236
242
ports:
237
243
- containerPort: 80
287
293
}
288
294
289
295
function kube-test-env-up {
290
- cd ${ROOT_DIR}
291
-
296
+
292
297
echo " ---"
293
298
export KUBECONFIG=" $( kind get kubeconfig-path ${CLUSTER_CONTEXT} ) "
294
299
@@ -384,6 +389,4 @@ kind-up-cluster
384
389
kube-test-env-up
385
390
386
391
echo " ==========================>>>>> Running E2E tests... <<<<<=========================="
387
- go test ./test/e2e -v -timeout 55m
388
- debug_function
389
- sleep 3600s
392
+ go test ./test/e2e -v -timeout 55m
0 commit comments