From 7d637a915562b27a06b7285bb9842e19a00bc683 Mon Sep 17 00:00:00 2001 From: Yang Ding Date: Fri, 25 Feb 2022 15:22:36 -0800 Subject: [PATCH] Cleanup test code Signed-off-by: Yang Ding --- ci/jenkins/clean-mc.sh | 148 ------------------ ci/jenkins/test-mc.sh | 26 +-- .../v1alpha1/resourceexport_webhook.go | 1 - 3 files changed, 13 insertions(+), 162 deletions(-) delete mode 100644 ci/jenkins/clean-mc.sh diff --git a/ci/jenkins/clean-mc.sh b/ci/jenkins/clean-mc.sh deleted file mode 100644 index 1e07681c09d..00000000000 --- a/ci/jenkins/clean-mc.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2021 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. - -set -eo pipefail - -DEFAULT_WORKDIR="/var/lib/jenkins" -DEFAULT_KUBECONFIG_PATH=$DEFAULT_WORKDIR/kube.conf -WORKDIR=$DEFAULT_WORKDIR -TESTCASE="" -TEST_FAILURE=false -DOCKER_REGISTRY=$(head -n1 "/var/lib/jenkins/antrea/ci/docker-registry") -GO_VERSION=$(head -n1 "/var/lib/jenkins/antrea/build/images/deps/go-version") -IMAGE_PULL_POLICY="Always" -MULTICLUSTER_KUBECONFIG_PATH=$WORKDIR/.kube -LEADER_CLUSTER_CONFIG="--kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH/leader" -EAST_CLUSTER_CONFIG="--kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH/east" -WEST_CLUSTER_CONFIG="--kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH/west" - -NGINX_IMAGE=projects.registry.vmware.com/antrea/nginx:1.21.6-alpine - -CONTROL_PLANE_NODE_ROLE="control-plane,master" - -multicluster_kubeconfigs=($EAST_CLUSTER_CONFIG $LEADER_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG) -membercluter_kubeconfigs=($EAST_CLUSTER_CONFIG $WEST_CLUSTER_CONFIG) - -CLEAN_STALE_IMAGES="docker system prune --force --all --filter until=48h" - -_usage="Usage: $0 [--kubeconfigs-path ] [--workdir ] - [--testcase ] - -Run Antrea multi-cluster e2e tests on a remote (Jenkins) Linux Cluster Set. - - --kubeconfigs-path Path of cluster set kubeconfigs. - --workdir Home path for Go, vSphere information and antrea_logs during cluster setup. Default is $WORKDIR. - --testcase Antrea multi-cluster e2e test cases on a Linux cluster set. - --registry The docker registry to use instead of dockerhub." - -function print_usage { - echoerr "$_usage" -} - - -while [[ $# -gt 0 ]] -do -key="$1" - -case $key in - --kubeconfigs-path) - MULTICLUSTER_KUBECONFIG_PATH="$2" - shift 2 - ;; - --workdir) - WORKDIR="$2" - shift 2 - ;; - --testcase) - TESTCASE="$2" - shift 2 - ;; - --registry) - DOCKER_REGISTRY="$2" - shift 2 - ;; - -h|--help) - print_usage - exit 0 - ;; - *) # unknown option - echoerr "Unknown option $1" - exit 1 - ;; -esac -done - - -function clean_tmp() { - echo "===== Clean up stale files & folders older than 7 days under /tmp =====" - CLEAN_LIST=( - "*codecov*" - "kustomize-*" - "*antrea*" - "go-build*" - ) - for item in "${CLEAN_LIST[@]}"; do - find /tmp -name "${item}" -mtime +7 -exec rm -rf {} \; 2>&1 | grep -v "Permission denied" || true - done - find ${WORKDIR} -name "support-bundles*" -mtime +7 -exec rm -rf {} \; 2>&1 | grep -v "Permission denied" || true -} - - -function cleanup_multicluster_ns { - ns=$1 - kubeconfig=$2 - - kubectl delete ns "${ns}" --ignore-not-found=true ${kubeconfig} --timeout=30s || true -} - -function cleanup_multicluster_controller { - echo "====== Cleanup Multicluster Controller Installation ======" - kubeconfig=$1 - for multicluster_yml in /var/lib/jenkins/antrea/multicluster/test/yamls/*.yml; do - kubectl delete -f $multicluster_yml $kubeconfig --ignore-not-found=true --timeout=30s || true - done - - for multicluster_yml in /var/lib/jenkins/antrea/multicluster/build/yamls/*.yml; do - kubectl delete -f $multicluster_yml $kubeconfig --ignore-not-found=true --timeout=30s || true - done -} - -function cleanup_multicluster_antrea { - echo "====== Cleanup Antrea controller and agent ======" - kubeconfig=$1 - kubectl get pod -n kube-system -l component=antrea-agent --no-headers=true $kubeconfig | awk '{print $1}' | while read AGENTNAME; do - kubectl exec $AGENTNAME -c antrea-agent -n kube-system ${kubeconfig} ovs-vsctl del-port br-int gw0 || true - done - - for antrea_yml in ${WORKDIR}/*.yml; do - kubectl delete -f $antrea_yml --ignore-not-found=true ${kubeconfig} --timeout=30s || true - done -} - -function clean_multicluster { - echo "====== Cleanup Multicluster Antrea Installation in clusters ======" - for kubeconfig in "${multicluster_kubeconfigs[@]}" - do - cleanup_multicluster_ns "antrea-multicluster-test" $kubeconfig - cleanup_multicluster_ns "antrea-mcs-ns" $kubeconfig - cleanup_multicluster_controller $kubeconfig - cleanup_multicluster_antrea $kubeconfig - done -} - -trap clean_multicluster EXIT -clean_tmp - diff --git a/ci/jenkins/test-mc.sh b/ci/jenkins/test-mc.sh index 968db1f54c2..5ac8eb9a4df 100755 --- a/ci/jenkins/test-mc.sh +++ b/ci/jenkins/test-mc.sh @@ -25,8 +25,8 @@ DEFAULT_KUBECONFIG_PATH=$DEFAULT_WORKDIR/kube.conf WORKDIR=$DEFAULT_WORKDIR TESTCASE="" TEST_FAILURE=false -DOCKER_REGISTRY=$(head -n1 "/var/lib/jenkins/antrea/ci/docker-registry") -GO_VERSION=$(head -n1 "/var/lib/jenkins/antrea/build/images/deps/go-version") +DOCKER_REGISTRY=$(head -n1 "${WORKSPACE}/ci/docker-registry") +GO_VERSION=$(head -n1 "${WORKSPACE}/build/images/deps/go-version") IMAGE_PULL_POLICY="Always" MULTICLUSTER_KUBECONFIG_PATH=$WORKDIR/.kube LEADER_CLUSTER_CONFIG="--kubeconfig=$MULTICLUSTER_KUBECONFIG_PATH/leader" @@ -115,11 +115,11 @@ function cleanup_multicluster_ns { function cleanup_multicluster_controller { echo "====== Cleanup Multicluster Controller Installation ======" kubeconfig=$1 - for multicluster_yml in /var/lib/jenkins/antrea/multicluster/test/yamls/*.yml; do + for multicluster_yml in ${WORKSPACE}/multicluster/test/yamls/*.yml; do kubectl delete -f $multicluster_yml $kubeconfig --ignore-not-found=true --timeout=30s || true done - for multicluster_yml in /var/lib/jenkins/antrea/multicluster/build/yamls/*.yml; do + for multicluster_yml in ${WORKSPACE}/multicluster/build/yamls/*.yml; do kubectl delete -f $multicluster_yml $kubeconfig --ignore-not-found=true --timeout=30s || true done } @@ -278,17 +278,17 @@ function run_multicluster_e2e { done -# set +e -# mkdir -p `pwd`/antrea-multicluster-test-logs -# go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir `pwd`/antrea-multicluster-test-logs -# if [[ "$?" != "0" ]]; then -# TEST_FAILURE=true -# fi -# set -e + set +e + mkdir -p `pwd`/antrea-multicluster-test-logs + go test -v antrea.io/antrea/multicluster/test/e2e --logs-export-dir `pwd`/antrea-multicluster-test-logs + if [[ "$?" != "0" ]]; then + TEST_FAILURE=true + fi + set -e } -#trap clean_multicluster EXIT -#clean_tmp +trap clean_multicluster EXIT +clean_tmp if [[ ${TESTCASE} =~ "e2e" ]]; then deliver_antrea_multicluster diff --git a/multicluster/apis/multicluster/v1alpha1/resourceexport_webhook.go b/multicluster/apis/multicluster/v1alpha1/resourceexport_webhook.go index 5b78713eee6..4429f182860 100644 --- a/multicluster/apis/multicluster/v1alpha1/resourceexport_webhook.go +++ b/multicluster/apis/multicluster/v1alpha1/resourceexport_webhook.go @@ -54,7 +54,6 @@ func (r *ResourceExport) Default() { if namespaceLabelVal, exists := r.Labels[common.SourceNamespace]; !exists || namespaceLabelVal != "" { r.Labels[common.SourceNamespace] = "" } - // TODO: put sourceClusterID for leader cluster? if kindLabelVal, exists := r.Labels[common.SourceKind]; !exists || kindLabelVal != common.AntreaClusterNetworkPolicyKind { r.Labels[common.SourceKind] = common.AntreaClusterNetworkPolicyKind }