@@ -34,6 +34,8 @@ EAST_CLUSTER_CONFIG="--kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH/east"
3434WEST_CLUSTER_CONFIG=" --kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH /west"
3535ENABLE_MC_GATEWAY=false
3636IS_CONTAINERD=false
37+ CODECOV_TOKEN=" "
38+ COVERAGE=false
3739
3840multicluster_kubeconfigs=($EAST_CLUSTER_CONFIG $LEADER_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG )
3941membercluster_kubeconfigs=($EAST_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG )
@@ -42,15 +44,17 @@ membercluster_kubeconfigs=($EAST_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG)
4244CLEAN_STALE_IMAGES=" docker system prune --force --all --filter until=48h"
4345
4446_usage=" Usage: $0 [--kubeconfigs-path <KubeconfigSavePath>] [--workdir <HomePath>]
45- [--testcase <e2e>] [--mc-gateway]
47+ [--testcase <e2e>] [--mc-gateway] [--codecov-token] [--coverage]
4648
4749Run Antrea multi-cluster e2e tests on a remote (Jenkins) Linux Cluster Set.
4850
4951 --kubeconfigs-path Path of cluster set kubeconfigs.
5052 --workdir Home path for Go, vSphere information and antrea_logs during cluster setup. Default is $WORKDIR .
5153 --testcase Antrea multi-cluster e2e test cases on a Linux cluster set.
5254 --registry The docker registry to use instead of dockerhub.
53- --mc-gateway Enable Multicluster Gateway."
55+ --mc-gateway Enable Multicluster Gateway.
56+ --codecov-token Token used to upload coverage report(s) to Codecov.
57+ --coverage Run e2e with coverage."
5458
5559function print_usage {
5660 echoerr " $_usage "
@@ -82,6 +86,14 @@ case $key in
8286 ENABLE_MC_GATEWAY=true
8387 shift
8488 ;;
89+ --codecov-token)
90+ CODECOV_TOKEN=" $2 "
91+ shift 2
92+ ;;
93+ --coverage)
94+ COVERAGE=true
95+ shift
96+ ;;
8597 -h|--help)
8698 print_usage
8799 exit 0
@@ -161,10 +173,9 @@ function wait_for_antrea_multicluster_pods_ready {
161173function wait_for_multicluster_controller_ready {
162174 echo " ====== Deploying Antrea Multicluster Leader Cluster with ${LEADER_CLUSTER_CONFIG} ======"
163175 kubectl create ns antrea-multicluster " ${LEADER_CLUSTER_CONFIG} " || true
164- kubectl apply -f ./multicluster/test/yamls/manifest.yml " ${LEADER_CLUSTER_CONFIG} "
165176 kubectl apply -f ./multicluster/build/yamls/antrea-multicluster-leader-global.yml " ${LEADER_CLUSTER_CONFIG} "
177+ kubectl apply -f ./multicluster/test/yamls/leader-manifest.yml " ${LEADER_CLUSTER_CONFIG} "
166178 kubectl rollout status deployment/antrea-mc-controller -n antrea-multicluster " ${LEADER_CLUSTER_CONFIG} " || true
167- kubectl apply -f ./multicluster/test/yamls/manifest.yml " ${LEADER_CLUSTER_CONFIG} "
168179 kubectl create -f ./multicluster/test/yamls/leader-access-token-secret.yml " ${LEADER_CLUSTER_CONFIG} " || true
169180 kubectl get secret -n antrea-multicluster leader-access-token " ${LEADER_CLUSTER_CONFIG} " -o yaml > ./multicluster/test/yamls/leader-access-token.yml
170181
@@ -180,7 +191,7 @@ function wait_for_multicluster_controller_ready {
180191 for config in " ${membercluster_kubeconfigs[@]} " ;
181192 do
182193 echo " ====== Deploying Antrea Multicluster Member Cluster with ${config} ======"
183- kubectl apply -f ./multicluster/build /yamls/antrea-multicluster- member.yml ${config}
194+ kubectl apply -f ./multicluster/test /yamls/member-manifest .yml ${config}
184195 kubectl rollout status deployment/antrea-mc-controller -n kube-system ${config}
185196 kubectl apply -f ./multicluster/test/yamls/leader-access-token.yml ${config}
186197 done
@@ -191,6 +202,34 @@ function wait_for_multicluster_controller_ready {
191202 kubectl apply -f ./multicluster/test/yamls/clusterset.yml " ${LEADER_CLUSTER_CONFIG} "
192203}
193204
205+ # We run the function in a subshell with "set -e" to ensure that it exits in
206+ # case of error (e.g. integrity check), no matter the context in which the
207+ # function is called.
208+ function run_codecov { (set -e
209+ flag=$1
210+ file=$2
211+ dir=$3
212+
213+ rm -f trustedkeys.gpg codecov
214+ # This is supposed to be a one-time step, but there should be no harm in
215+ # getting the key every time. It does not come from the codecov.io
216+ # website. Anyway, this is needed when the VM is re-created for every test.
217+ curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
218+ curl -Os https://uploader.codecov.io/latest/linux/codecov
219+ curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
220+ curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
221+
222+ # Check that the sha256 matches the signature
223+ gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
224+ # Then check the integrity of the codecov binary
225+ shasum -a 256 -c codecov.SHA256SUM
226+
227+ chmod +x codecov
228+ ./codecov -c -t ${CODECOV_TOKEN} -F ${flag} -f ${file} -s ${dir} -C ${GIT_COMMIT} -r antrea-io/antrea
229+
230+ rm -f trustedkeys.gpg codecov
231+ )}
232+
194233function deliver_antrea_multicluster {
195234 echo " ====== Building Antrea for the Following Commit ======"
196235 export GO111MODULE=on
@@ -231,10 +270,17 @@ function deliver_multicluster_controller {
231270 export GOROOT=/usr/local/go
232271 export PATH=${GOROOT} /bin:$PATH
233272
234- export NO_PULL=1; make antrea-mc-controller
235-
236- docker save " ${DOCKER_REGISTRY} " /antrea/antrea-mc-controller:latest -o " ${WORKDIR} " /antrea-mcs.tar
237- ./multicluster/hack/generate-manifest.sh -l antrea-multicluster > ./multicluster/test/yamls/manifest.yml
273+ if $COVERAGE ; then
274+ export NO_PULL=1; make antrea-mc-controller-coverage
275+ docker save " ${DOCKER_REGISTRY} " /antrea/antrea-mc-controller-coverage:latest -o " ${WORKDIR} " /antrea-mcs.tar
276+ ./multicluster/hack/generate-manifest.sh -l antrea-multicluster -c > ./multicluster/test/yamls/leader-manifest.yml
277+ ./multicluster/hack/generate-manifest.sh -m -c > ./multicluster/test/yamls/member-manifest.yml
278+ else
279+ export NO_PULL=1; make antrea-mc-controller
280+ docker save " ${DOCKER_REGISTRY} " /antrea/antrea-mc-controller:latest -o " ${WORKDIR} " /antrea-mcs.tar
281+ ./multicluster/hack/generate-manifest.sh -l antrea-multicluster > ./multicluster/test/yamls/leader-manifest.yml
282+ ./multicluster/hack/generate-manifest.sh -m > ./multicluster/test/yamls/member-manifest.yml
283+ fi
238284
239285 for kubeconfig in " ${multicluster_kubeconfigs[@]} "
240286 do
@@ -264,7 +310,7 @@ function deliver_multicluster_controller {
264310}
265311
266312function run_multicluster_e2e {
267- echo " ====== Running Multicluster e2e Tests ======"
313+ echo " ====== Running Multicluster e2e Tests ======"
268314 export GO111MODULE=on
269315 export GOPATH=${WORKDIR} /go
270316 export GOROOT=/usr/local/go
@@ -311,11 +357,12 @@ EOF
311357 done
312358
313359 set +e
314- mkdir -p ` pwd` /antrea-multicluster-test-logs
360+ CURRENT_DIR=` pwd`
361+ mkdir -p ${CURRENT_DIR} /antrea-multicluster-test-logs
315362 if ${ENABLE_MC_GATEWAY} ; then
316- go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir ` pwd` /antrea-multicluster-test-logs --mc-gateway
363+ go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir ` pwd` /antrea-multicluster-test-logs --mc-gateway
317364 else
318- go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir ` pwd` /antrea-multicluster-test-logs
365+ go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir ` pwd` /antrea-multicluster-test-logs
319366 fi
320367
321368 if [[ " $? " != " 0" ]]; then
324371 set -e
325372}
326373
374+ function collect_coverage {
375+ COVERAGE_DIR=$1
376+ timestamp=$( date +%Y%m%d%H%M%S)
377+ echo " ====== Collect Multicluster e2e Tests Coverage Files ======"
378+ for kubeconfig in " ${multicluster_kubeconfigs[@]} " ; do
379+ namespace=" kube-system"
380+ if [[ ${kubeconfig} =~ " leader" ]]; then
381+ namespace=" antrea-multicluster"
382+ fi
383+ mc_controller_pod_name=" $( kubectl get pods --selector=app=antrea,component=antrea-mc-controller -n ${namespace} --no-headers=true ${kubeconfig} | awk ' { print $1 }' ) "
384+ controller_pid=" $( kubectl exec -i $mc_controller_pod_name -n ${namespace} ${kubeconfig} -- pgrep antrea) "
385+ kubectl exec -i $mc_controller_pod_name -n ${namespace} ${kubeconfig} -- kill -SIGINT $controller_pid
386+ kubectl cp ${namespace} /$mc_controller_pod_name :antrea-mc-controller.cov.out ${COVERAGE_DIR} /$mc_controller_pod_name -$timestamp ${kubeconfig}
387+ done
388+ }
389+
327390trap clean_multicluster EXIT
328391clean_tmp
329392clean_images
@@ -341,6 +404,16 @@ if [[ ${TESTCASE} =~ "e2e" ]]; then
341404 deliver_antrea_multicluster
342405 deliver_multicluster_controller
343406 run_multicluster_e2e
407+ if $COVERAGE ; then
408+ CURRENT_DIR=` pwd`
409+ rm -rf mc-e2e-coverage
410+ mkdir -p mc-e2e-coverage
411+ collect_coverage ${CURRENT_DIR} /mc-e2e-coverage
412+ # Backup coverage files for later analysis
413+ set +e; find ${DEFAULT_WORKDIR} /mc-e2e-coverage -maxdepth 1 -mtime +1 -type f | xargs -n 1 rm; set -e; # Clean up backup files older than one day.
414+ cp -r mc-e2e-coverage ${DEFAULT_WORKDIR}
415+ run_codecov " e2e-tests" " *antrea-mc*" " ${CURRENT_DIR} /mc-e2e-coverage"
416+ fi
344417fi
345418
346419if [[ ${TEST_FAILURE} == true ]]; then
0 commit comments