From 546eec14e1522fd7d7df0bed3893a5dfd4cacb06 Mon Sep 17 00:00:00 2001 From: vbadrina Date: Wed, 18 Dec 2024 11:13:14 +0530 Subject: [PATCH] Set Mirroring field to false than setting it to nil Signed-off-by: vbadrina --- addons/agent_mirrorpeer_controller.go | 9 +++++---- addons/agent_mirrorpeer_controller_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) 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") } }