Skip to content

Commit

Permalink
drclusters: ensure the spec fencestate field matches with expected
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavendra Talur <[email protected]>
(cherry picked from commit 97ad661)
  • Loading branch information
raghavendra-talur committed Oct 30, 2023
1 parent 9adf856 commit 3646118
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions controllers/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,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 {
Expand Down Expand Up @@ -474,6 +474,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")
Expand Down Expand Up @@ -540,6 +545,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")
Expand Down
8 changes: 8 additions & 0 deletions controllers/drcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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
Expand Down

0 comments on commit 3646118

Please sign in to comment.