From aaf3e935b14d473621476abb519a016d11ea90d0 Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Fri, 27 Oct 2023 12:32:00 -0400 Subject: [PATCH] drclusters: ensure the spec fencestate field matches with expected Signed-off-by: Raghavendra Talur (cherry picked from commit 97ad661b955e52d758283292592a010a22f35bdd) --- controllers/drcluster_controller.go | 14 ++++++++++++-- controllers/drcluster_controller_test.go | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/drcluster_controller.go b/controllers/drcluster_controller.go index f6bd11016..1924878ea 100644 --- a/controllers/drcluster_controller.go +++ b/controllers/drcluster_controller.go @@ -641,8 +641,8 @@ func (u *drclusterInstance) clusterUnfence() (bool, error) { requeue, err := u.unfenceClusterOnCluster(&peerCluster) if err != nil { - return requeue, fmt.Errorf("unfence operation to fence off cluster %s on cluster %s failed", - u.object.Name, peerCluster.Name) + return requeue, fmt.Errorf("unfence operation to unfence cluster %s on cluster %s failed: %w", + u.object.Name, peerCluster.Name, err) } if requeue { @@ -705,6 +705,11 @@ func (u *drclusterInstance) fenceClusterOnCluster(peerCluster *ramen.DRCluster) return true, fmt.Errorf("failed to get NetworkFence using MCV (error: %w)", err) } + if nf.Spec.FenceState != csiaddonsv1alpha1.FenceState(u.object.Spec.ClusterFence) { + return true, fmt.Errorf("fence state in the NetworkFence resource is not changed to %v yet", + u.object.Spec.ClusterFence) + } + if nf.Status.Result != csiaddonsv1alpha1.FencingOperationResultSucceeded { setDRClusterFencingFailedCondition(&u.object.Status.Conditions, u.object.Generation, "fencing operation not successful") @@ -771,6 +776,11 @@ func (u *drclusterInstance) unfenceClusterOnCluster(peerCluster *ramen.DRCluster return true, fmt.Errorf("failed to get NetworkFence using MCV (error: %w", err) } + if nf.Spec.FenceState != csiaddonsv1alpha1.FenceState(u.object.Spec.ClusterFence) { + return true, fmt.Errorf("fence state in the NetworkFence resource is not changed to %v yet", + u.object.Spec.ClusterFence) + } + if nf.Status.Result != csiaddonsv1alpha1.FencingOperationResultSucceeded { setDRClusterUnfencingFailedCondition(&u.object.Status.Conditions, u.object.Generation, "unfencing operation not successful") diff --git a/controllers/drcluster_controller_test.go b/controllers/drcluster_controller_test.go index b9b2a0039..d6775d307 100644 --- a/controllers/drcluster_controller_test.go +++ b/controllers/drcluster_controller_test.go @@ -43,6 +43,14 @@ func (f FakeMCVGetter) GetNFFromManagedCluster(resourceName, resourceNamespace, } nf := baseNF.DeepCopy() + + callerName := getFunctionNameAtIndex(2) + if callerName == "fenceClusterOnCluster" { + nf.Spec.FenceState = csiaddonsv1alpha1.Fenced + } else if callerName == "unfenceClusterOnCluster" { + nf.Spec.FenceState = csiaddonsv1alpha1.Unfenced + } + nf.Status = nfStatus nf.Generation = 1