Skip to content

Commit 47acb99

Browse files
authored
GCP and AWS improvements for test (#986)
1 parent b6ff30a commit 47acb99

File tree

10 files changed

+47
-37
lines changed

10 files changed

+47
-37
lines changed

.github/actions/build-push-image/action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ runs:
4646
using: "composite"
4747
steps:
4848
- name: Check out code
49-
uses: actions/checkout@v3.1.0
49+
uses: actions/checkout@v3.5.3
5050
if: ${{ inputs.forked == false }}
5151
with:
5252
submodules: true
5353
fetch-depth: 0
5454
- name: Check out code for forked PR
55-
uses: actions/checkout@v3.1.0
55+
uses: actions/checkout@v3.5.3
5656
if: ${{ inputs.forked == true }}
5757
with:
5858
ref: ${{github.event.pull_request.head.sha}}

.github/actions/cleanup-pe/cleanall.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ func cleanAllAWSPE(region string, subnets []string) error {
4040
}
4141

4242
if len(subnetOutput.Subnets) == 0 {
43-
return fmt.Errorf("no subnets found")
43+
continue
4444
}
4545
subnetID := subnetOutput.Subnets[0].SubnetId
4646

47+
fmt.Printf("Listing private endpoints in subnet %s at region %s", *subnetID, region)
4748
endpoints, err := svc.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{})
4849
if err != nil {
4950
return fmt.Errorf("error fething all vpcEP: %v", err)
@@ -56,6 +57,8 @@ func cleanAllAWSPE(region string, subnets []string) error {
5657
}
5758
}
5859

60+
fmt.Printf("Found %d private endpoints in subnet %s at region %s", len(endpointIDs), *subnetID, region)
61+
5962
err = deleteAWSPEsByID(svc, endpointIDs)
6063
if err != nil {
6164
return err
@@ -92,6 +95,7 @@ func cleanAllAzurePE(ctx context.Context, resourceGroupName, azureSubscriptionID
9295
peClient := network.NewPrivateEndpointsClient(azureSubscriptionID)
9396
peClient.Authorizer = authorizer
9497

98+
fmt.Printf("Listing private endpoints at %s", resourceGroupName)
9599
peList, err := peClient.List(ctx, resourceGroupName)
96100
if err != nil {
97101
return fmt.Errorf("error fething all PE: %v", err)
@@ -106,6 +110,8 @@ func cleanAllAzurePE(ctx context.Context, resourceGroupName, azureSubscriptionID
106110
}
107111
}
108112

113+
fmt.Printf("Found %d private endpoints at %s", len(endpointNames), resourceGroupName)
114+
109115
for _, peName := range endpointNames {
110116
_, errDelete := peClient.Delete(ctx, resourceGroupName, peName)
111117
if errDelete != nil {
@@ -129,10 +135,12 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [
129135
for _, subnet := range subnets {
130136
subnetURL := formSubnetURL(region, subnet, projectID)
131137

138+
fmt.Printf("Listing forward rules at %s", subnetURL)
132139
forwardRules, err := computeService.ForwardingRules.List(projectID, region).Do()
133140
if err != nil {
134141
return fmt.Errorf("error while listing forwarding rules: %v", err)
135142
}
143+
log.Printf("Found %d forward rule(s)", len(forwardRules.Items))
136144

137145
counter := 0
138146
for _, forwardRule := range forwardRules.Items {
@@ -147,7 +155,7 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [
147155
forwardRule.Name, forwardRule.Network)
148156
}
149157
}
150-
log.Printf("deleted %d GCP Forfard rules", counter)
158+
log.Printf("deleted %d GCP Forward rules", counter)
151159

152160
time.Sleep(time.Second * 20) // need to wait for GCP to delete the forwarding rule
153161
err = deleteGCPAddressBySubnet(computeService, projectID, region, subnetURL)
@@ -160,6 +168,7 @@ func cleanAllGCPPE(ctx context.Context, projectID, vpc, region string, subnets [
160168
}
161169

162170
func deleteGCPAddressBySubnet(service *compute.Service, projectID, region, subnetURL string) error {
171+
fmt.Printf("Listing addresses at %s", subnetURL)
163172
addressList, err := service.Addresses.List(projectID, region).Do()
164173
if err != nil {
165174
return fmt.Errorf("error while listing addresses: %v", err)

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
7-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0
7+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1
88
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
99
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1
1010
github.com/Azure/go-autorest/autorest v0.11.29
@@ -23,7 +23,7 @@ require (
2323
github.com/pborman/uuid v1.2.1
2424
github.com/sethvargo/go-password v0.2.0
2525
github.com/stretchr/testify v1.8.4
26-
go.mongodb.org/atlas v0.28.0
26+
go.mongodb.org/atlas v0.29.0
2727
go.mongodb.org/mongo-driver v1.11.7
2828
go.uber.org/zap v1.24.0
2929
golang.org/x/sync v0.2.0
@@ -110,7 +110,7 @@ require (
110110
go.uber.org/atomic v1.9.0 // indirect
111111
go.uber.org/multierr v1.7.0 // indirect
112112
golang.org/x/crypto v0.9.0 // indirect
113-
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb
113+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
114114
golang.org/x/net v0.10.0 // indirect
115115
golang.org/x/oauth2 v0.8.0 // indirect
116116
golang.org/x/sys v0.9.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3939
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
4040
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
41-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk=
42-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
41+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 h1:SEy2xmstIphdPwNBUi7uhvjyjhVKISfwjfOJmuy7kg4=
42+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
4343
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
4444
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U=
4545
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
399399
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
400400
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
401401
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
402-
go.mongodb.org/atlas v0.28.0 h1:CelAXtmiM36tdifSDwWdDH1nNbdvq0M2XfUR8208JxA=
403-
go.mongodb.org/atlas v0.28.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
402+
go.mongodb.org/atlas v0.29.0 h1:vBo4Qe8u2GKn8ZEiw8vLCv8lmxryhea6kUWY0ZJL8OU=
403+
go.mongodb.org/atlas v0.29.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
404404
go.mongodb.org/mongo-driver v1.11.7 h1:LIwYxASDLGUg/8wOhgOOZhX8tQa/9tgZPgzZoVqJvcs=
405405
go.mongodb.org/mongo-driver v1.11.7/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
406406
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
446446
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
447447
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
448448
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
449-
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w=
450-
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
449+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
450+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
451451
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
452452
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
453453
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

pkg/controller/atlasdeployment/atlasdeployment_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,12 @@ func (r *AtlasDeploymentReconciler) deleteDeploymentFromAtlas(
443443
return err
444444
}
445445

446-
deleteDeploymentFunc := atlasClient.AdvancedClusters.Delete
447446
if deployment.IsServerless() {
448-
deleteDeploymentFunc = atlasClient.ServerlessInstances.Delete
447+
_, err = atlasClient.ServerlessInstances.Delete(ctx, project.Status.ID, deployment.GetDeploymentName())
448+
} else {
449+
_, err = atlasClient.AdvancedClusters.Delete(ctx, project.Status.ID, deployment.GetDeploymentName(), nil)
449450
}
450451

451-
_, err = deleteDeploymentFunc(ctx, project.Status.ID, deployment.GetDeploymentName())
452-
453452
var apiError *mongodbatlas.ErrorResponse
454453
if errors.As(err, &apiError) && apiError.ErrorCode == atlas.ClusterNotFound {
455454
log.Info("Deployment doesn't exist or is already deleted")

test/e2e/actions/cloud/gcp.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"time"
78

89
"google.golang.org/api/googleapi"
910

@@ -36,12 +37,9 @@ type gcpNetwork struct {
3637

3738
const (
3839
// TODO get from GCP
39-
GoogleProjectID = "atlasoperator" // Google Cloud Project ID
40-
GoogleVPC = "atlas-operator-test" // VPC Name
41-
GoogleSubnetName = "atlas-operator-subnet-leo" // Subnet Name
42-
googleConnectPrefix = "ao" // Private Service Connect Endpoint Prefix
43-
44-
gcpSubnetIPMask = "10.0.0.%d"
40+
GoogleProjectID = "atlasoperator" // Google Cloud Project ID
41+
googleConnectPrefix = "ao" // Private Service Connect Endpoint Prefix
42+
gcpSubnetIPMask = "10.0.0.%d"
4543
)
4644

4745
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)
328326
func (a *GCPAction) createVirtualAddress(ctx context.Context, name, subnet, region string) (string, error) {
329327
a.t.Helper()
330328

329+
rand.Seed(time.Now().UnixNano())
330+
331331
ip := fmt.Sprintf(gcpSubnetIPMask, rand.IntnRange(10, 120))
332332
if subnet == Subnet2Name {
333333
ip = fmt.Sprintf(gcpSubnetIPMask, rand.IntnRange(150, 250))

test/e2e/actions/cloud/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"path"
55
"time"
66

7-
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
8-
97
. "github.com/onsi/gomega"
108

9+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
1110
"github.com/onsi/ginkgo/v2/dsl/core"
1211

1312
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider"

test/e2e/actions/deploy/deploy_operator.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ func CreateProject(testData *model.TestDataProvider) {
5353
err := testData.K8SClient.Create(testData.Context, testData.Project)
5454
Expect(err).ShouldNot(HaveOccurred(), "Project %s was not created", testData.Project.GetName())
5555
Eventually(func(g Gomega) {
56-
condition, _ := k8s.GetProjectStatusCondition(testData.Context, testData.K8SClient, status.ReadyType,
57-
testData.Resources.Namespace, testData.Project.GetName())
58-
g.Expect(condition).Should(Equal("True"))
59-
}).Should(Succeed(), "Project %s was not created", testData.Project.GetName())
60-
})
61-
By(fmt.Sprintf("Wait for Project %s", testData.Project.GetName()), func() {
62-
Eventually(func() bool {
56+
condition, _ := k8s.GetProjectStatusCondition(
57+
testData.Context,
58+
testData.K8SClient,
59+
status.ReadyType,
60+
testData.Resources.Namespace,
61+
testData.Project.GetName(),
62+
)
63+
g.Expect(condition).To(Equal("True"))
64+
6365
statuses := kube.GetProjectStatus(testData)
64-
return statuses.ID != ""
65-
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), "Project %s is not ready", kube.GetProjectStatus(testData))
66+
g.Expect(statuses.ID).ToNot(BeEmpty())
67+
}).WithTimeout(10*time.Minute).WithPolling(10*time.Second).
68+
Should(Succeed(), "Project %s was not created", testData.Project.GetName())
6669
})
6770
}
6871

test/int/datafederation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var _ = Describe("AtlasDataFederation", Label("AtlasDataFederation"), func() {
7474
if manualDeletion && createdProject != nil {
7575
By("Deleting the deployment in Atlas manually", func() {
7676
// We need to remove the deployment in Atlas manually to let project get removed
77-
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDataFederation.Name)
77+
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDataFederation.Name, nil)
7878
Expect(err).NotTo(HaveOccurred())
7979
Eventually(checkAtlasDeploymentRemoved(createdProject.Status.ID, createdDataFederation.Name), 600, interval).Should(BeTrue())
8080
createdDataFederation = nil

test/int/deployment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment"), func() {
100100
if manualDeletion && createdProject != nil {
101101
By("Deleting the deployment in Atlas manually", func() {
102102
// We need to remove the deployment in Atlas manually to let project get removed
103-
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDeployment.GetDeploymentName())
103+
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), createdProject.ID(), createdDeployment.GetDeploymentName(), nil)
104104
Expect(err).NotTo(HaveOccurred())
105105
Eventually(checkAtlasDeploymentRemoved(createdProject.Status.ID, createdDeployment.GetDeploymentName()), 600, interval).Should(BeTrue())
106106
createdDeployment = nil
@@ -1292,7 +1292,7 @@ func checkAtlasDeploymentRemoved(projectID string, deploymentName string) func()
12921292
}
12931293

12941294
func deleteAtlasDeployment(projectID string, deploymentName string) error {
1295-
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), projectID, deploymentName)
1295+
_, err := atlasClient.AdvancedClusters.Delete(context.Background(), projectID, deploymentName, nil)
12961296
return err
12971297
}
12981298

0 commit comments

Comments
 (0)