-
Notifications
You must be signed in to change notification settings - Fork 404
/
run-e2e-tests.sh
executable file
·140 lines (117 loc) · 5.46 KB
/
run-e2e-tests.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
#!/usr/bin/env bash
# Copyright 2020 The OpenYurt Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -x
set -e
set -u
YURT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)
source "${YURT_ROOT}/hack/lib/init.sh"
source "${YURT_ROOT}/hack/lib/build.sh"
readonly LOCAL_ARCH=$(go env GOHOSTARCH)
readonly LOCAL_OS=$(go env GOHOSTOS)
readonly YURT_E2E_TARGETS="test/e2e/yurt-e2e-test"
cloudNodeContainerName="openyurt-e2e-test-control-plane"
edgeNodeContainerName="openyurt-e2e-test-worker"
edgeNodeContainer2Name="openyurt-e2e-test-worker2"
KUBECONFIG=${KUBECONFIG:-${HOME}/.kube/config}
TARGET_PLATFORM=${TARGET_PLATFORMS:-linux/amd64}
ENABLE_AUTONOMY_TESTS=${ENABLE_AUTONOMY_TESTS:-true}
function set_flags() {
goldflags="${GOLDFLAGS:--s -w $(project_info)}"
gcflags="${GOGCFLAGS:-}"
goflags=${GOFLAGS:-}
# set kubeconfig
docker exec -d $edgeNodeContainerName /bin/bash -c 'mkdir /root/.kube/ -p'
docker exec -d $edgeNodeContainerName /bin/bash -c "echo 'export KUBECONFIG=/root/.kube/config' >> /etc/profile && source /etc/profile"
docker cp $KUBECONFIG $edgeNodeContainerName:/root/.kube/config
}
function cleanup {
rm -rf "$YURT_ROOT/test/e2e/e2e.test"
}
# install gingko
function get_ginkgo() {
go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4
}
function build_e2e_binary() {
echo "Begin to build e2e binary"
local goflags goldflags gcflags
goldflags="${GOLDFLAGS:--s -w $(project_info)}"
gcflags="${GOGCFLAGS:-}"
goflags=${GOFLAGS:-}
local arg
for arg; do
if [[ "${arg}" == -* ]]; then
# Assume arguments starting with a dash are flags to pass to go.
goflags+=("${arg}")
fi
done
ginkgo build $YURT_ROOT/test/e2e \
--gcflags "${gcflags:-}" ${goflags} --ldflags "${goldflags}"
}
# run e2e tests
function run_non_edge_autonomy_e2e_tests {
# check kubeconfig
if [ ! -f "${KUBECONFIG}" ]; then
echo "kubeconfig does not exist at ${KUBECONFIG}"
exit -1
fi
# run non-edge-autonomy-e2e-tests
cd $YURT_ROOT/test/e2e/
$YURT_ROOT/test/e2e/e2e.test e2e --ginkgo.label-filter='!edge-autonomy' --ginkgo.v
}
function run_e2e_edge_autonomy_tests {
# check kubeconfig
if [ ! -f "${KUBECONFIG}" ]; then
echo "kubeconfig does not exist at ${KUBECONFIG}"
exit -1
fi
# run edge-autonomy-e2e-tests
cd $YURT_ROOT/test/e2e/
$YURT_ROOT/test/e2e/e2e.test e2e --ginkgo.label-filter='edge-autonomy' --ginkgo.v
}
function prepare_autonomy_tests {
# run a nginx pod as static pod on each edge node
local nginxYamlPath="${YURT_ROOT}/test/e2e/yamls/nginx.yaml"
local nginxServiceYamlPath="${YURT_ROOT}/test/e2e/yamls/nginxService.yaml"
local staticPodPath="/etc/kubernetes/manifests/"
local POD_CREATE_TIMEOUT=240s
# create service for nginx pods
kubectl apply -f $nginxServiceYamlPath
docker cp $nginxYamlPath $edgeNodeContainerName:$staticPodPath
docker cp $nginxYamlPath $edgeNodeContainer2Name:$staticPodPath
# wait confirm that nginx is running
kubectl wait --for=condition=Ready pod/yurt-e2e-test-nginx-openyurt-e2e-test-worker --timeout=${POD_CREATE_TIMEOUT}
kubectl wait --for=condition=Ready pod/yurt-e2e-test-nginx-openyurt-e2e-test-worker2 --timeout=${POD_CREATE_TIMEOUT}
# set up dig in edge node1
# docker exec -t $edgeNodeContainerName /bin/bash -c "sed -i -r 's/([a-z]{2}.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainerName /bin/bash -c "sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainerName /bin/bash -c "sed -i -r 's/ports.ubuntu.com\/ubuntu-ports/old-releases.ubuntu.com\/ubuntu/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainerName /bin/bash -c "sed -i -r 's/old-releases.ubuntu.com\/ubuntu-ports/old-releases.ubuntu.com\/ubuntu/g' /etc/apt/sources.list"
docker exec -t $edgeNodeContainerName /bin/bash -c "apt-get update && apt-get install dnsutils -y"
# set up dig in edge node2
# docker exec -t $edgeNodeContainer2Name /bin/bash -c "sed -i -r 's/([a-z]{2}.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainer2Name /bin/bash -c "sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainer2Name /bin/bash -c "sed -i -r 's/ports.ubuntu.com\/ubuntu-ports/old-releases.ubuntu.com\/ubuntu/g' /etc/apt/sources.list"
# docker exec -t $edgeNodeContainer2Name /bin/bash -c "sed -i -r 's/old-releases.ubuntu.com\/ubuntu-ports/old-releases.ubuntu.com\/ubuntu/g' /etc/apt/sources.list"
docker exec -t $edgeNodeContainer2Name /bin/bash -c "apt-get update && apt-get install dnsutils -y"
}
GOOS=${LOCAL_OS} GOARCH=${LOCAL_ARCH} set_flags
cleanup
get_ginkgo
GOOS=${LOCAL_OS} GOARCH=${LOCAL_ARCH} build_e2e_binary
run_non_edge_autonomy_e2e_tests
if [ "$ENABLE_AUTONOMY_TESTS" = "true" ]; then
prepare_autonomy_tests
run_e2e_edge_autonomy_tests
fi