From 296431ae1fcf411609599fa08301d1714f5ec498 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Tue, 6 Jun 2023 17:31:30 +0200 Subject: [PATCH 1/6] skip when subnet doesn't exist --- .github/actions/cleanup-pe/cleanall.go | 2 +- test/e2e/actions/cloud/gcp.go | 12 ++++++------ test/e2e/actions/cloud/provider.go | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/actions/cleanup-pe/cleanall.go b/.github/actions/cleanup-pe/cleanall.go index 20762d5ffd..ec7d4cd9ef 100644 --- a/.github/actions/cleanup-pe/cleanall.go +++ b/.github/actions/cleanup-pe/cleanall.go @@ -40,7 +40,7 @@ func cleanAllAWSPE(region string, subnets []string) error { } if len(subnetOutput.Subnets) == 0 { - return fmt.Errorf("no subnets found") + continue } subnetID := subnetOutput.Subnets[0].SubnetId diff --git a/test/e2e/actions/cloud/gcp.go b/test/e2e/actions/cloud/gcp.go index 8773e5f556..5db1ca4b39 100644 --- a/test/e2e/actions/cloud/gcp.go +++ b/test/e2e/actions/cloud/gcp.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "time" "google.golang.org/api/googleapi" @@ -36,12 +37,9 @@ type gcpNetwork struct { const ( // TODO get from GCP - GoogleProjectID = "atlasoperator" // Google Cloud Project ID - GoogleVPC = "atlas-operator-test" // VPC Name - GoogleSubnetName = "atlas-operator-subnet-leo" // Subnet Name - googleConnectPrefix = "ao" // Private Service Connect Endpoint Prefix - - gcpSubnetIPMask = "10.0.0.%d" + GoogleProjectID = "atlasoperator" // Google Cloud Project ID + googleConnectPrefix = "ao" // Private Service Connect Endpoint Prefix + gcpSubnetIPMask = "10.0.0.%d" ) func (a *GCPAction) InitNetwork(vpcName, region string, subnets map[string]string, cleanup bool) (string, error) { @@ -328,6 +326,8 @@ func (a *GCPAction) deleteSubnet(ctx context.Context, subnetName, region string) func (a *GCPAction) createVirtualAddress(ctx context.Context, name, subnet, region string) (string, error) { a.t.Helper() + rand.Seed(time.Now().UnixNano()) + ip := fmt.Sprintf(gcpSubnetIPMask, rand.IntnRange(10, 120)) if subnet == Subnet2Name { ip = fmt.Sprintf(gcpSubnetIPMask, rand.IntnRange(150, 250)) diff --git a/test/e2e/actions/cloud/provider.go b/test/e2e/actions/cloud/provider.go index 6317fe5fbc..d2d9824e87 100644 --- a/test/e2e/actions/cloud/provider.go +++ b/test/e2e/actions/cloud/provider.go @@ -4,10 +4,9 @@ import ( "path" "time" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" - . "github.com/onsi/gomega" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" "github.com/onsi/ginkgo/v2/dsl/core" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider" From bb350b246d80f378bb28d578d15fe5c7948501f2 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 12 Jun 2023 12:31:57 +0200 Subject: [PATCH 2/6] adding some logging msg --- .github/actions/cleanup-pe/cleanall.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/actions/cleanup-pe/cleanall.go b/.github/actions/cleanup-pe/cleanall.go index ec7d4cd9ef..b6e2d9d0e7 100644 --- a/.github/actions/cleanup-pe/cleanall.go +++ b/.github/actions/cleanup-pe/cleanall.go @@ -44,6 +44,7 @@ func cleanAllAWSPE(region string, subnets []string) error { } subnetID := subnetOutput.Subnets[0].SubnetId + fmt.Printf("Listing private endpoints in subnet %s at region %s", *subnetID, region) endpoints, err := svc.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{}) if err != nil { return fmt.Errorf("error fething all vpcEP: %v", err) @@ -56,6 +57,8 @@ func cleanAllAWSPE(region string, subnets []string) error { } } + fmt.Printf("Found %d private endpoints in subnet %s at region %s", len(endpointIDs), *subnetID, region) + err = deleteAWSPEsByID(svc, endpointIDs) if err != nil { return err @@ -92,6 +95,7 @@ func cleanAllAzurePE(ctx context.Context, resourceGroupName, azureSubscriptionID peClient := network.NewPrivateEndpointsClient(azureSubscriptionID) peClient.Authorizer = authorizer + fmt.Printf("Listing private endpoints at %s", resourceGroupName) peList, err := peClient.List(ctx, resourceGroupName) if err != nil { return fmt.Errorf("error fething all PE: %v", err) @@ -106,6 +110,8 @@ func cleanAllAzurePE(ctx context.Context, resourceGroupName, azureSubscriptionID } } + fmt.Printf("Found %d private endpoints at %s", len(endpointNames), resourceGroupName) + for _, peName := range endpointNames { _, errDelete := peClient.Delete(ctx, resourceGroupName, peName) if errDelete != nil { @@ -129,10 +135,12 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [ for _, subnet := range subnets { subnetURL := formSubnetURL(region, subnet, projectID) + fmt.Printf("Listing forward rules at %s", subnetURL) forwardRules, err := computeService.ForwardingRules.List(projectID, region).Do() if err != nil { return fmt.Errorf("error while listing forwarding rules: %v", err) } + log.Printf("Found %d forward rule(s)", len(forwardRules.Items)) counter := 0 for _, forwardRule := range forwardRules.Items { @@ -147,7 +155,7 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [ forwardRule.Name, forwardRule.Network) } } - log.Printf("deleted %d GCP Forfard rules", counter) + log.Printf("deleted %d GCP Forward rules", counter) time.Sleep(time.Second * 20) // need to wait for GCP to delete the forwarding rule err = deleteGCPAddressBySubnet(computeService, projectID, region, subnetURL) @@ -160,6 +168,7 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [ } func deleteGCPAddressBySubnet(service *compute.Service, projectID, region, subnetURL string) error { + fmt.Printf("Listing addresses at %s", subnetURL) addressList, err := service.Addresses.List(projectID, region).Do() if err != nil { return fmt.Errorf("error while listing addresses: %v", err) From f67e2c300c37d55a4441089e5465253c25cf0ee0 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 12 Jun 2023 14:40:01 +0200 Subject: [PATCH 3/6] timeout improvements --- test/e2e/actions/deploy/deploy_operator.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/e2e/actions/deploy/deploy_operator.go b/test/e2e/actions/deploy/deploy_operator.go index 4d2a1f3011..905b879f88 100644 --- a/test/e2e/actions/deploy/deploy_operator.go +++ b/test/e2e/actions/deploy/deploy_operator.go @@ -52,17 +52,20 @@ func CreateProject(testData *model.TestDataProvider) { By(fmt.Sprintf("Deploy Project %s", testData.Project.GetName()), func() { err := testData.K8SClient.Create(testData.Context, testData.Project) Expect(err).ShouldNot(HaveOccurred(), "Project %s was not created", testData.Project.GetName()) - Eventually(func(g Gomega) { - condition, _ := k8s.GetProjectStatusCondition(testData.Context, testData.K8SClient, status.ReadyType, - testData.Resources.Namespace, testData.Project.GetName()) + Eventually(func(g Gomega) bool { + condition, _ := k8s.GetProjectStatusCondition( + testData.Context, + testData.K8SClient, + status.ReadyType, + testData.Resources.Namespace, + testData.Project.GetName(), + ) g.Expect(condition).Should(Equal("True")) - }).Should(Succeed(), "Project %s was not created", testData.Project.GetName()) - }) - By(fmt.Sprintf("Wait for Project %s", testData.Project.GetName()), func() { - Eventually(func() bool { + statuses := kube.GetProjectStatus(testData) return statuses.ID != "" - }, 5*time.Minute, 5*time.Second).Should(BeTrue(), "Project %s is not ready", kube.GetProjectStatus(testData)) + }).WithTimeout(10*time.Minute).WithPolling(10*time.Second). + Should(Succeed(), "Project %s was not created", testData.Project.GetName()) }) } From 34dd7faf2a5f0863b28d4342946897d4b3028b61 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 12 Jun 2023 15:16:30 +0200 Subject: [PATCH 4/6] timeout improvements --- test/e2e/actions/deploy/deploy_operator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/actions/deploy/deploy_operator.go b/test/e2e/actions/deploy/deploy_operator.go index 905b879f88..f2474c9461 100644 --- a/test/e2e/actions/deploy/deploy_operator.go +++ b/test/e2e/actions/deploy/deploy_operator.go @@ -52,7 +52,7 @@ func CreateProject(testData *model.TestDataProvider) { By(fmt.Sprintf("Deploy Project %s", testData.Project.GetName()), func() { err := testData.K8SClient.Create(testData.Context, testData.Project) Expect(err).ShouldNot(HaveOccurred(), "Project %s was not created", testData.Project.GetName()) - Eventually(func(g Gomega) bool { + Eventually(func(g Gomega) { condition, _ := k8s.GetProjectStatusCondition( testData.Context, testData.K8SClient, @@ -60,10 +60,10 @@ func CreateProject(testData *model.TestDataProvider) { testData.Resources.Namespace, testData.Project.GetName(), ) - g.Expect(condition).Should(Equal("True")) + g.Expect(condition).To(Equal("True")) statuses := kube.GetProjectStatus(testData) - return statuses.ID != "" + g.Expect(statuses.ID).ToNot(BeEmpty()) }).WithTimeout(10*time.Minute).WithPolling(10*time.Second). Should(Succeed(), "Project %s was not created", testData.Project.GetName()) }) From f7ddcc9be68903732b22d2179d5913bf090af026 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Tue, 13 Jun 2023 17:05:04 +0200 Subject: [PATCH 5/6] more updates --- .github/actions/build-push-image/action.yaml | 4 ++-- go.mod | 6 +++--- go.sum | 12 ++++++------ .../atlasdeployment/atlasdeployment_controller.go | 7 +++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/actions/build-push-image/action.yaml b/.github/actions/build-push-image/action.yaml index 70dbe3154b..9eabe70b78 100644 --- a/.github/actions/build-push-image/action.yaml +++ b/.github/actions/build-push-image/action.yaml @@ -46,13 +46,13 @@ runs: using: "composite" steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.5.3 if: ${{ inputs.forked == false }} with: submodules: true fetch-depth: 0 - name: Check out code for forked PR - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.5.3 if: ${{ inputs.forked == true }} with: ref: ${{github.event.pull_request.head.sha}} diff --git a/go.mod b/go.mod index c42ea84f83..88d97bc1cd 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/Azure/azure-sdk-for-go v68.0.0+incompatible - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1 github.com/Azure/go-autorest/autorest v0.11.29 @@ -23,7 +23,7 @@ require ( github.com/pborman/uuid v1.2.1 github.com/sethvargo/go-password v0.2.0 github.com/stretchr/testify v1.8.4 - go.mongodb.org/atlas v0.28.0 + go.mongodb.org/atlas v0.29.0 go.mongodb.org/mongo-driver v1.11.7 go.uber.org/zap v1.24.0 golang.org/x/sync v0.2.0 @@ -110,7 +110,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.7.0 // indirect golang.org/x/crypto v0.9.0 // indirect - golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 golang.org/x/net v0.10.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect golang.org/x/sys v0.9.0 // indirect diff --git a/go.sum b/go.sum index 15e93ba9d1..2c44f68252 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU= github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 h1:SEy2xmstIphdPwNBUi7uhvjyjhVKISfwjfOJmuy7kg4= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= @@ -399,8 +399,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/atlas v0.28.0 h1:CelAXtmiM36tdifSDwWdDH1nNbdvq0M2XfUR8208JxA= -go.mongodb.org/atlas v0.28.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= +go.mongodb.org/atlas v0.29.0 h1:vBo4Qe8u2GKn8ZEiw8vLCv8lmxryhea6kUWY0ZJL8OU= +go.mongodb.org/atlas v0.29.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= go.mongodb.org/mongo-driver v1.11.7 h1:LIwYxASDLGUg/8wOhgOOZhX8tQa/9tgZPgzZoVqJvcs= go.mongodb.org/mongo-driver v1.11.7/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -446,8 +446,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w= -golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/pkg/controller/atlasdeployment/atlasdeployment_controller.go b/pkg/controller/atlasdeployment/atlasdeployment_controller.go index a2c00cae3e..063dcf64a0 100644 --- a/pkg/controller/atlasdeployment/atlasdeployment_controller.go +++ b/pkg/controller/atlasdeployment/atlasdeployment_controller.go @@ -443,13 +443,12 @@ func (r *AtlasDeploymentReconciler) deleteDeploymentFromAtlas( return err } - deleteDeploymentFunc := atlasClient.AdvancedClusters.Delete if deployment.IsServerless() { - deleteDeploymentFunc = atlasClient.ServerlessInstances.Delete + _, err = atlasClient.ServerlessInstances.Delete(ctx, project.Status.ID, deployment.GetDeploymentName()) + } else { + _, err = atlasClient.AdvancedClusters.Delete(ctx, project.Status.ID, deployment.GetDeploymentName(), nil) } - _, err = deleteDeploymentFunc(ctx, project.Status.ID, deployment.GetDeploymentName()) - var apiError *mongodbatlas.ErrorResponse if errors.As(err, &apiError) && apiError.ErrorCode == atlas.ClusterNotFound { log.Info("Deployment doesn't exist or is already deleted") From 931eea5743b140f1c88e020fb76309d8cfb435d8 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Tue, 13 Jun 2023 17:15:44 +0200 Subject: [PATCH 6/6] fix integration test --- test/int/datafederation_test.go | 2 +- test/int/deployment_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/int/datafederation_test.go b/test/int/datafederation_test.go index 178627b291..99f4edaa8d 100644 --- a/test/int/datafederation_test.go +++ b/test/int/datafederation_test.go @@ -74,7 +74,7 @@ var _ = Describe("AtlasDataFederation", Label("AtlasDataFederation"), func() { if manualDeletion && createdProject != nil { By("Deleting the deployment in Atlas manually", func() { // We need to remove the deployment in Atlas manually to let project get removed - _, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDataFederation.Name) + _, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDataFederation.Name, nil) Expect(err).NotTo(HaveOccurred()) Eventually(checkAtlasDeploymentRemoved(createdProject.Status.ID, createdDataFederation.Name), 600, interval).Should(BeTrue()) createdDataFederation = nil diff --git a/test/int/deployment_test.go b/test/int/deployment_test.go index 46f59d414d..ab63dbe72a 100644 --- a/test/int/deployment_test.go +++ b/test/int/deployment_test.go @@ -100,7 +100,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment"), func() { if manualDeletion && createdProject != nil { By("Deleting the deployment in Atlas manually", func() { // We need to remove the deployment in Atlas manually to let project get removed - _, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDeployment.GetDeploymentName()) + _, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDeployment.GetDeploymentName(), nil) Expect(err).NotTo(HaveOccurred()) Eventually(checkAtlasDeploymentRemoved(createdProject.Status.ID, createdDeployment.GetDeploymentName()), 600, interval).Should(BeTrue()) createdDeployment = nil @@ -1292,7 +1292,7 @@ func checkAtlasDeploymentRemoved(projectID string, deploymentName string) func() } func deleteAtlasDeployment(projectID string, deploymentName string) error { - _, err := atlasClient.AdvancedClusters.Delete(context.Background(), projectID, deploymentName) + _, err := atlasClient.AdvancedClusters.Delete(context.Background(), projectID, deploymentName, nil) return err }