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-175080: Support deletion protection for Atlas projects #1028

Merged
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
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