diff --git a/addons/agent_mirrorpeer_controller.go b/addons/agent_mirrorpeer_controller.go index a85b2dce..07e479d1 100644 --- a/addons/agent_mirrorpeer_controller.go +++ b/addons/agent_mirrorpeer_controller.go @@ -417,11 +417,12 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust return err } + if sc.Spec.Mirroring == nil { + sc.Spec.Mirroring = &ocsv1.MirroringSpec{} + } + // 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 @@ -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 r.Logger.Info("Mirroring disabled on StorageCluster", "storageClusterName", storageClusterName) } diff --git a/addons/agent_mirrorpeer_controller_test.go b/addons/agent_mirrorpeer_controller_test.go index 3a8847de..38052a97 100644 --- a/addons/agent_mirrorpeer_controller_test.go +++ b/addons/agent_mirrorpeer_controller_test.go @@ -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") } }