Skip to content

Commit

Permalink
Update unit tests to verify deletion of namespace manifestwork
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Shakya <[email protected]>
  • Loading branch information
abhijeet219 committed Aug 12, 2024
1 parent 2cec923 commit f0bdf1b
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions internal/controller/drplacementcontrol_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ func deleteUserPlacementRule(name, namespace string) {
Expect(k8sClient.Delete(context.TODO(), userPlacementRule)).Should(Succeed())
}

func deleteUserPlacement(name, namespace string) {
userPlacement := getLatestUserPlacement(name, namespace)
func deleteUserPlacement() {
userPlacement := getLatestUserPlacement(UserPlacementName, DefaultDRPCNamespace)
Expect(k8sClient.Delete(context.TODO(), userPlacement)).Should(Succeed())
}

Expand All @@ -701,7 +701,7 @@ func deleteDRPC() {
Expect(k8sClient.Delete(context.TODO(), drpc)).Should(Succeed())
}

func deleteNamespaceMWsFromAllClusters(namespace string) {
func ensureNamespaceMWsDeletedFromAllClusters(namespace string) {
foundMW := &ocmworkv1.ManifestWork{}
mwName := fmt.Sprintf(rmnutil.ManifestWorkNameFormat, DRPCCommonName, namespace, rmnutil.MWTypeNS)
err := k8sClient.Get(context.TODO(),
Expand Down Expand Up @@ -1245,6 +1245,7 @@ func verifyNSManifestWorkBackupLabelNotExist(resourceName, namespaceString, mana
Expect(err).NotTo(HaveOccurred())

Expect(mw).ToNot(BeNil())
Expect(mw.Spec.DeleteOption).ToNot(BeNil())
Expect(mw.Labels[rmnutil.OCMBackupLabelKey]).To(Equal(""))
}

Expand Down Expand Up @@ -1978,9 +1979,9 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
Expect(getManifestWorkCount(East1ManagedCluster)).Should(BeElementOf(3, 4)) // DRCluster + VRG MW
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster + NS MW only
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
Expect(getManagedClusterViewCount(East1ManagedCluster)).Should(Equal(0)) // NS + VRG MCV
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
})
It("should delete the DRPC causing its referenced drpolicy to be deleted"+
" by drpolicy controller since no DRPCs reference it anymore", func() {
Expand Down Expand Up @@ -2041,7 +2042,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
})
When("Deleting user Placement", func() {
It("Should cleanup DRPC", func() {
deleteUserPlacement(UserPlacementName, DefaultDRPCNamespace)
deleteUserPlacement()
drpc := getLatestDRPC(DefaultDRPCNamespace)
_, condition := getDRPCCondition(&drpc.Status, rmn.ConditionPeerReady)
Expect(condition).NotTo(BeNil())
Expand All @@ -2052,9 +2053,9 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
Expect(getManifestWorkCount(East1ManagedCluster)).Should(BeElementOf(3, 4)) // DRCluster + VRG + NS MW
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster + NS MW only
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
Expect(getManagedClusterViewCount(East1ManagedCluster)).Should(Equal(0)) // NS + VRG MCV
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
})
It("should delete the DRPC causing its referenced drpolicy to be deleted"+
" by drpolicy controller since no DRPCs reference it anymore", func() {
Expand Down Expand Up @@ -2129,7 +2130,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
})
When("Deleting user Placement", func() {
It("Should cleanup DRPC", func() {
deleteUserPlacement(UserPlacementName, DefaultDRPCNamespace)
deleteUserPlacement()
drpc := getLatestDRPC(DefaultDRPCNamespace)
_, condition := getDRPCCondition(&drpc.Status, rmn.ConditionPeerReady)
Expect(condition).NotTo(BeNil())
Expand All @@ -2140,9 +2141,9 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
Expect(getManifestWorkCount(East1ManagedCluster)).Should(BeElementOf(3, 4)) // DRCluster + VRG + NS MW
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster + NS MW only
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
Expect(getManagedClusterViewCount(East1ManagedCluster)).Should(Equal(0)) // NS + VRG MCV
deleteNamespaceMWsFromAllClusters(ApplicationNamespace)
ensureNamespaceMWsDeletedFromAllClusters(ApplicationNamespace)
deleteAppSet()
UseApplicationSet = false
})
Expand Down Expand Up @@ -2224,7 +2225,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
By("\n\n*** DELETE DRPC ***\n\n")
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster+NS MW
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
deleteDRPolicySync()
deleteDRClustersSync()
})
Expand Down Expand Up @@ -2295,17 +2296,16 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
Expect(getManifestWorkCount(East1ManagedCluster)).Should(BeElementOf(3, 4)) // DRCluster + NS + VRG MW
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster + NS MW
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
deleteDRPolicySync()
deleteDRClustersSync()
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
})
})
})

Context("DRPlacementControl Reconciler HubRecovery (Subscription)", func() {
var userPlacementRule1 *plrv1.PlacementRule
var drpc1 *rmn.DRPlacementControl

Specify("DRClusters", func() {
populateDRClusters()
Expand All @@ -2318,7 +2318,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
createDRPolicyAsync()

var placementObj client.Object
placementObj, drpc1 = CreatePlacementAndDRPC(
placementObj, _ = CreatePlacementAndDRPC(
DefaultDRPCNamespace, UserPlacementRuleName, East1ManagedCluster, UsePlacementRule)
userPlacementRule1 = placementObj.(*plrv1.PlacementRule)
Expect(userPlacementRule1).NotTo(BeNil())
Expand Down Expand Up @@ -2508,8 +2508,9 @@ var _ = Describe("DRPlacementControl Reconciler", func() {

When("Deleting DRPC", func() {
It("Should delete all VRGs", func() {
Expect(k8sClient.Delete(context.TODO(), drpc1)).Should(Succeed())
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
deleteDRPC()
waitForCompletion("deleted")
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
})
})
Specify("delete drclusters", func() {
Expand All @@ -2519,7 +2520,6 @@ var _ = Describe("DRPlacementControl Reconciler", func() {

Context("DRPlacementControl Reconciler HubRecovery VRG Adoption (Subscription)", func() {
var userPlacementRule1 *plrv1.PlacementRule
var drpc1 *rmn.DRPlacementControl

Specify("DRClusters", func() {
populateDRClusters()
Expand All @@ -2538,7 +2538,7 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
createVRGMW(DRPCCommonName, DefaultDRPCNamespace, East1ManagedCluster)

var placementObj client.Object
placementObj, drpc1 = CreatePlacementAndDRPC(
placementObj, _ = CreatePlacementAndDRPC(
DefaultDRPCNamespace, UserPlacementRuleName, East1ManagedCluster, UsePlacementRule)
userPlacementRule1 = placementObj.(*plrv1.PlacementRule)
Expect(userPlacementRule1).NotTo(BeNil())
Expand All @@ -2564,8 +2564,9 @@ var _ = Describe("DRPlacementControl Reconciler", func() {

When("Deleting DRPC", func() {
It("Should delete all VRGs", func() {
Expect(k8sClient.Delete(context.TODO(), drpc1)).Should(Succeed())
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
deleteDRPC()
waitForCompletion("deleted")
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
})
})

Expand Down Expand Up @@ -2604,12 +2605,12 @@ var _ = Describe("DRPlacementControl Reconciler", func() {
})
})
Specify("Cleanup after tests", func() {
deleteUserPlacement(UserPlacementName, DefaultDRPCNamespace)
deleteUserPlacement()
deleteDRPC()
waitForCompletion("deleted")
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(2)) // DRCluster + NS MW only
Expect(getManifestWorkCount(East1ManagedCluster)).Should(Equal(1)) // DRCluster
Expect(getManagedClusterViewCount(East1ManagedCluster)).Should(Equal(0)) // NS + VRG MCV
deleteNamespaceMWsFromAllClusters(DefaultDRPCNamespace)
ensureNamespaceMWsDeletedFromAllClusters(DefaultDRPCNamespace)
deleteDRPolicyAsync()
ensureDRPolicyIsDeleted(drpc.Spec.DRPolicyRef.Name)
deleteDRClustersAsync()
Expand Down

0 comments on commit f0bdf1b

Please sign in to comment.