From 4937b1cc61c8562b90e0afe7d8f04b6fcc5cef86 Mon Sep 17 00:00:00 2001 From: Gowtham Shanmugasundaram Date: Tue, 26 Nov 2024 14:24:21 +0530 Subject: [PATCH] Initialize Mirroring spec to avoid nil pointer exception Signed-off-by: Gowtham Shanmugasundaram --- addons/agent_mirrorpeer_controller.go | 3 +++ addons/rook_secret_handler.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/addons/agent_mirrorpeer_controller.go b/addons/agent_mirrorpeer_controller.go index b24048f3..e000d63a 100644 --- a/addons/agent_mirrorpeer_controller.go +++ b/addons/agent_mirrorpeer_controller.go @@ -373,6 +373,9 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust } // Determine if mirroring should be enabled or disabled + if sc.Spec.Mirroring == nil { + sc.Spec.Mirroring = &ocsv1.MirroringSpec{} + } if enabled { oppPeers := getOppositePeerRefs(mp, r.SpokeClusterName) if hasRequiredSecret(sc.Spec.Mirroring.PeerSecretNames, oppPeers) { diff --git a/addons/rook_secret_handler.go b/addons/rook_secret_handler.go index b50ef29a..375eccd8 100644 --- a/addons/rook_secret_handler.go +++ b/addons/rook_secret_handler.go @@ -197,6 +197,9 @@ func updateStorageCluster(secretName, storageClusterName, storageClusterNamespac } // Update secret name + if sc.Spec.Mirroring == nil { + sc.Spec.Mirroring = &ocsv1.MirroringSpec{} + } if !utils.ContainsString(sc.Spec.Mirroring.PeerSecretNames, secretName) { sc.Spec.Mirroring.PeerSecretNames = append(sc.Spec.Mirroring.PeerSecretNames, secretName) err := spokeClient.Update(ctx, sc)