Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 2247003: drclusters: ensure the spec fencestate field matches with expected #151

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions controllers/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
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 @@ -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
Expand Down
Loading