From c9858432a24546a8486918780b9fae4dd1049a9b Mon Sep 17 00:00:00 2001 From: Elena Gershkovich Date: Tue, 21 May 2024 19:04:13 +0300 Subject: [PATCH 1/3] Use peer cluster name as namespace in NF manifest name Signed-off-by: Elena Gershkovich (cherry picked from commit 161b3d00f010c775f06ccdfe1198b3ddd5158bd8) --- controllers/drcluster_controller.go | 2 +- controllers/util/mw_util.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/drcluster_controller.go b/controllers/drcluster_controller.go index a2ac2825b..65bb307c5 100644 --- a/controllers/drcluster_controller.go +++ b/controllers/drcluster_controller.go @@ -1320,7 +1320,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") diff --git a/controllers/util/mw_util.go b/controllers/util/mw_util.go index 878cd4161..f2e4dd6aa 100644 --- a/controllers/util/mw_util.go +++ b/controllers/util/mw_util.go @@ -228,10 +228,10 @@ 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 } @@ -239,7 +239,7 @@ func (mwu *MWUtil) CreateOrUpdateNFManifestWork( 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) @@ -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 From 927213d0f2a10c66c9e0b3bca7a0d308110d6c29 Mon Sep 17 00:00:00 2001 From: Elena Gershkovich Date: Wed, 22 May 2024 15:39:00 +0300 Subject: [PATCH 2/3] DeleteManifestWork returns nil when MW was not found Signed-off-by: Elena Gershkovich (cherry picked from commit 716c02de0e877ca667aa7d7c9e7a450dfa168b3e) --- controllers/drcluster_controller.go | 42 ----------------------------- 1 file changed, 42 deletions(-) diff --git a/controllers/drcluster_controller.go b/controllers/drcluster_controller.go index 65bb307c5..39578fd93 100644 --- a/controllers/drcluster_controller.go +++ b/controllers/drcluster_controller.go @@ -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 } From 1287f192d4bfd52ef1bf66f6c47de0487368d0a6 Mon Sep 17 00:00:00 2001 From: Elena Gershkovich Date: Thu, 23 May 2024 16:13:54 +0530 Subject: [PATCH 3/3] Adjust tests for deletion of NF MW after unfence Signed-off-by: Elena Gershkovich (cherry picked from commit 383a85d582299e95907ef32c9805f38ec72acc88) --- controllers/drplacementcontrol_controller_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/drplacementcontrol_controller_test.go b/controllers/drplacementcontrol_controller_test.go index a7d0b9feb..cdabcbafd 100644 --- a/controllers/drplacementcontrol_controller_test.go +++ b/controllers/drplacementcontrol_controller_test.go @@ -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} @@ -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