Skip to content

Commit

Permalink
CLOUDP-175080: Support deletion protection for Atlas projects (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs authored and josvazg committed Aug 2, 2023
1 parent 0d903e7 commit 5f99ca2
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 134 deletions.
18 changes: 10 additions & 8 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ func main() {
}

if err = (&atlasproject.AtlasProjectReconciler{
Client: mgr.GetClient(),
Log: logger.Named("controllers").Named("AtlasProject").Sugar(),
Scheme: mgr.GetScheme(),
AtlasDomain: config.AtlasDomain,
ResourceWatcher: watch.NewResourceWatcher(),
GlobalAPISecret: config.GlobalAPISecret,
GlobalPredicates: globalPredicates,
EventRecorder: mgr.GetEventRecorderFor("AtlasProject"),
Client: mgr.GetClient(),
Log: logger.Named("controllers").Named("AtlasProject").Sugar(),
Scheme: mgr.GetScheme(),
AtlasDomain: config.AtlasDomain,
ResourceWatcher: watch.NewResourceWatcher(),
GlobalAPISecret: config.GlobalAPISecret,
GlobalPredicates: globalPredicates,
EventRecorder: mgr.GetEventRecorderFor("AtlasProject"),
ObjectDeletionProtection: config.ObjectDeletionProtection,
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AtlasProject")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/atlasproject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ func (p *AtlasProject) WithLabels(labels map[string]string) *AtlasProject {
return p
}

func (p *AtlasProject) WithAnnotations(labels map[string]string) *AtlasProject {
p.Labels = labels
func (p *AtlasProject) WithAnnotations(annotations map[string]string) *AtlasProject {
p.Annotations = annotations
return p
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 1 addition & 14 deletions pkg/controller/atlasdatabaseuser/atlasdatabaseuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *AtlasDatabaseUserReconciler) Reconcile(ctx context.Context, req ctrl.Re
}
workflowCtx.Client = atlasClient

owner, err := customresource.IsOwner(databaseUser, r.ObjectDeletionProtection, managedByOperator(), managedByAtlas(ctx, atlasClient, project.ID(), log))
owner, err := customresource.IsOwner(databaseUser, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, managedByAtlas(ctx, atlasClient, project.ID(), log))
if err != nil {
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("enable to resolve ownership for deletion protection: %s", err))
workflowCtx.SetConditionFromResult(status.DatabaseUserReadyType, result)
Expand Down Expand Up @@ -274,16 +274,3 @@ func managedByAtlas(ctx context.Context, atlasClient mongodbatlas.Client, projec
return !isSame, nil
}
}

func managedByOperator() customresource.OperatorChecker {
return func(resource mdbv1.AtlasCustomResource) (bool, error) {
annotations := resource.GetAnnotations()
if annotations == nil {
return false, nil
}

_, ok := annotations[customresource.AnnotationLastAppliedConfiguration]

return ok, nil
}
}
Loading

0 comments on commit 5f99ca2

Please sign in to comment.