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 2246638: DRCluster does not clear its condition after it is unfenced #295

Open
wants to merge 3 commits into
base: release-4.16
Choose a base branch
from
Open
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
44 changes: 1 addition & 43 deletions controllers/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,51 +926,9 @@ func (u *drclusterInstance) removeFencingCR(cluster ramen.DRCluster) (bool, erro
err := u.mwUtil.DeleteManifestWork(fmt.Sprintf(util.ManifestWorkNameFormat,
u.object.Name, cluster.Name, util.MWTypeNF), cluster.Name)
if err != nil {
if errors.IsNotFound(err) {
return u.ensureNetworkFenceDeleted(cluster.Name)
}

return true, fmt.Errorf("failed to delete NetworkFence resource from cluster %s", cluster.Name)
}

setDRClusterCleaningCondition(&u.object.Status.Conditions, u.object.Generation, "NetworkFence resource clean started")

// Since ManifestWork for the fencing CR delete request
// has been just issued, requeue is needed to ensure that
// the fencing CR has indeed been deleted from the cluster.
return true, nil
}

func (u *drclusterInstance) ensureNetworkFenceDeleted(clusterName string) (bool, error) {
annotations := make(map[string]string)
annotations[DRClusterNameAnnotation] = u.object.Name

if _, err := u.reconciler.MCVGetter.GetNFFromManagedCluster(u.object.Name,
u.object.Namespace, clusterName, annotations); err != nil {
if errors.IsNotFound(err) {
return u.deleteNFMCV(clusterName)
}

return true, fmt.Errorf("failed to get MCV for NetworkFence on %s (%w)", clusterName, err)
}

// We are here means, successfully NetworkFence MCV is obtained. Hence
// we need to wait for NetworkFence deletion to complete. Requeue.
return true, nil
}

func (u *drclusterInstance) deleteNFMCV(clusterName string) (bool, error) {
mcvNameNF := util.BuildManagedClusterViewName(u.object.Name, u.object.Namespace, util.MWTypeNF)

err := u.reconciler.MCVGetter.DeleteNFManagedClusterView(u.object.Name, u.object.Namespace, clusterName, mcvNameNF)
if err != nil {
u.log.Info("Failed to delete the MCV for NetworkFence")

return true, fmt.Errorf("failed to delete MCV for NetworkFence %w", err)
}

u.log.Info("Deleted the MCV for NetworkFence")
// successfully deleted the MCV for NetworkFence. No need to requeue
return false, nil
}

Expand Down Expand Up @@ -1320,7 +1278,7 @@ func (u *drclusterInstance) createNFManifestWork(targetCluster *ramen.DRCluster,
annotations[DRClusterNameAnnotation] = u.object.Name

if err := u.mwUtil.CreateOrUpdateNFManifestWork(
u.object.Name, u.object.Namespace,
u.object.Name,
peerCluster.Name, nf, annotations); err != nil {
log.Error(err, "failed to create or update NetworkFence manifest")

Expand Down
12 changes: 8 additions & 4 deletions controllers/drplacementcontrol_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,12 +1467,16 @@ func runFailoverAction(placementObj client.Object, fromCluster, toCluster string
// resource is cleaned up or not, number of MW may change.
if !isSyncDR {
Expect(getManifestWorkCount(toCluster)).Should(BeElementOf(3, 4)) // MW for VRG+DRCluster+NS
Expect(getManifestWorkCount(fromCluster)).Should(Equal(2)) // DRCluster + NS MW
} else {
Expect(getManifestWorkCount(toCluster)).Should(Equal(4)) // MW for VRG+DRCluster + NS + NF
Expect(getManifestWorkCount(fromCluster)).Should(Equal(2)) // NS + DRCluster MW
if manualFence {
Expect(getManifestWorkCount(toCluster)).Should(Equal(3)) // MW for VRG+DRCluster + NS
} else {
Expect(getManifestWorkCount(toCluster)).Should(Equal(4)) // MW for VRG+DRCluster + NS + NF
}
}

Expect(getManifestWorkCount(fromCluster)).Should(Equal(2)) // DRCluster + NS MW

drpc := getLatestDRPC(placementObj.GetNamespace())
// At this point expect the DRPC status condition to have 2 types
// {Available and PeerReady}
Expand Down Expand Up @@ -1700,7 +1704,7 @@ func verifyFailoverToSecondary(placementObj client.Object, toCluster string,
// MW for VRG+NS+DRCluster
Eventually(getManifestWorkCount, timeout, interval).WithArguments(toCluster).Should(BeElementOf(3, 4))
} else {
Expect(getManifestWorkCount(toCluster)).Should(Equal(4)) // MW for VRG+NS+DRCluster+NF
Expect(getManifestWorkCount(toCluster)).Should(BeElementOf(3, 4)) // MW for VRG+NS+DRCluster+NF
}

Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRClustern+NS
Expand Down
8 changes: 4 additions & 4 deletions controllers/util/mw_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,18 @@ func ExtractMModeFromManifestWork(mw *ocmworkv1.ManifestWork) (*rmn.MaintenanceM

// NetworkFence MW creation
func (mwu *MWUtil) CreateOrUpdateNFManifestWork(
name, namespace, homeCluster string,
name, homeCluster string,
nf csiaddonsv1alpha1.NetworkFence, annotations map[string]string,
) error {
manifestWork, err := mwu.generateNFManifestWork(name, namespace, homeCluster, nf, annotations)
manifestWork, err := mwu.generateNFManifestWork(name, homeCluster, nf, annotations)
if err != nil {
return err
}

return mwu.createOrUpdateManifestWork(manifestWork, homeCluster)
}

func (mwu *MWUtil) generateNFManifestWork(name, namespace, homeCluster string,
func (mwu *MWUtil) generateNFManifestWork(name, homeCluster string,
nf csiaddonsv1alpha1.NetworkFence, annotations map[string]string,
) (*ocmworkv1.ManifestWork, error) {
nfClientManifest, err := mwu.generateNFManifest(nf)
Expand All @@ -257,7 +257,7 @@ func (mwu *MWUtil) generateNFManifestWork(name, namespace, homeCluster string,
// that wants to create the csiaddonsv1alpha1.NetworkFence resource
// type: type of the resource for this ManifestWork
return mwu.newManifestWork(
fmt.Sprintf(ManifestWorkNameFormat, name, namespace, MWTypeNF),
fmt.Sprintf(ManifestWorkNameFormat, name, homeCluster, MWTypeNF),
homeCluster,
map[string]string{"app": "NF"},
manifests, annotations), nil
Expand Down
Loading