@@ -1309,19 +1309,31 @@ var _ = Describe("Test Work Generator Controller", func() {
13091309 TargetCluster : memberClusterName ,
13101310 }
13111311 createClusterResourceBinding (& binding , spec )
1312+ })
1313+
1314+ AfterEach (func () {
1315+ // Delete the master resource snapshot.
1316+ Expect (k8sClient .Delete (ctx , masterSnapshot )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1317+ By (fmt .Sprintf ("Master resource snapshot %s deleted" , masterSnapshot .Name ))
1318+ // Delete the second resource snapshot.
1319+ Expect (k8sClient .Delete (ctx , secondSnapshot )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1320+ By (fmt .Sprintf ("Secondary resource snapshot %s deleted" , secondSnapshot .Name ))
1321+ // Delete the binding.
1322+ Expect (k8sClient .Delete (ctx , binding )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1323+ By (fmt .Sprintf ("Resource binding %s deleted" , binding .Name ))
1324+ })
13121325
1326+ It ("Should create necessary work in the target namespace after a resource snapshot with selected envelope object is created" , func () {
13131327 // Now create the second resource snapshot.
13141328 secondSnapshot = generateResourceSnapshot (2 , 2 , 1 , [][]byte {
13151329 testEnvelopConfigMap , testNameSpace ,
13161330 })
13171331 Expect (k8sClient .Create (ctx , secondSnapshot )).Should (Succeed ())
13181332 By (fmt .Sprintf ("Secondary resource snapshot %s created" , secondSnapshot .Name ))
1319-
13201333 // Update master resource snapshot labels.
13211334 Expect (k8sClient .Get (ctx , types.NamespacedName {Name : masterSnapshot .Name }, masterSnapshot )).Should (Succeed ())
13221335 masterSnapshot .Labels [placementv1beta1 .IsLatestSnapshotLabel ] = "false"
13231336 Expect (k8sClient .Update (ctx , masterSnapshot )).Should (Succeed ())
1324-
13251337 // Update binding.
13261338 updateRolloutStartedGeneration (& binding )
13271339 By (fmt .Sprintf ("resource binding %s updated" , binding .Name ))
@@ -1332,21 +1344,6 @@ var _ = Describe("Test Work Generator Controller", func() {
13321344 return errors .IsNotFound (err )
13331345 }, duration , interval ).Should (BeTrue (), "controller should not create work in hub cluster" )
13341346 By ("Work for first resource snapshot is not created in hub cluster" )
1335- })
1336-
1337- AfterEach (func () {
1338- // Delete the master resource snapshot.
1339- Expect (k8sClient .Delete (ctx , masterSnapshot )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1340- By (fmt .Sprintf ("Master resource snapshot %s deleted" , masterSnapshot .Name ))
1341- // Delete the second resource snapshot.
1342- Expect (k8sClient .Delete (ctx , secondSnapshot )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1343- By (fmt .Sprintf ("Secondary resource snapshot %s deleted" , secondSnapshot .Name ))
1344- // Delete the binding.
1345- Expect (k8sClient .Delete (ctx , binding )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}))
1346- By (fmt .Sprintf ("Resource binding %s deleted" , binding .Name ))
1347- })
1348-
1349- It ("Should create necessary work in the target namespace after a resource snapshot with selected envelope object is created" , func () {
13501347 // Check the work for the secondary resource snapshot is created, it's name is crp-subindex.
13511348 secondWork := placementv1beta1.Work {}
13521349 Eventually (func () error {
@@ -1443,6 +1440,26 @@ var _ = Describe("Test Work Generator Controller", func() {
14431440 })
14441441
14451442 It ("Should create necessary work in the target namespace after a resource snapshot with selected resource is created" , func () {
1443+ // Now create the second resource snapshot.
1444+ secondSnapshot = generateResourceSnapshot (2 , 2 , 1 , [][]byte {
1445+ testResourceCRD , testNameSpace ,
1446+ })
1447+ Expect (k8sClient .Create (ctx , secondSnapshot )).Should (Succeed ())
1448+ By (fmt .Sprintf ("Secondary resource snapshot %s created" , secondSnapshot .Name ))
1449+ // Update master resource snapshot labels.
1450+ Expect (k8sClient .Get (ctx , types.NamespacedName {Name : masterSnapshot .Name }, masterSnapshot )).Should (Succeed ())
1451+ masterSnapshot .Labels [placementv1beta1 .IsLatestSnapshotLabel ] = "false"
1452+ Expect (k8sClient .Update (ctx , masterSnapshot )).Should (Succeed ())
1453+ // Update binding.
1454+ updateRolloutStartedGeneration (& binding )
1455+ By (fmt .Sprintf ("resource binding %s updated" , binding .Name ))
1456+ // Check the work for the master resource snapshot is not created.
1457+ work := placementv1beta1.Work {}
1458+ Consistently (func () bool {
1459+ err := k8sClient .Get (ctx , types.NamespacedName {Name : fmt .Sprintf (placementv1beta1 .FirstWorkNameFmt , testCRPName ), Namespace : memberClusterNamespaceName }, & work )
1460+ return errors .IsNotFound (err )
1461+ }, duration , interval ).Should (BeTrue (), "controller should not create work in hub cluster" )
1462+ By ("Work for first resource snapshot is not created in hub cluster" )
14461463 // Check the work for the secondary resource snapshot is created, it's name is crp-subindex.
14471464 secondWork := placementv1beta1.Work {}
14481465 Eventually (func () error {
0 commit comments