Skip to content

Commit

Permalink
test/e2e: use dedicated VPC for datafederation and wait for VPC delet…
Browse files Browse the repository at this point in the history
…ion (#1808)
  • Loading branch information
s-urbaniak authored Sep 6, 2024
1 parent 64e353e commit 6faf1c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/e2e/datafederation_pe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/config"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/data"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/model"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/utils"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/resources"
)

Expand Down Expand Up @@ -75,7 +76,11 @@ var _ = Describe("UserLogin", Label("datafederation"), func() {

vpcId := providerAction.SetupNetwork(
"AWS",
cloud.WithAWSConfig(&cloud.AWSConfig{Region: config.AWSRegionEU}),
cloud.WithAWSConfig(&cloud.AWSConfig{
VPC: utils.RandomName("datafederation-private-endpoint"),
Region: config.AWSRegionEU,
EnableCleanup: true,
}),
)
pe = providerAction.SetupPrivateEndpoint(
&cloud.AWSPrivateEndpointRequest{
Expand Down
30 changes: 30 additions & 0 deletions test/helper/e2e/actions/cloud/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/kms"
Expand Down Expand Up @@ -280,6 +282,34 @@ func (a *AwsAction) CreatePrivateEndpoint(serviceName, privateEndpointName, regi
if err != nil {
a.t.Error(err)
}

timeout := 10 * time.Minute
start := time.Now()
for {
a.t.Log(fmt.Sprintf("deleting VPC ID %q since %v", aws.StringValue(result.VpcEndpoint.VpcEndpointId), time.Since(start)))

output, err := ec2Client.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{
VpcEndpointIds: []*string{result.VpcEndpoint.VpcEndpointId},
})

var e awserr.Error
if (errors.As(err, &e) && e.Code() == "InvalidVpcEndpointId.NotFound") || len(output.VpcEndpoints) == 0 {
return
}

if err != nil {
a.t.Error(err)
return
}

if time.Since(start) > timeout {
a.t.Error(errors.New("timeout waiting for deletion of vpc endpoints"))
return
}

// we do know that deletion of VPC endpoints takes time
time.Sleep(3 * time.Second)
}
})

return *result.VpcEndpoint.VpcEndpointId, nil
Expand Down

0 comments on commit 6faf1c5

Please sign in to comment.