From 5ce44ea057b631e23ab9a1bd803c84693824fc61 Mon Sep 17 00:00:00 2001 From: Lan Date: Wed, 21 Sep 2022 00:34:45 +0800 Subject: [PATCH] Add e2e test for Multi-cluster Service Endpoints changes (#4217) Add a new e2e test to validate Endpoint change event to make sure event filter works as expected. Signed-off-by: Lan Luo --- multicluster/test/e2e/main_test.go | 1 + multicluster/test/e2e/service_test.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/multicluster/test/e2e/main_test.go b/multicluster/test/e2e/main_test.go index fc77a7a88b5..8f9a6bd3ca5 100644 --- a/multicluster/test/e2e/main_test.go +++ b/multicluster/test/e2e/main_test.go @@ -110,6 +110,7 @@ func TestConnectivity(t *testing.T) { defer tearDownForServiceExportsTest(t, data) initializeForServiceExportsTest(t, data) t.Run("Case=MCServiceConnectivity", func(t *testing.T) { testMCServiceConnectivity(t, data) }) + t.Run("Case=ScaleDownMCServiceEndpoints", func(t *testing.T) { testScaleDownMCServiceEndpoints(t, data) }) t.Run("Case=ANPToServices", func(t *testing.T) { testANPToServices(t, data) }) }) diff --git a/multicluster/test/e2e/service_test.go b/multicluster/test/e2e/service_test.go index 48c74b9e741..40572d043dc 100644 --- a/multicluster/test/e2e/service_test.go +++ b/multicluster/test/e2e/service_test.go @@ -23,6 +23,7 @@ import ( "time" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" antreae2e "antrea.io/antrea/test/e2e" @@ -100,6 +101,18 @@ func testMCServiceConnectivity(t *testing.T, data *MCTestData) { data.testMCServiceConnectivity(t) } +// Delete existing Pod to scale down the number of Endpoints to zero, then +// the Multi-cluster Service should be deleted due to empty Endpoints. +func testScaleDownMCServiceEndpoints(t *testing.T, data *MCTestData) { + deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, testServerPod) + time.Sleep(2 * time.Second) + mcServiceName := fmt.Sprintf("antrea-mc-%s", eastClusterTestService) + _, err := data.getService(westCluster, multiClusterTestNamespace, mcServiceName) + if !apierrors.IsNotFound(err) { + t.Fatalf("Expected to get not found error when getting the imported Service %s, but got: %v", mcServiceName, err) + } +} + func testANPToServices(t *testing.T, data *MCTestData) { data.testANPToServices(t) } @@ -126,7 +139,6 @@ func (data *MCTestData) probeMCServiceFromCluster(t *testing.T, clusterName stri if err := data.probeServiceFromPodInCluster(clusterName, regularClientName, "client", multiClusterTestNamespace, ip); err != nil { t.Fatalf("Error when probing Service from client Pod %s in cluster %s, err: %v", regularClientName, clusterName, err) } - return } func (data *MCTestData) testANPToServices(t *testing.T) {