-
Notifications
You must be signed in to change notification settings - Fork 346
/
test-e2e-kind.sh
executable file
·247 lines (223 loc) · 7.48 KB
/
test-e2e-kind.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
#!/usr/bin/env bash
# Copyright 2020 Antrea 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.
# The script runs kind e2e tests with different traffic encapsulation modes.
set -eo pipefail
function echoerr {
>&2 echo "$@"
}
_usage="Usage: $0 [--encap-mode <mode>] [--ip-family <v4|v6>] [--no-proxy] [--np] [--coverage] [--help|-h]
--encap-mode Traffic encapsulation mode. (default is 'encap').
--ip-family Configures the ipFamily for the KinD cluster.
--no-proxy Disables Antrea proxy.
--proxy-all Enables Antrea proxy with all Service support.
--endpointslice Enables Antrea proxy and EndpointSlice support.
--no-np Disables Antrea-native policies.
--skip A comma-separated list of keywords, with which tests should be skipped.
--coverage Enables measure Antrea code coverage when run e2e tests on kind.
--setup-only Only perform setting up the cluster and run test.
--cleanup-only Only perform cleaning up the cluster.
--test-only Only run test on current cluster. Not set up/clean up the cluster.
--help, -h Print this message and exit.
"
function print_usage {
echoerr -n "$_usage"
}
TESTBED_CMD=$(dirname $0)"/kind-setup.sh"
YML_CMD=$(dirname $0)"/../../hack/generate-manifest.sh"
FLOWAGGREGATOR_YML_CMD=$(dirname $0)"/../../hack/generate-manifest-flow-aggregator.sh"
function quit {
result=$?
if [[ $setup_only || $test_only ]]; then
exit $result
fi
echoerr "Cleaning testbed"
$TESTBED_CMD destroy kind
}
mode=""
ipfamily="v4"
proxy=true
proxy_all=false
endpointslice=false
np=true
coverage=false
skiplist=""
setup_only=false
cleanup_only=false
test_only=false
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--no-proxy)
proxy=false
shift
;;
--proxy-all)
proxy_all=true
shift
;;
--ip-family)
ipfamily="$2"
shift 2
;;
--endpointslice)
endpointslice=true
shift
;;
--no-np)
np=false
shift
;;
--skip)
skiplist="$2"
shift 2
;;
--encap-mode)
mode="$2"
shift 2
;;
--coverage)
coverage=true
shift
;;
--setup-only)
setup_only=true
shift
;;
--cleanup-only)
cleanup_only=true
shift
;;
--test-only)
test_only=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*) # unknown option
echoerr "Unknown option $1"
exit 1
;;
esac
done
if [[ $cleanup_only == "true" ]];then
$TESTBED_CMD destroy kind
exit 0
fi
trap "quit" INT EXIT
manifest_args=""
if ! $proxy; then
manifest_args="$manifest_args --no-proxy"
fi
if $proxy_all; then
if ! $proxy; then
echoerr "--proxy-all requires AntreaProxy, so it cannot be used with --no-proxy"
exit 1
fi
manifest_args="$manifest_args --proxy-all"
fi
if $endpointslice; then
manifest_args="$manifest_args --endpointslice"
fi
if ! $np; then
manifest_args="$manifest_args --no-np"
fi
COMMON_IMAGES_LIST=("k8s.gcr.io/e2e-test-images/agnhost:2.29" \
"projects.registry.vmware.com/library/busybox" \
"projects.registry.vmware.com/antrea/nginx:1.21.6-alpine" \
"projects.registry.vmware.com/antrea/perftool" \
"projects.registry.vmware.com/antrea/ipfix-collector:v0.5.12")
for image in "${COMMON_IMAGES_LIST[@]}"; do
for i in `seq 3`; do
docker pull $image && break
sleep 1
done
done
if $coverage; then
manifest_args="$manifest_args --coverage"
COMMON_IMAGES_LIST+=("antrea/antrea-ubuntu-coverage:latest")
COMMON_IMAGES_LIST+=("antrea/flow-aggregator-coverage:latest")
else
COMMON_IMAGES_LIST+=("projects.registry.vmware.com/antrea/antrea-ubuntu:latest")
COMMON_IMAGES_LIST+=("projects.registry.vmware.com/antrea/flow-aggregator:latest")
fi
if $proxy_all; then
COMMON_IMAGES_LIST+=("k8s.gcr.io/echoserver:1.10")
fi
printf -v COMMON_IMAGES "%s " "${COMMON_IMAGES_LIST[@]}"
function setup_cluster {
args=$1
if [[ "$ipfamily" == "v6" ]]; then
args="$args --ip-family ipv6 --pod-cidr fd00:10:244::/56"
elif [[ "$ipfamily" != "v4" ]]; then
echoerr "invalid value for --ip-family \"$ipfamily\", expected \"v4\" or \"v6\""
exit 1
fi
if $proxy_all; then
args="$args --no-kube-proxy"
fi
echo "creating test bed with args $args"
eval "timeout 600 $TESTBED_CMD create kind $args"
}
function run_test {
current_mode=$1
if $coverage; then
$YML_CMD --encap-mode $current_mode $manifest_args | docker exec -i kind-control-plane dd of=/root/antrea-coverage.yml
$YML_CMD --ipsec $manifest_args | docker exec -i kind-control-plane dd of=/root/antrea-ipsec-coverage.yml
$FLOWAGGREGATOR_YML_CMD --coverage | docker exec -i kind-control-plane dd of=/root/flow-aggregator-coverage.yml
else
$YML_CMD --encap-mode $current_mode $manifest_args | docker exec -i kind-control-plane dd of=/root/antrea.yml
$YML_CMD --ipsec $manifest_args | docker exec -i kind-control-plane dd of=/root/antrea-ipsec.yml
$FLOWAGGREGATOR_YML_CMD | docker exec -i kind-control-plane dd of=/root/flow-aggregator.yml
fi
if $proxy_all; then
apiserver=$(docker exec -i kind-control-plane kubectl get endpoints kubernetes --no-headers | awk '{print $2}')
if $coverage; then
docker exec -i kind-control-plane sed -i.bak -E "s/^[[:space:]]*[#]?kubeAPIServerOverride[[:space:]]*:[[:space:]]*[a-z\"]+[[:space:]]*$/ kubeAPIServerOverride: \"$apiserver\"/" /root/antrea-coverage.yml /root/antrea-ipsec-coverage.yml
else
docker exec -i kind-control-plane sed -i.bak -E "s/^[[:space:]]*[#]?kubeAPIServerOverride[[:space:]]*:[[:space:]]*[a-z\"]+[[:space:]]*$/ kubeAPIServerOverride: \"$apiserver\"/" /root/antrea.yml /root/antrea-ipsec.yml
fi
fi
sleep 1
if $coverage; then
go test -v -timeout=80m -run=TestTraceflow/testTraceflowInterNode/traceflowGroupTest/interNodeTraceflowIPv4 antrea.io/antrea/test/e2e -provider=kind --logs-export-dir=$ANTREA_LOG_DIR --coverage --coverage-dir $ANTREA_COV_DIR --skip=$skiplist
else
go test -v -timeout=75m antrea.io/antrea/test/e2e -provider=kind --logs-export-dir=$ANTREA_LOG_DIR --skip=$skiplist
fi
}
if [[ "$mode" == "" ]] || [[ "$mode" == "encap" ]]; then
echo "======== Test encap mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--images \"$COMMON_IMAGES\""
fi
run_test encap
fi
if [[ "$mode" == "" ]] || [[ "$mode" == "noEncap" ]]; then
echo "======== Test noencap mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--images \"$COMMON_IMAGES\""
fi
run_test noEncap
fi
if [[ "$mode" == "" ]] || [[ "$mode" == "hybrid" ]]; then
echo "======== Test hybrid mode =========="
if [[ $test_only == "false" ]];then
setup_cluster "--subnets \"20.20.20.0/24\" --images \"$COMMON_IMAGES\""
fi
run_test hybrid
fi
exit 0