forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-k8s-e2e-tests.sh
executable file
·266 lines (235 loc) · 8.93 KB
/
run-k8s-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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/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.
# ERR trap is inherited by shell functions
set -E
# Possible exit codes are 0 (all tests pass), 1 (all tests were run, but at least one failed) and 2
# (internal error when running tests, not a test failure).
trap 'exit 2' ERR
function echoerr {
>&2 echo "$@"
}
RUN_CONFORMANCE=false
RUN_WHOLE_CONFORMANCE=false
RUN_NETWORK_POLICY=false
RUN_SIG_NETWORK=false
RUN_E2E_FOCUS=""
RUN_E2E_SKIP=""
KUBECONFIG_OPTION=""
DEFAULT_E2E_CONFORMANCE_FOCUS="\[Conformance\]"
DEFAULT_E2E_CONFORMANCE_SKIP="\[Slow\]|\[Serial\]|\[Disruptive\]|\[Flaky\]|\[Feature:.+\]|\[sig-cli\]|\[sig-storage\]|\[sig-auth\]|\[sig-api-machinery\]|\[sig-apps\]|\[sig-node\]|\[sig-instrumentation\]"
DEFAULT_E2E_NETWORKPOLICY_FOCUS="\[Feature:NetworkPolicy\]"
DEFAULT_E2E_NETWORKPOLICY_SKIP="NetworkPolicyLegacy"
DEFAULT_E2E_SIG_NETWORK_FOCUS="\[sig-network\]"
DEFAULT_E2E_SIG_NETWORK_SKIP="\[Slow\]|\[Serial\]|\[Disruptive\]|\[GCE\]|\[Feature:.+\]|\[Feature:IPv6DualStack\]|\[Feature:IPv6DualStackAlphaFeature\]|should create pod that uses dns|should provide Internet connection for containers"
MODE="report"
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
KUBE_CONFORMANCE_IMAGE_VERSION_OPTION=""
IMAGE_PULL_POLICY="Always"
CONFORMANCE_IMAGE_CONFIG_PATH="${THIS_DIR}/conformance-image-config.yaml"
SONOBUOY_IMAGE="antrea/sonobuoy:v0.56.16"
SYSTEMD_LOGS_IMAGE="antrea/systemd-logs:v0.4"
_usage="Usage: $0 [--e2e-conformance] [--e2e-network-policy] [--e2e-focus <TestRegex>] [--e2e-skip <SkipRegex>]
[--kubeconfig <Kubeconfig>] [--kubernetes-version <ConformanceImageVersion>]
[--log-mode <SonobuoyResultLogLevel>]
Run the K8s e2e community tests (Conformance & Network Policy) which are relevant to Project Antrea,
using the sonobuoy tool. Possible exit codes are 0 (all tests pass), 1 (all tests were run, but at
least one failed) and 2 (internal error when running tests, not a test failure).
--e2e-conformance Run Conformance tests.
--e2e-whole-conformance Run whole Conformance tests.
--e2e-network-policy Run Network Policy tests.
--e2e-sig-network Run sig-network tests.
--e2e-all Run whole Conformance, Network Policy, and sig-network tests.
--e2e-focus TestRegex Run only tests matching a specific regex, this is useful to run a single tests for example.
--e2e-skip TestRegex Skip some tests matching a specific regex.
--kubeconfig Kubeconfig Explicit path to Kubeconfig file. You may also set the KUBECONFIG environment variable.
--kubernetes-version ConformanceImageVersion Use specific version of the Conformance tests container image. Default is $KUBE_CONFORMANCE_IMAGE_VERSION.
--log-mode Use the flag to set either 'report', 'detail', or 'dump' level data for sonobuoy results.
--image-pull-policy The ImagePullPolicy Sonobuoy should use for the aggregators and workers. (default Always)
--sonobuoy-image SonobuoyImage Sonobuoy image to use. Default is $SONOBUOY_IMAGE.
--help, -h Print this message and exit
This tool uses sonobuoy (https://github.com/vmware-tanzu/sonobuoy) to run the K8s e2e community
tests which are relevant to Antrea. You can set the SONOBUOY environment variable to the path of the
sonobuoy binary you want to use. Otherwise we will look for sonobuoy in your PATH. If we cannot find
sonobuoy there, we will try to install it."
function print_usage {
echoerr "$_usage"
}
function print_help {
echoerr "Try '$0 --help' for more information."
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--kubeconfig)
KUBECONFIG_OPTION="--kubeconfig $2"
shift 2
;;
--kubernetes-version)
KUBE_CONFORMANCE_IMAGE_VERSION_OPTION="--kubernetes-version $2"
shift 2
;;
--e2e-conformance)
RUN_CONFORMANCE=true
shift
;;
--e2e-whole-conformance)
RUN_WHOLE_CONFORMANCE=true
shift
;;
--e2e-network-policy)
RUN_NETWORK_POLICY=true
shift
;;
--e2e-sig-network)
RUN_SIG_NETWORK=true
shift
;;
--e2e-all)
RUN_WHOLE_CONFORMANCE=true
RUN_NETWORK_POLICY=true
RUN_SIG_NETWORK=true
shift
;;
--e2e-focus)
RUN_E2E_FOCUS="$2"
shift 2
;;
--e2e-skip)
RUN_E2E_SKIP="$2"
shift 2
;;
--log-mode)
MODE="$2"
shift 2
;;
--image-pull-policy)
IMAGE_PULL_POLICY="$2"
shift 2
;;
--sonobuoy-image)
SONOBUOY_IMAGE="$2"
shift 2
;;
--systemd-logs-image)
SYSTEMD_LOGS_IMAGE="$2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*) # unknown option
echoerr "Unknown option $1"
exit 1
;;
esac
done
source $THIS_DIR/verify-sonobuoy.sh
if [ -z "$SONOBUOY" ]; then
SONOBUOY="$(verify_sonobuoy)"
elif ! $SONOBUOY version > /dev/null 2>&1; then
echoerr "$SONOBUOY does not appear to be a valid sonobuoy binary"
print_help
exit 1
fi
echoerr "Using this sonobuoy: $SONOBUOY"
# Incremented by 1 for every sonobuoy run invocation with at least one failed test
errors=0
function run_sonobuoy() {
local focus_regex="$1"
local skip_regex="$2"
$SONOBUOY delete --wait=10 $KUBECONFIG_OPTION
echo "Running tests with sonobuoy. While test is running, check logs with: $SONOBUOY $KUBECONFIG_OPTION logs -f."
set -x
if [[ "$focus_regex" == "" && "$skip_regex" == "" ]]; then
$SONOBUOY run --wait \
$KUBECONFIG_OPTION \
$KUBE_CONFORMANCE_IMAGE_VERSION_OPTION \
--mode "certified-conformance" --image-pull-policy ${IMAGE_PULL_POLICY} \
--sonobuoy-image ${SONOBUOY_IMAGE} --systemd-logs-image ${SYSTEMD_LOGS_IMAGE} --e2e-repo-config ${CONFORMANCE_IMAGE_CONFIG_PATH}
else
$SONOBUOY run --wait \
$KUBECONFIG_OPTION \
--e2e-parallel=true \
$KUBE_CONFORMANCE_IMAGE_VERSION_OPTION \
--e2e-focus "$focus_regex" --e2e-skip "$skip_regex" --image-pull-policy ${IMAGE_PULL_POLICY} \
--sonobuoy-image ${SONOBUOY_IMAGE} --systemd-logs-image ${SYSTEMD_LOGS_IMAGE} --e2e-repo-config ${CONFORMANCE_IMAGE_CONFIG_PATH}
fi
set +x
results_path=$($SONOBUOY retrieve $KUBECONFIG_OPTION)
results=$($SONOBUOY results $results_path --mode=$MODE)
echo "$results"
if grep -Fxq "Failed tests:" <<< "$results"; then
errors=$((errors+1))
fi
}
function run_conformance() {
local e2e_skip="${DEFAULT_E2E_CONFORMANCE_SKIP}"
if [[ "$RUN_E2E_FOCUS" != "" ]]; then
echo "It is not allowed to specify focus when running conformance tests"
exit 1
fi
if [[ "$RUN_E2E_SKIP" != "" ]]; then
e2e_skip="$RUN_E2E_SKIP"
fi
run_sonobuoy "${DEFAULT_E2E_CONFORMANCE_FOCUS}" "${e2e_skip}"
}
function run_whole_conformance() {
run_sonobuoy "" ""
}
function run_network_policy() {
local e2e_skip="${DEFAULT_E2E_NETWORKPOLICY_SKIP}"
if [[ "$RUN_E2E_FOCUS" != "" ]]; then
echo "It is not allowed to specify focus when running network policy tests"
exit 1
fi
if [[ "$RUN_E2E_SKIP" != "" ]]; then
e2e_skip="$RUN_E2E_SKIP"
fi
run_sonobuoy "${DEFAULT_E2E_NETWORKPOLICY_FOCUS}" "${e2e_skip}"
}
function run_sig_network() {
local e2e_skip="${DEFAULT_E2E_SIG_NETWORK_SKIP}"
if [[ "$RUN_E2E_FOCUS" != "" ]]; then
echo "It is not allowed to specify focus when running sig-network tests"
exit 1
fi
if [[ "$RUN_E2E_SKIP" != "" ]]; then
e2e_skip="$RUN_E2E_SKIP"
fi
run_sonobuoy "${DEFAULT_E2E_SIG_NETWORK_FOCUS}" "${e2e_skip}"
}
if [[ "$RUN_E2E_FOCUS" != "" ]]; then
run_sonobuoy "$RUN_E2E_FOCUS" "$RUN_E2E_SKIP"
fi
if $RUN_CONFORMANCE; then
run_conformance
fi
if $RUN_WHOLE_CONFORMANCE; then
run_whole_conformance
fi
if $RUN_NETWORK_POLICY; then
run_network_policy
fi
if $RUN_SIG_NETWORK; then
run_sig_network
fi
echoerr "Deleting sonobuoy resources"
$SONOBUOY delete --wait=10 $KUBECONFIG_OPTION
if [[ $errors -ne 0 ]]; then
exit 1
fi
exit 0