Skip to content

Commit 145b35e

Browse files
authored
CLOUDP-229283: disable ownership detection (#1371)
* test/e2e: remove ownership detection e2e tests * pkg/controller: disable ownership detection * cmd/manager: deprecate subobject deletion flag, add event and log notifications
1 parent d3a3142 commit 145b35e

12 files changed

+24
-980
lines changed

cmd/manager/main.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const (
6464
objectDeletionProtectionEnvVar = "OBJECT_DELETION_PROTECTION"
6565
subobjectDeletionProtectionEnvVar = "SUBOBJECT_DELETION_PROTECTION"
6666
objectDeletionProtectionDefault = true
67-
subobjectDeletionProtectionDefault = true
67+
subobjectDeletionProtectionDefault = false
68+
subobjectDeletionProtectionMessage = "Note: sub-object deletion protection is IGNORED because it does not work deterministically."
6869
)
6970

7071
var (
@@ -147,7 +148,7 @@ func main() {
147148
EventRecorder: mgr.GetEventRecorderFor("AtlasDeployment"),
148149
AtlasProvider: atlasProvider,
149150
ObjectDeletionProtection: config.ObjectDeletionProtection,
150-
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
151+
SubObjectDeletionProtection: false,
151152
}).SetupWithManager(mgr); err != nil {
152153
setupLog.Error(err, "unable to create controller", "controller", "AtlasDeployment")
153154
os.Exit(1)
@@ -162,7 +163,7 @@ func main() {
162163
EventRecorder: mgr.GetEventRecorderFor("AtlasProject"),
163164
AtlasProvider: atlasProvider,
164165
ObjectDeletionProtection: config.ObjectDeletionProtection,
165-
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
166+
SubObjectDeletionProtection: false,
166167
}).SetupWithManager(mgr); err != nil {
167168
setupLog.Error(err, "unable to create controller", "controller", "AtlasProject")
168169
os.Exit(1)
@@ -177,7 +178,7 @@ func main() {
177178
AtlasProvider: atlasProvider,
178179
GlobalPredicates: globalPredicates,
179180
ObjectDeletionProtection: config.ObjectDeletionProtection,
180-
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
181+
SubObjectDeletionProtection: false,
181182
FeaturePreviewOIDCAuthEnabled: config.FeatureFlags.IsFeaturePresent(featureflags.FeatureOIDC),
182183
}).SetupWithManager(mgr); err != nil {
183184
setupLog.Error(err, "unable to create controller", "controller", "AtlasDatabaseUser")
@@ -193,7 +194,7 @@ func main() {
193194
EventRecorder: mgr.GetEventRecorderFor("AtlasDataFederation"),
194195
AtlasProvider: atlasProvider,
195196
ObjectDeletionProtection: config.ObjectDeletionProtection,
196-
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
197+
SubObjectDeletionProtection: false,
197198
}).SetupWithManager(mgr); err != nil {
198199
setupLog.Error(err, "unable to create controller", "controller", "AtlasDataFederation")
199200
os.Exit(1)
@@ -208,7 +209,7 @@ func main() {
208209
EventRecorder: mgr.GetEventRecorderFor("AtlasFederatedAuth"),
209210
AtlasProvider: atlasProvider,
210211
ObjectDeletionProtection: config.ObjectDeletionProtection,
211-
SubObjectDeletionProtection: config.SubObjectDeletionProtection,
212+
SubObjectDeletionProtection: false,
212213
}).SetupWithManager(mgr); err != nil {
213214
setupLog.Error(err, "unable to create controller", "controller", "AtlasFederatedAuth")
214215
os.Exit(1)
@@ -225,6 +226,7 @@ func main() {
225226
os.Exit(1)
226227
}
227228

229+
setupLog.Info(subobjectDeletionProtectionMessage)
228230
setupLog.Info("starting manager")
229231
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
230232
setupLog.Error(err, "problem running manager")
@@ -264,7 +266,7 @@ func parseConfiguration() Config {
264266
flag.BoolVar(&config.ObjectDeletionProtection, objectDeletionProtectionFlag, objectDeletionProtectionDefault, "Defines if the operator deletes Atlas resource "+
265267
"when a Custom Resource is deleted")
266268
flag.BoolVar(&config.SubObjectDeletionProtection, subobjectDeletionProtectionFlag, subobjectDeletionProtectionDefault, "Defines if the operator overwrites "+
267-
"(and consequently delete) subresources that were not previously created by the operator")
269+
"(and consequently delete) subresources that were not previously created by the operator. "+subobjectDeletionProtectionMessage)
268270
appVersion := flag.Bool("v", false, "prints application version")
269271
flag.Parse()
270272

cmd/manager/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Test_configureDeletionProtection(t *testing.T) {
3434
t,
3535
Config{
3636
ObjectDeletionProtection: true,
37-
SubObjectDeletionProtection: true,
37+
SubObjectDeletionProtection: false,
3838
},
3939
config,
4040
)

pkg/controller/atlasdatabaseuser/atlasdatabaseuser_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ func (r *AtlasDatabaseUserReconciler) Reconcile(ctx context.Context, req ctrl.Re
133133
workflowCtx.OrgID = orgID
134134
workflowCtx.Client = atlasClient
135135

136-
owner, err := customresource.IsOwner(databaseUser, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, managedByAtlas(ctx, atlasClient, project.ID(), log))
136+
// Setting protection flag to static false because ownership detection is disabled.
137+
owner, err := customresource.IsOwner(databaseUser, false, customresource.IsResourceManagedByOperator, managedByAtlas(ctx, atlasClient, project.ID(), log))
137138
if err != nil {
138139
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("enable to resolve ownership for deletion protection: %s", err))
139140
workflowCtx.SetConditionFromResult(status.DatabaseUserReadyType, result)

pkg/controller/atlasdatafederation/datafederation_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ func (r *AtlasDataFederationReconciler) Reconcile(context context.Context, req c
104104
ctx.OrgID = orgID
105105
ctx.Client = atlasClient
106106

107-
owner, err := customresource.IsOwner(dataFederation, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, managedByAtlas(context, atlasClient, project.ID(), log))
107+
// Setting protection flag to static false because ownership detection is disabled.
108+
owner, err := customresource.IsOwner(dataFederation, false, customresource.IsResourceManagedByOperator, managedByAtlas(context, atlasClient, project.ID(), log))
108109
if err != nil {
109110
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("unable to resolve ownership for deletion protection: %s", err))
110111
ctx.SetConditionFromResult(status.DataFederationReadyType, result)

pkg/controller/atlasdeployment/atlasdeployment_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ func (r *AtlasDeploymentReconciler) checkDeploymentIsManaged(
225225
project *mdbv1.AtlasProject,
226226
deployment *mdbv1.AtlasDeployment,
227227
) workflow.Result {
228+
// Setting protection flag to static false because ownership detection is disabled.
228229
owner, err := customresource.IsOwner(
229230
deployment,
230-
r.ObjectDeletionProtection,
231+
false,
231232
customresource.IsResourceManagedByOperator,
232233
managedByAtlas(workflowCtx, project.ID(), log),
233234
)

pkg/controller/atlasdeployment/atlasdeployment_controller_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ func TestProtectedAdvancedDeploymentManagedInAtlas(t *testing.T) {
119119
inAtlas: sameAdvancedDeployment(fakeDomain),
120120
expectedErr: "",
121121
},
122-
{
123-
title: "advanced deployment not tagged and different in Atlas means unmanaged",
124-
inAtlas: differentAdvancedDeployment(fakeDomain),
125-
expectedErr: "unable to reconcile Deployment due to deletion protection being enabled. see https://dochub.mongodb.org/core/ako-deletion-protection for further information",
126-
},
127122
}
128123
for _, tc := range testCases {
129124
t.Run(tc.title, func(t *testing.T) {
@@ -164,11 +159,6 @@ func TestProtectedServerlessManagedInAtlas(t *testing.T) {
164159
inAtlas: sameServerlessDeployment(fakeDomain),
165160
expectedErr: "",
166161
},
167-
{
168-
title: "serverless deployment not tagged and different in Atlas means unmanaged",
169-
inAtlas: differentServerlessDeployment(fakeDomain),
170-
expectedErr: "unable to reconcile Deployment due to deletion protection being enabled. see https://dochub.mongodb.org/core/ako-deletion-protection for further information",
171-
},
172162
}
173163
for _, tc := range testCases {
174164
t.Run(tc.title, func(t *testing.T) {
@@ -573,28 +563,13 @@ func TestCleanupBindings(t *testing.T) {
573563
})
574564
}
575565

576-
func differentAdvancedDeployment(ns string) *mongodbatlas.AdvancedCluster {
577-
project := testProject(ns)
578-
deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment)
579-
deployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M2"
580-
advancedSpec := deployment.Spec.DeploymentSpec
581-
return intoAdvancedAtlasCluster(advancedSpec)
582-
}
583-
584566
func sameAdvancedDeployment(ns string) *mongodbatlas.AdvancedCluster {
585567
project := testProject(ns)
586568
deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment)
587569
advancedSpec := deployment.Spec.DeploymentSpec
588570
return intoAdvancedAtlasCluster(advancedSpec)
589571
}
590572

591-
func differentServerlessDeployment(ns string) *mongodbatlas.Cluster {
592-
project := testProject(ns)
593-
deployment := v1.NewDefaultAWSServerlessInstance(project.Namespace, project.Name)
594-
deployment.Spec.ServerlessSpec.ProviderSettings.RegionName = "US_EAST_2"
595-
return intoServerlessAtlasCluster(deployment.Spec.ServerlessSpec)
596-
}
597-
598573
func sameServerlessDeployment(ns string) *mongodbatlas.Cluster {
599574
project := testProject(ns)
600575
deployment := v1.NewDefaultAWSServerlessInstance(project.Namespace, project.Name)

pkg/controller/atlasfederatedauth/atlasfederated_auth_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func (r *AtlasFederatedAuthReconciler) Reconcile(ctx context.Context, req ctrl.R
9292
workflowCtx.SdkClient = atlasClient
9393
workflowCtx.OrgID = orgID
9494

95-
owner, err := customresource.IsOwner(fedauth, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, managedByAtlas(ctx, atlasClient, orgID))
95+
// Setting protection flag to static false because ownership detection is disabled.
96+
owner, err := customresource.IsOwner(fedauth, false, customresource.IsResourceManagedByOperator, managedByAtlas(ctx, atlasClient, orgID))
9697
if err != nil {
9798
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("unable to resolve ownership for deletion protection: %s", err))
9899
workflowCtx.SetConditionFromResult(status.FederatedAuthReadyType, result)

pkg/controller/atlasfederatedauth/atlasfederated_auth_controller_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ func TestReconcile(t *testing.T) {
135135
groupAPI.EXPECT().ListProjects(context.Background()).
136136
Return(admin.ListProjectsApiRequest{ApiService: groupAPI})
137137
groupAPI.EXPECT().ListProjectsExecute(mock.Anything).
138-
Twice().
139138
Return(
140139
&admin.PaginatedAtlasGroup{
141140
Results: &[]admin.Group{

pkg/controller/atlasproject/atlasproject_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ func (r *AtlasProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request
148148
workflowCtx.OrgID = orgID
149149
workflowCtx.Client = atlasClient
150150

151-
owner, err := customresource.IsOwner(project, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, managedByAtlas(workflowCtx))
151+
// Setting protection flag to static false because ownership detection is disabled.
152+
owner, err := customresource.IsOwner(project, false, customresource.IsResourceManagedByOperator, managedByAtlas(workflowCtx))
152153
if err != nil {
153154
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("unable to resolve ownership for deletion protection: %s", err))
154155
workflowCtx.SetConditionFromResult(status.ProjectReadyType, result)

pkg/controller/atlasproject/team_reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (r *AtlasProjectReconciler) teamReconcile(
6666
teamCtx.OrgID = orgID
6767
teamCtx.Client = atlasClient
6868

69-
owner, err := customresource.IsOwner(team, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, teamsManagedByAtlas(teamCtx))
69+
owner, err := customresource.IsOwner(team, false, customresource.IsResourceManagedByOperator, teamsManagedByAtlas(teamCtx))
7070
if err != nil {
7171
result = workflow.Terminate(workflow.Internal, fmt.Sprintf("unable to resolve ownership for deletion protection: %s", err))
7272
teamCtx.SetConditionFromResult(status.ReadyType, result)

0 commit comments

Comments
 (0)