From 25a00308a0f9fd974066184aa6b847a345230104 Mon Sep 17 00:00:00 2001 From: bzsuni Date: Thu, 25 Jan 2024 09:39:27 +0800 Subject: [PATCH] fix duplicate gateway ip in some test case Signed-off-by: bzsuni --- .../egressendpointslice_test.go | 6 +++--- test/e2e/egressgateway/egressgateway_test.go | 8 ++++---- test/e2e/egresspolicy/egresspolicy_test.go | 19 ++++++++++++------- test/e2e/reliability/reliability_test.go | 6 +++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/test/e2e/egressendpointslice/egressendpointslice_test.go b/test/e2e/egressendpointslice/egressendpointslice_test.go index ded3e9f1a..678b92ee6 100644 --- a/test/e2e/egressendpointslice/egressendpointslice_test.go +++ b/test/e2e/egressendpointslice/egressendpointslice_test.go @@ -29,7 +29,7 @@ var _ = Describe("Egressendpointslice", func() { 4. Verify the status of EndpointSlices and the egress IP of Pods. 5. When deleting all Pods, EndpointSlices should be deleted as well. */ - Context("After performing several rounds of creating and deleting pods, check the status of the egress endpointSlice and the exported IP of the pod", Label("S00001"), func() { + Context("After performing several rounds of creating and deleting pods, check the status of the egress endpointSlice and the exported IP of the pod", Serial, Label("S00001"), func() { // deploy var ( deploy *appsv1.Deployment @@ -59,7 +59,7 @@ var _ = Describe("Egressendpointslice", func() { nodeSelector := egressv1.NodeSelector{Selector: &metav1.LabelSelector{MatchLabels: nodeLabel}} - egw, err = common.CreateGatewayNew(ctx, cli, "egw-"+uuid.NewString(), pool, nodeSelector) + egw, err = common.CreateGatewayNew(ctx, cli, egwName, pool, nodeSelector) Expect(err).NotTo(HaveOccurred(), "failed to create egressGateway %s\n", egwName) DeferCleanup(func() { @@ -84,7 +84,7 @@ var _ = Describe("Egressendpointslice", func() { // delete the egressGateway if its exists if egw != nil { GinkgoWriter.Printf("delete the gatgeway %s if its exists\n", egw.Name) - Expect(common.DeleteObj(ctx, cli, egw)).NotTo(HaveOccurred()) + Expect(common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2)).NotTo(HaveOccurred()) } }) }) diff --git a/test/e2e/egressgateway/egressgateway_test.go b/test/e2e/egressgateway/egressgateway_test.go index 2b6fdb29d..f53713e1e 100644 --- a/test/e2e/egressgateway/egressgateway_test.go +++ b/test/e2e/egressgateway/egressgateway_test.go @@ -352,7 +352,7 @@ var _ = Describe("Operate EgressGateway", Label("EgressGateway"), Ordered, func( DeferCleanup(func() { // delete EgressGateway if egw != nil { - err := common.DeleteObj(ctx, cli, egw) + err := common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2) Expect(err).NotTo(HaveOccurred()) } }) @@ -544,7 +544,7 @@ var _ = Describe("Operate EgressGateway", Label("EgressGateway"), Ordered, func( // delete egw time.Sleep(time.Second) GinkgoWriter.Printf("Delete egw: %s\n", egw.Name) - Expect(common.DeleteObj(ctx, cli, egw)).NotTo(HaveOccurred()) + Expect(common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2)).NotTo(HaveOccurred()) }) }) @@ -687,7 +687,7 @@ var _ = Describe("Operate EgressGateway", Label("EgressGateway"), Ordered, func( // delete the egw if it exists if egw != nil { GinkgoWriter.Printf("Delete egw: %s\n", egw.Name) - Expect(common.DeleteObj(ctx, cli, egw)).NotTo(HaveOccurred()) + Expect(common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2)).NotTo(HaveOccurred()) } }) }) @@ -727,7 +727,7 @@ var _ = Describe("Operate EgressGateway", Label("EgressGateway"), Ordered, func( func createEgressGateway(ctx context.Context) (egw *egressv1.EgressGateway) { // create gateway GinkgoWriter.Println("Create EgressGateway") - pool, err := common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, 3, 1) + pool, err := common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, 3, 2) Expect(err).NotTo(HaveOccurred()) nodeSelector := egressv1.NodeSelector{Selector: &metav1.LabelSelector{MatchLabels: node1.Labels}} egw, err = common.CreateGatewayNew(ctx, cli, "egw-"+uuid.NewString(), pool, nodeSelector) diff --git a/test/e2e/egresspolicy/egresspolicy_test.go b/test/e2e/egresspolicy/egresspolicy_test.go index d9f29d7af..e41b01c64 100644 --- a/test/e2e/egresspolicy/egresspolicy_test.go +++ b/test/e2e/egresspolicy/egresspolicy_test.go @@ -39,7 +39,7 @@ var _ = Describe("EgressPolicy", Serial, func() { ipNum = 3 // create EgressGateway - pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 1) + pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 3) Expect(err).NotTo(HaveOccurred()) nodeSelector := egressv1.NodeSelector{Selector: &metav1.LabelSelector{MatchLabels: nodeLabel}} @@ -50,7 +50,7 @@ var _ = Describe("EgressPolicy", Serial, func() { DeferCleanup(func() { // delete EgressGateway if egw != nil { - err = common.DeleteObj(ctx, cli, egw) + err = common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2) Expect(err).NotTo(HaveOccurred()) } }) @@ -359,6 +359,11 @@ var _ = Describe("EgressPolicy", Serial, func() { err = common.WaitEgressPoliciesDeleted(ctx, cli, []*egressv1.EgressPolicy{egp}, time.Second*5) Expect(err).NotTo(HaveOccurred()) } + // delete the cluster policy if it is existed + if egcp != nil { + err = common.WaitEgressClusterPoliciesDeleted(ctx, cli, []*egressv1.EgressClusterPolicy{egcp}, time.Second*5) + Expect(err).NotTo(HaveOccurred()) + } }) DescribeTable("namespaced policy", func(expectErr bool, setUp func(egp *egressv1.EgressPolicy)) { @@ -940,7 +945,7 @@ var _ = Describe("EgressPolicy", Serial, func() { The policy and clusterPolicy should be created successfully, and the spec.egressGatewayName should be set to the cluster's default gateway. Verify that the status is correct. Create a namespace-level default gateway. Create a policy in this namespace without specifying the gatewayName. It is expected to use the default gateway of this namespace, and verify that the status is correct. */ - Context("Test cluster-level default-egressgateway and namesapce-level default-egressgateway", func() { + Context("Test cluster-level default-egressgateway and namesapce-level default-egressgateway", Serial, func() { var ctx context.Context var err error // gateway @@ -969,7 +974,7 @@ var _ = Describe("EgressPolicy", Serial, func() { // create cluster-level egressgateway ipNum = 3 - pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 1) + pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 4) Expect(err).NotTo(HaveOccurred()) nodeSelector := egressv1.NodeSelector{Selector: &metav1.LabelSelector{MatchLabels: nodeLabel}} @@ -1000,10 +1005,10 @@ var _ = Describe("EgressPolicy", Serial, func() { // delete gateway if it exists if defaultClusterEgw != nil { - Expect(common.DeleteObj(ctx, cli, defaultClusterEgw)).NotTo(HaveOccurred()) + Expect(common.DeleteEgressGateway(ctx, cli, defaultClusterEgw, time.Minute/2)).NotTo(HaveOccurred()) } if defaultNamespaceEgw != nil { - Expect(common.DeleteObj(ctx, cli, defaultNamespaceEgw)).NotTo(HaveOccurred()) + Expect(common.DeleteEgressGateway(ctx, cli, defaultNamespaceEgw, time.Minute/2)).NotTo(HaveOccurred()) } }) }) @@ -1074,7 +1079,7 @@ var _ = Describe("EgressPolicy", Serial, func() { createNamespaceLevelPolicyAndCheck(ctx, defaultClusterEgw, pool, ipNum, podLabels, testNS) // create namespace-default-gateway - pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 1) + pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 5) Expect(err).NotTo(HaveOccurred()) nodeSelector := egressv1.NodeSelector{Selector: &metav1.LabelSelector{MatchLabels: nodeLabel}} diff --git a/test/e2e/reliability/reliability_test.go b/test/e2e/reliability/reliability_test.go index c2ec08eed..2ca101000 100644 --- a/test/e2e/reliability/reliability_test.go +++ b/test/e2e/reliability/reliability_test.go @@ -53,7 +53,7 @@ var _ = Describe("Reliability", Serial, Label("Reliability"), func() { }).WithTimeout(time.Second * 6).WithPolling(time.Second * 2).Should(Succeed()) ipNum = 3 - pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 2) + pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 6) Expect(err).NotTo(HaveOccurred()) egw, err = common.CreateGatewayNew(ctx, cli, "egw-"+uuid.NewString(), pool, selector) @@ -92,7 +92,7 @@ var _ = Describe("Reliability", Serial, Label("Reliability"), func() { Expect(err).NotTo(HaveOccurred()) GinkgoWriter.Println("delete gateway") - err = common.DeleteObj(ctx, cli, egw) + err = common.DeleteEgressGateway(ctx, cli, egw, time.Minute/2) Expect(err).NotTo(HaveOccurred()) // start up all nodes if some nodes not ready @@ -346,7 +346,7 @@ var _ = Describe("Reliability", Serial, Label("Reliability"), func() { GinkgoWriter.Printf("succeeded to create the deploy %s\n", deploy.Name) // create EgressGateway - pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 1) + pool, err = common.GenIPPools(ctx, cli, egressConfig.EnableIPv4, egressConfig.EnableIPv6, int64(ipNum), 7) Expect(err).NotTo(HaveOccurred()) nodeSelector := egressv1.NodeSelector{Selector: &v1.LabelSelector{MatchLabels: nodeLabel}}