@@ -23,7 +23,6 @@ import (
2323 . "github.com/onsi/ginkgo/v2"
2424 . "github.com/onsi/gomega"
2525 corev1 "k8s.io/api/core/v1"
26- "k8s.io/apimachinery/pkg/api/errors"
2726 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827 "k8s.io/apimachinery/pkg/types"
2928 "k8s.io/apimachinery/pkg/util/intstr"
@@ -84,16 +83,6 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
8483
8584 By ("deleting created work resources on member cluster" )
8685 cleanWorkResourcesOnCluster (allMemberClusters [0 ])
87-
88- // Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
89- // This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
90- // and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
91- // and flakiness in subsequent tests.
92- By ("Check if work is deleted" )
93- Eventually (func () bool {
94- work := & placementv1beta1.Work {}
95- return errors .IsNotFound (hubClient .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-work" , crpName ), Namespace : fmt .Sprintf ("fleet-member-%s" , allMemberClusterNames [0 ])}, work ))
96- }, 6 * eventuallyDuration , eventuallyInterval ).Should (BeTrue (), "Work resource should be deleted from hub" )
9786 })
9887
9988 It ("should update CRP status as expected" , func () {
@@ -137,8 +126,12 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
137126
138127 if len (ns .OwnerReferences ) > 0 {
139128 for _ , ownerRef := range ns .OwnerReferences {
140- if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () && ownerRef .Kind == placementv1beta1 .AppliedWorkKind && ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) && * ownerRef .BlockOwnerDeletion {
141- return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
129+ if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () &&
130+ ownerRef .Kind == placementv1beta1 .AppliedWorkKind &&
131+ ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) {
132+ if * ownerRef .BlockOwnerDeletion {
133+ return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
134+ }
142135 }
143136 }
144137 }
@@ -273,16 +266,6 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
273266
274267 By ("deleting created work resources on member cluster" )
275268 cleanWorkResourcesOnCluster (allMemberClusters [0 ])
276-
277- // Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
278- // This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
279- // and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
280- // and flakiness in subsequent tests.
281- By ("Check if work is deleted" )
282- Eventually (func () bool {
283- work := & placementv1beta1.Work {}
284- return errors .IsNotFound (hubClient .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-work" , crpName ), Namespace : fmt .Sprintf ("fleet-member-%s" , allMemberClusterNames [0 ])}, work ))
285- }, 6 * eventuallyDuration , eventuallyInterval ).Should (BeTrue (), "Work resource should be deleted from hub" )
286269 })
287270
288271 It ("should update CRP status as expected" , func () {
@@ -382,8 +365,12 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
382365
383366 if len (ns .OwnerReferences ) > 0 {
384367 for _ , ownerRef := range ns .OwnerReferences {
385- if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () && ownerRef .Kind == placementv1beta1 .AppliedWorkKind && ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) && * ownerRef .BlockOwnerDeletion {
386- return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
368+ if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () &&
369+ ownerRef .Kind == placementv1beta1 .AppliedWorkKind &&
370+ ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) {
371+ if * ownerRef .BlockOwnerDeletion {
372+ return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
373+ }
387374 }
388375 }
389376 }
@@ -427,16 +414,6 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
427414
428415 By ("deleting created work resources on member cluster" )
429416 cleanWorkResourcesOnCluster (allMemberClusters [0 ])
430-
431- // Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
432- // This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
433- // and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
434- // and flakiness in subsequent tests.
435- By ("Check if work is deleted" )
436- Eventually (func () bool {
437- work := & placementv1beta1.Work {}
438- return errors .IsNotFound (hubClient .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-work" , crpName ), Namespace : fmt .Sprintf ("fleet-member-%s" , allMemberClusterNames [0 ])}, work ))
439- }, 7 * eventuallyDuration , eventuallyInterval ).Should (BeTrue (), "Work resource should be deleted from hub" )
440417 })
441418
442419 It ("should update CRP status as expected" , func () {
@@ -482,8 +459,12 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
482459
483460 if len (ns .OwnerReferences ) > 0 {
484461 for _ , ownerRef := range ns .OwnerReferences {
485- if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () && ownerRef .Kind == placementv1beta1 .AppliedWorkKind && ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) && * ownerRef .BlockOwnerDeletion {
486- return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
462+ if ownerRef .APIVersion == placementv1beta1 .GroupVersion .String () &&
463+ ownerRef .Kind == placementv1beta1 .AppliedWorkKind &&
464+ ownerRef .Name == fmt .Sprintf ("%s-work" , crpName ) {
465+ if * ownerRef .BlockOwnerDeletion {
466+ return fmt .Errorf ("namespace %s owner reference for AppliedWork should have been updated to have BlockOwnerDeletion set to false" , workNamespaceName )
467+ }
487468 }
488469 }
489470 }
0 commit comments