44 "context"
55 "errors"
66 "fmt"
7- "net/http"
87
9- "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/atlas"
108 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/validate"
119
1210 "github.com/google/go-cmp/cmp"
@@ -27,10 +25,6 @@ import (
2725 mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
2826)
2927
30- var errArgIsNotBackupSchedule = errors .New ("failed to match resource type as AtlasBackupSchedule" )
31-
32- const BackupProtected = "unable to reconcile AtlasBackupSchedule due to deletion protection being enabled. see https://dochub.mongodb.org/core/ako-deletion-protection for further information"
33-
3428func (r * AtlasDeploymentReconciler ) ensureBackupScheduleAndPolicy (
3529 service * workflow.Context ,
3630 projectID string ,
@@ -70,44 +64,6 @@ func (r *AtlasDeploymentReconciler) ensureBackupScheduleAndPolicy(
7064 return r .updateBackupScheduleAndPolicy (service .Context , service , projectID , deployment , bSchedule , bPolicy )
7165}
7266
73- func backupScheduleManagedByAtlas (ctx context.Context , atlasClient mongodbatlas.Client , projectID string , deployment * mdbv1.AtlasDeployment , policy * mdbv1.AtlasBackupPolicy ) customresource.AtlasChecker {
74- return func (resource mdbv1.AtlasCustomResource ) (bool , error ) {
75- clusterName := deployment .GetDeploymentName ()
76-
77- backupSchedule , ok := resource .(* mdbv1.AtlasBackupSchedule )
78- if ! ok {
79- return false , errArgIsNotBackupSchedule
80- }
81-
82- atlasBS , _ , err := atlasClient .CloudProviderSnapshotBackupPolicies .Get (ctx , projectID , clusterName )
83- if err != nil {
84- var apiError * mongodbatlas.ErrorResponse
85- if errors .As (err , & apiError ) && (apiError .ErrorCode == atlas .ResourceNotFound || apiError .HTTPCode == http .StatusNotFound ) {
86- return false , nil
87- }
88-
89- return false , err
90- }
91-
92- operatorBS := backupSchedule .ToAtlas (atlasBS .ClusterID , clusterName , deployment .GetReplicationSetID (), policy )
93- if err != nil {
94- return false , err
95- }
96- if len (operatorBS .Policies ) != len (atlasBS .Policies ) {
97- return false , nil
98- }
99- if len (atlasBS .Policies ) != 0 && len (operatorBS .Policies ) != 0 {
100- operatorBS .Policies [0 ].ID = atlasBS .Policies [0 ].ID
101- }
102-
103- isSame , err := backupSchedulesAreEqual (atlasBS , operatorBS )
104- if err != nil {
105- return true , nil
106- }
107- return ! isSame , nil
108- }
109- }
110-
11167func (r * AtlasDeploymentReconciler ) ensureBackupSchedule (
11268 service * workflow.Context ,
11369 deployment * mdbv1.AtlasDeployment ,
@@ -243,14 +199,6 @@ func (r *AtlasDeploymentReconciler) updateBackupScheduleAndPolicy(
243199
244200 r .Log .Debugf ("successfully received backup configuration: %v" , currentSchedule )
245201
246- owner , err := customresource .IsOwner (bSchedule , r .ObjectDeletionProtection , customresource .IsResourceManagedByOperator , backupScheduleManagedByAtlas (ctx , service .Client , projectID , deployment , bPolicy ))
247- if err != nil {
248- return err
249- }
250-
251- if ! owner {
252- return fmt .Errorf (BackupProtected )
253- }
254202 r .Log .Debugf ("updating backup configuration for the atlas deployment: %v" , clusterName )
255203
256204 apiScheduleReq := bSchedule .ToAtlas (currentSchedule .ClusterID , clusterName , deployment .GetReplicationSetID (), bPolicy )
0 commit comments