Skip to content

Commit

Permalink
Merge pull request #241 from GowthamShanmugam/fix_enable_mirroring
Browse files Browse the repository at this point in the history
Initialize Mirroring spec to avoid nil pointer exception
  • Loading branch information
openshift-merge-bot[bot] authored Nov 28, 2024
2 parents 1aeb02f + 5cf12a9 commit 4305a16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion addons/agent_mirrorpeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust

// 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 @@ -427,7 +430,7 @@ func (r *MirrorPeerReconciler) toggleMirroring(ctx context.Context, storageClust
return fmt.Errorf("StorageCluster %q does not have required PeerSecrets", storageClusterName)
}
} else {
sc.Spec.Mirroring.Enabled = false
sc.Spec.Mirroring = nil
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.Enabled {
if sc.Spec.Mirroring != nil {
t.Error("failed to disable mirroring")
}
}
Expand Down
3 changes: 3 additions & 0 deletions addons/rook_secret_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4305a16

Please sign in to comment.