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 } diff --git a/multicluster/controllers/multicluster/commonarea/resourceimport_controller.go b/multicluster/controllers/multicluster/commonarea/resourceimport_controller.go index e5af77e5df7..919b7d9f7b8 100644 --- a/multicluster/controllers/multicluster/commonarea/resourceimport_controller.go +++ b/multicluster/controllers/multicluster/commonarea/resourceimport_controller.go @@ -377,22 +377,24 @@ func (r *ResourceImportReconciler) handleResImpUpdateForClusterNetworkPolicy(ctx tierKind, tierName := &v1alpha1.Tier{}, acnpObj.Spec.Tier err = r.localClusterClient.Get(ctx, types.NamespacedName{Namespace: "", Name: tierName}, tierKind) tierNotFound := apierrors.IsNotFound(err) - if acnpNotFound && !tierNotFound { - if err = r.localClusterClient.Create(ctx, acnpObj, &client.CreateOptions{}); err != nil { - klog.ErrorS(err, "failed to create imported Antrea ClusterNetworkPolicy", "acnp", klog.KObj(acnpObj)) - return ctrl.Result{}, err + if !tierNotFound { + if acnpNotFound { + if err = r.localClusterClient.Create(ctx, acnpObj, &client.CreateOptions{}); err != nil { + klog.ErrorS(err, "failed to create imported Antrea ClusterNetworkPolicy", "acnp", klog.KObj(acnpObj)) + return ctrl.Result{}, err + } + } else if !apiequality.Semantic.DeepEqual(acnp.Spec, acnpObj.Spec) { + acnp.Spec = acnpObj.Spec + if err = r.localClusterClient.Update(ctx, acnp, &client.UpdateOptions{}); err != nil { + klog.ErrorS(err, "failed to update imported Antrea ClusterNetworkPolicy", "acnp", klog.KObj(acnpObj)) + return ctrl.Result{}, err + } } - } else if !acnpNotFound && tierNotFound { + } else if tierNotFound && !acnpNotFound { if err = r.localClusterClient.Delete(ctx, acnpObj, &client.DeleteOptions{}); err != nil { klog.ErrorS(err, "failed to delete imported Antrea ClusterNetworkPolicy that no longer have a valid Tier for the current cluster", "acnp", klog.KObj(acnpObj)) return ctrl.Result{}, err } - } else if !apiequality.Semantic.DeepEqual(acnp.Spec, acnpObj.Spec) { - acnp.Spec = acnpObj.Spec - if err = r.localClusterClient.Update(ctx, acnp, &client.UpdateOptions{}); err != nil { - klog.ErrorS(err, "failed to update imported Antrea ClusterNetworkPolicy", "acnp", klog.KObj(acnpObj)) - return ctrl.Result{}, err - } } acnpImp := &multiclusterv1alpha1.ACNPImport{} err = r.localClusterClient.Get(ctx, acnpImpName, acnpImp) diff --git a/multicluster/controllers/multicluster/resourceexport_controller.go b/multicluster/controllers/multicluster/resourceexport_controller.go index 6f4cdb708d1..ea57d799a50 100644 --- a/multicluster/controllers/multicluster/resourceexport_controller.go +++ b/multicluster/controllers/multicluster/resourceexport_controller.go @@ -79,7 +79,7 @@ func NewResourceExportReconciler( // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile func (r *ResourceExportReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - klog.InfoS("reconciling ResourceExport", "resourceexport", req.NamespacedName) + klog.V(2).InfoS("reconciling ResourceExport", "resourceexport", req.NamespacedName) var resExport mcsv1alpha1.ResourceExport if err := r.Client.Get(ctx, req.NamespacedName, &resExport); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) @@ -92,7 +92,6 @@ func (r *ResourceExportReconciler) Reconcile(ctx context.Context, req ctrl.Reque // More details about using Finalizers, please refer to https://book.kubebuilder.io/reference/using-finalizers.html. if !resExport.DeletionTimestamp.IsZero() { if common.StringExistsInSlice(resExport.Finalizers, common.ResourceExportFinalizer) { - klog.Info("There are finalizers, handling delete event") err := r.handleDeleteEvent(ctx, &resExport) if err != nil { return ctrl.Result{}, err @@ -103,7 +102,6 @@ func (r *ResourceExportReconciler) Reconcile(ctx context.Context, req ctrl.Reque } return ctrl.Result{}, nil } - klog.Info("There are no finalizers, returning") return ctrl.Result{}, nil } diff --git a/multicluster/controllers/multicluster/resourceexport_controller_test.go b/multicluster/controllers/multicluster/resourceexport_controller_test.go index 428d162b90b..fd1ff1c61d6 100644 --- a/multicluster/controllers/multicluster/resourceexport_controller_test.go +++ b/multicluster/controllers/multicluster/resourceexport_controller_test.go @@ -35,9 +35,9 @@ import ( ) var ( - now = metav1.Now() - dropAction = v1alpha1.RuleActionDrop - svcLabels = map[string]string{ + now = metav1.Now() + dropAction = v1alpha1.RuleActionDrop + svcLabels = map[string]string{ common.SourceNamespace: "default", common.SourceName: "nginx", common.SourceKind: "Service",