Skip to content
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
52 changes: 0 additions & 52 deletions pkg/controller/atlasdeployment/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/atlas"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/validate"

"github.com/google/go-cmp/cmp"
Expand All @@ -27,10 +25,6 @@ import (
mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
)

var errArgIsNotBackupSchedule = errors.New("failed to match resource type as AtlasBackupSchedule")

const BackupProtected = "unable to reconcile AtlasBackupSchedule due to deletion protection being enabled. see https://dochub.mongodb.org/core/ako-deletion-protection for further information"

func (r *AtlasDeploymentReconciler) ensureBackupScheduleAndPolicy(
service *workflow.Context,
projectID string,
Expand Down Expand Up @@ -70,44 +64,6 @@ func (r *AtlasDeploymentReconciler) ensureBackupScheduleAndPolicy(
return r.updateBackupScheduleAndPolicy(service.Context, service, projectID, deployment, bSchedule, bPolicy)
}

func backupScheduleManagedByAtlas(ctx context.Context, atlasClient mongodbatlas.Client, projectID string, deployment *mdbv1.AtlasDeployment, policy *mdbv1.AtlasBackupPolicy) customresource.AtlasChecker {
return func(resource mdbv1.AtlasCustomResource) (bool, error) {
clusterName := deployment.GetDeploymentName()

backupSchedule, ok := resource.(*mdbv1.AtlasBackupSchedule)
if !ok {
return false, errArgIsNotBackupSchedule
}

atlasBS, _, err := atlasClient.CloudProviderSnapshotBackupPolicies.Get(ctx, projectID, clusterName)
if err != nil {
var apiError *mongodbatlas.ErrorResponse
if errors.As(err, &apiError) && (apiError.ErrorCode == atlas.ResourceNotFound || apiError.HTTPCode == http.StatusNotFound) {
return false, nil
}

return false, err
}

operatorBS := backupSchedule.ToAtlas(atlasBS.ClusterID, clusterName, deployment.GetReplicationSetID(), policy)
if err != nil {
return false, err
}
if len(operatorBS.Policies) != len(atlasBS.Policies) {
return false, nil
}
if len(atlasBS.Policies) != 0 && len(operatorBS.Policies) != 0 {
operatorBS.Policies[0].ID = atlasBS.Policies[0].ID
}

isSame, err := backupSchedulesAreEqual(atlasBS, operatorBS)
if err != nil {
return true, nil
}
return !isSame, nil
}
}

func (r *AtlasDeploymentReconciler) ensureBackupSchedule(
service *workflow.Context,
deployment *mdbv1.AtlasDeployment,
Expand Down Expand Up @@ -243,14 +199,6 @@ func (r *AtlasDeploymentReconciler) updateBackupScheduleAndPolicy(

r.Log.Debugf("successfully received backup configuration: %v", currentSchedule)

owner, err := customresource.IsOwner(bSchedule, r.ObjectDeletionProtection, customresource.IsResourceManagedByOperator, backupScheduleManagedByAtlas(ctx, service.Client, projectID, deployment, bPolicy))
if err != nil {
return err
}

if !owner {
return fmt.Errorf(BackupProtected)
}
r.Log.Debugf("updating backup configuration for the atlas deployment: %v", clusterName)

apiScheduleReq := bSchedule.ToAtlas(currentSchedule.ClusterID, clusterName, deployment.GetReplicationSetID(), bPolicy)
Expand Down
Loading