Skip to content

Commit

Permalink
Support deletion protection for Atlas projects
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs committed Jul 12, 2023
1 parent d44d490 commit 1f1f6ad
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 131 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 @@ -129,7 +129,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 @@ -272,16 +272,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 1f1f6ad

Please sign in to comment.