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

Set Mirroring field to false than setting it to nil #250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions addons/agent_mirrorpeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust
return err
}

if sc.Spec.Mirroring == nil {
sc.Spec.Mirroring = &ocsv1.MirroringSpec{}
}
Comment on lines +420 to +422
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want to initialize it everytime.
We only want to initialize it when MCO is the one controlling the enable/disable of mirroring. That was the reason we moved the initialization under the if enabled { block.

@rewantsoni Since the mirroring spec is managed by 2 different controllers, I think we need to document how to work with this spec and the expected behavior.


// Determine if mirroring should be enabled or disabled
if enabled {
if sc.Spec.Mirroring == nil {
sc.Spec.Mirroring = &ocsv1.MirroringSpec{}
}
oppPeers := getOppositePeerRefs(mp, r.SpokeClusterName)
if hasRequiredSecret(sc.Spec.Mirroring.PeerSecretNames, oppPeers) {
sc.Spec.Mirroring.Enabled = true
Expand All @@ -430,7 +431,7 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust
return fmt.Errorf("StorageCluster %q does not have required PeerSecrets", storageClusterName)
}
} else {
sc.Spec.Mirroring = nil
sc.Spec.Mirroring.Enabled = false
Comment on lines -433 to +434
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set it to nil as we will no longer be managing this spec once mirroring is disabled.

r.Logger.Info("Mirroring disabled on StorageCluster", "storageClusterName", storageClusterName)
}

Expand Down
2 changes: 1 addition & 1 deletion addons/agent_mirrorpeer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestDisableMirroring(t *testing.T) {
t.Error("failed to get storage cluster", err)
}

if sc.Spec.Mirroring != nil {
if sc.Spec.Mirroring.Enabled {
t.Error("failed to disable mirroring")
}
}
Expand Down
Loading