Skip to content

Commit

Permalink
CLOUDP-186825: Add deletion protection to deployments
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Vazquez <jose.vazquez@mongodb.com>
  • Loading branch information
josvazg committed Aug 10, 2023
1 parent 7d95e9f commit 94bb692
Show file tree
Hide file tree
Showing 16 changed files with 1,191 additions and 95 deletions.
20 changes: 10 additions & 10 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ import (
)

const (
objectDeletionProtectionFlag = "object-deletion-protection"
subobjectDeletionProtectionFlag = "subobject-deletion-protection"
objectDeletionProtectionDefault = false
subobjectDeletionProtectionDefault = false

Expand Down Expand Up @@ -136,14 +134,16 @@ func main() {
}

if err = (&atlasdeployment.AtlasDeploymentReconciler{
Client: mgr.GetClient(),
Log: logger.Named("controllers").Named("AtlasDeployment").Sugar(),
Scheme: mgr.GetScheme(),
AtlasDomain: config.AtlasDomain,
GlobalAPISecret: config.GlobalAPISecret,
ResourceWatcher: watch.NewResourceWatcher(),
GlobalPredicates: globalPredicates,
EventRecorder: mgr.GetEventRecorderFor("AtlasDeployment"),
Client: mgr.GetClient(),
Log: logger.Named("controllers").Named("AtlasDeployment").Sugar(),
Scheme: mgr.GetScheme(),
AtlasDomain: config.AtlasDomain,
GlobalAPISecret: config.GlobalAPISecret,
ResourceWatcher: watch.NewResourceWatcher(),
GlobalPredicates: globalPredicates,
EventRecorder: mgr.GetEventRecorderFor("AtlasDeployment"),
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasDeployment")
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ github.com/aws/aws-sdk-go v1.44.318 h1:Yl66rpbQHFUbxe9JBKLcvOvRivhVgP6+zH0b9KzAR
github.com/aws/aws-sdk-go v1.44.318/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/v1/atlasdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ type ServerlessSpec struct {
PrivateEndpoints []ServerlessPrivateEndpoint `json:"privateEndpoints,omitempty"`
}

// ToAtlas converts the ServerlessSpec to native Atlas client Cluster format.
func (s *ServerlessSpec) ToAtlas() (*mongodbatlas.Cluster, error) {
result := &mongodbatlas.Cluster{}
err := compat.JSONCopy(result, s)
return result, err
}

// BiConnector specifies BI Connector for Atlas configuration on this deployment.
type BiConnector struct {
Enabled *bool `json:"enabled,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/atlas/api_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const (
// Error indicates that the cluster doesn't exist
ClusterNotFound = "CLUSTER_NOT_FOUND"

// ServerlessClusterNotFound indicates that the serverless cluster doesn't exist
ServerlessInstanceNotFound = "SERVERLESS_INSTANCE_NOT_FOUND"

// ServerlessClusterFromClusterAPI indicates that we are trying to access
// a serverless instance from the cluster API, which is not allowed
ServerlessInstanceFromClusterAPI = "CANNOT_USE_SERVERLESS_INSTANCE_IN_CLUSTER_API"

// Resource not found
ResourceNotFound = "RESOURCE_NOT_FOUND"
)
Loading

0 comments on commit 94bb692

Please sign in to comment.