Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-287234: Fix Atlas cleaner to reap fed db private endpoints #1957

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tools/clean/atlas/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ type Cleaner struct {
}

type ProjectDependencies struct {
NetworkPeering []admin.BaseNetworkPeeringConnectionSettings
AWSPrivateEndpoints []admin.EndpointService
GCPPrivateEndpoints []admin.EndpointService
AzurePrivateEndpoints []admin.EndpointService
Clusters []admin.AdvancedClusterDescription
ServerlessClusters []admin.ServerlessInstanceDescription
FederatedDatabases []admin.DataLakeTenant
EncryptionAtRest *admin.EncryptionAtRest
NetworkPeering []admin.BaseNetworkPeeringConnectionSettings
AWSPrivateEndpoints []admin.EndpointService
GCPPrivateEndpoints []admin.EndpointService
AzurePrivateEndpoints []admin.EndpointService
Clusters []admin.AdvancedClusterDescription
ServerlessClusters []admin.ServerlessInstanceDescription
FederatedDatabases []admin.DataLakeTenant
FederatedDBPrivateEndpoints []admin.PrivateNetworkEndpointIdEntry
EncryptionAtRest *admin.EncryptionAtRest
}

func (pd *ProjectDependencies) Length() int {
return len(pd.NetworkPeering) + len(pd.AWSPrivateEndpoints) + len(pd.GCPPrivateEndpoints) + len(pd.AzurePrivateEndpoints) +
len(pd.Clusters) + len(pd.ServerlessClusters) + len(pd.FederatedDatabases)
len(pd.Clusters) + len(pd.ServerlessClusters) + len(pd.FederatedDBPrivateEndpoints) + len(pd.FederatedDatabases)
}

func (c *Cleaner) Clean(ctx context.Context, lifetimeHours int) error {
Expand Down
30 changes: 30 additions & 0 deletions tools/clean/atlas/data_federation_private_endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package atlas

import (
"context"
"fmt"

"github.com/jedib0t/go-pretty/v6/text"
"go.mongodb.org/atlas-sdk/v20231115008/admin"
)

func (c *Cleaner) listFederatedDBPrivateEndpoints(ctx context.Context, projectID string) []admin.PrivateNetworkEndpointIdEntry {
federatedDBPEs, _, err := c.client.DataFederationApi.ListDataFederationPrivateEndpoints(ctx, projectID).Execute()
if err != nil {
fmt.Println(text.FgRed.Sprintf("\tFailed to list federated databases for project %s: %s", projectID, err))

return nil
}

return federatedDBPEs.GetResults()
}

func (c *Cleaner) deleteFederatedDBPrivateEndpoints(ctx context.Context, projectID string, dbpes []admin.PrivateNetworkEndpointIdEntry) {
for _, fedDBPE := range dbpes {
_, _, err := c.client.DataFederationApi.DeleteDataFederationPrivateEndpoint(ctx, projectID, fedDBPE.GetEndpointId()).Execute()
if err != nil {
fmt.Println(text.FgRed.Sprintf("\t\t\tFailed to request deletion of Federated DB private endpoint %s: %s", fedDBPE.GetEndpointId(), err))
}
fmt.Println(text.FgBlue.Sprintf("\t\t\tRequested deletion of Federated DB private endpoint %s", fedDBPE.GetEndpointId()))
}
}
10 changes: 9 additions & 1 deletion tools/clean/atlas/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *Cleaner) GetProjectDependencies(ctx context.Context, projectID string,
}()

if !isGov {
wg.Add(4)
wg.Add(5)

go func() {
defer wg.Done()
Expand All @@ -95,6 +95,12 @@ func (c *Cleaner) GetProjectDependencies(ctx context.Context, projectID string,
deps.ServerlessClusters = c.listServerlessClusters(ctx, projectID)
}()

go func() {
defer wg.Done()

deps.FederatedDBPrivateEndpoints = c.listFederatedDBPrivateEndpoints(ctx, projectID)
}()

go func() {
defer wg.Done()

Expand All @@ -112,6 +118,8 @@ func (c *Cleaner) DeleteProjectDependencies(ctx context.Context, projectID strin

c.deleteServerlessClusters(ctx, projectID, deps.ServerlessClusters)

c.deleteFederatedDBPrivateEndpoints(ctx, projectID, deps.FederatedDBPrivateEndpoints)

c.deleteFederatedDatabases(ctx, projectID, deps.FederatedDatabases)

c.deleteEncryptionAtRest(ctx, projectID, deps.EncryptionAtRest)
Expand Down
Loading