Skip to content

Commit 9fa5f5d

Browse files
committed
try to fix apply strategy e2e
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 53b6fe8 commit 9fa5f5d

File tree

2 files changed

+71
-35
lines changed

2 files changed

+71
-35
lines changed

test/e2e/placement_apply_strategy_test.go

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ 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"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/types"
2829
"k8s.io/apimachinery/pkg/util/intstr"
@@ -37,7 +38,7 @@ const (
3738
e2eTestFieldManager = "e2e-test-field-manager"
3839
)
3940

40-
var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
41+
var _ = Describe("validating CRP when resources exists", Ordered, func() {
4142
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
4243
annotationKey := "annotation-key"
4344
annotationValue := "annotation-value"
@@ -77,17 +78,27 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
7778
})
7879

7980
AfterAll(func() {
80-
By("removing the owner reference of the namespace")
81-
// Remove the extra owner reference from the namespace to avoid deletion delays.
82-
// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
83-
// from deleting until the applied work is fully deleted. If the namespace has
84-
// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
85-
// and flakiness in subsequent tests.
86-
removeOtherOwner(allMemberClusters[0])
81+
//By("removing the owner reference of the namespace")
82+
//// Remove the extra owner reference from the namespace to avoid deletion delays.
83+
//// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
84+
//// from deleting until the applied work is fully deleted. If the namespace has
85+
//// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
86+
//// and flakiness in subsequent tests.
87+
//removeOtherOwner(allMemberClusters[0])
8788

8889
By("deleting created work resources on member cluster")
8990
cleanWorkResourcesOnCluster(allMemberClusters[0])
9091

92+
// Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
93+
// This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
94+
// and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
95+
// and flakiness in subsequent tests.
96+
By("Check if work is deleted")
97+
Eventually(func() bool {
98+
work := &placementv1beta1.Work{}
99+
return errors.IsNotFound(hubClient.Get(ctx, types.NamespacedName{Name: "crp-1-work", Namespace: "fleet-member-kind-cluster-1"}, work))
100+
}, 6*eventuallyDuration, eventuallyInterval).Should(BeTrue(), "Work resource should be deleted from hub")
101+
91102
By(fmt.Sprintf("deleting placement %s", crpName))
92103
cleanupCRP(crpName)
93104

@@ -128,7 +139,7 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
128139
It("namespace should be kept on member cluster", func() {
129140
Consistently(func() error {
130141
ns := &corev1.Namespace{}
131-
return allMemberClusters[0].KubeClient.Get(ctx, types.NamespacedName{Name: workNamespaceName}, ns)
142+
return hubClient.Get(ctx, types.NamespacedName{Name: workNamespaceName}, ns)
132143
}, consistentlyDuration, consistentlyInterval).Should(Succeed(), "Namespace which is not owned by the CRP should not be deleted")
133144
})
134145
})
@@ -148,6 +159,16 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
148159
})
149160

150161
AfterAll(func() {
162+
// Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
163+
// This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
164+
// and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
165+
// and flakiness in subsequent tests.
166+
By("Check if work is deleted")
167+
Eventually(func() bool {
168+
work := &placementv1beta1.Work{}
169+
return errors.IsNotFound(hubClient.Get(ctx, types.NamespacedName{Name: "crp-1-work", Namespace: "fleet-member-kind-cluster-1"}, work))
170+
}, 6*eventuallyDuration, eventuallyInterval).Should(BeTrue(), "Work resource should be deleted from hub")
171+
151172
By(fmt.Sprintf("deleting placement %s", crpName))
152173
cleanupCRP(crpName)
153174
})
@@ -203,6 +224,7 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
203224
AfterAll(func() {
204225
By(fmt.Sprintf("deleting placement %s", crpName))
205226
cleanupCRP(crpName)
227+
206228
})
207229

208230
It("should update CRP status as expected", func() {
@@ -259,19 +281,29 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
259281
})
260282

261283
AfterAll(func() {
262-
By("removing the owner reference of the namespace")
263-
// Remove the extra owner reference from the namespace to avoid deletion delays.
264-
// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
265-
// from deleting until the applied work is fully deleted. If the namespace has
266-
// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
284+
//By("removing the owner reference of the namespace")
285+
//// Remove the extra owner reference from the namespace to avoid deletion delays.
286+
//// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
287+
//// from deleting until the applied work is fully deleted. If the namespace has
288+
//// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
289+
//// and flakiness in subsequent tests.
290+
//removeOtherOwner(allMemberClusters[0])
291+
292+
By("deleting created work resources on member cluster")
293+
cleanWorkResourcesOnCluster(allMemberClusters[0])
294+
295+
// Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
296+
// This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
297+
// and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
267298
// and flakiness in subsequent tests.
268-
removeOtherOwner(allMemberClusters[0])
299+
By("Check if work is deleted")
300+
Eventually(func() bool {
301+
work := &placementv1beta1.Work{}
302+
return errors.IsNotFound(hubClient.Get(ctx, types.NamespacedName{Name: "crp-1-work", Namespace: "fleet-member-kind-cluster-1"}, work))
303+
}, 6*eventuallyDuration, eventuallyInterval).Should(BeTrue(), "Work resource should be deleted from hub")
269304

270305
By(fmt.Sprintf("deleting placement %s", crpName))
271306
cleanupCRP(crpName)
272-
273-
By("deleting created work resources on member cluster")
274-
cleanWorkResourcesOnCluster(allMemberClusters[0])
275307
})
276308

277309
It("should update CRP status as expected", func() {
@@ -402,19 +434,29 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
402434
})
403435

404436
AfterAll(func() {
405-
By("removing the owner reference of the namespace")
406-
// Remove the extra owner reference from the namespace to avoid deletion delays.
407-
// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
408-
// from deleting until the applied work is fully deleted. If the namespace has
409-
// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
437+
//By("removing the owner reference of the namespace")
438+
//// Remove the extra owner reference from the namespace to avoid deletion delays.
439+
//// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
440+
//// from deleting until the applied work is fully deleted. If the namespace has
441+
//// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
442+
//// and flakiness in subsequent tests.
443+
//removeOtherOwner(allMemberClusters[0])
444+
445+
By("deleting created work resources on member cluster")
446+
cleanWorkResourcesOnCluster(allMemberClusters[0])
447+
448+
// Check if work is deleted. Needed to ensure that the Work resource is cleaned up before the next CRP is created.
449+
// This is because the Work resource is created with a finalizer that blocks deletion until the all applied work
450+
// and applied work itself is successfully deleted. If the Work resource is not deleted, it can cause resource overlap
410451
// and flakiness in subsequent tests.
411-
removeOtherOwner(allMemberClusters[0])
452+
By("Check if work is deleted")
453+
Eventually(func() bool {
454+
work := &placementv1beta1.Work{}
455+
return errors.IsNotFound(hubClient.Get(ctx, types.NamespacedName{Name: "crp-1-work", Namespace: "fleet-member-kind-cluster-1"}, work))
456+
}, 7*eventuallyDuration, eventuallyInterval).Should(BeTrue(), "Work resource should be deleted from hub")
412457

413458
By(fmt.Sprintf("deleting placement %s", crpName))
414459
cleanupCRP(crpName)
415-
416-
By("deleting created work resources on member cluster")
417-
cleanWorkResourcesOnCluster(allMemberClusters[0])
418460
})
419461

420462
It("should update CRP status as expected", func() {
@@ -638,14 +680,6 @@ var _ = FDescribe("validating CRP when resources exists", Ordered, func() {
638680
})
639681

640682
AfterAll(func() {
641-
By("removing the owner reference of the namespace")
642-
// Remove the extra owner reference from the namespace to avoid deletion delays.
643-
// With the new change to use foreground deletion on applied Work resources, the Work will be blocked
644-
// from deleting until the applied work is fully deleted. If the namespace has
645-
// multiple owner references, it won’t be deleted immediately, which can cause resource overlap
646-
// and flakiness in subsequent tests.
647-
removeOtherOwner(allMemberClusters[0])
648-
649683
ensureCRPAndRelatedResourcesDeleted(crpName, allMemberClusters)
650684

651685
ensureCRPAndRelatedResourcesDeleted(conflictedCRPName, allMemberClusters)

test/e2e/utils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,8 @@ func removeOtherOwner(cluster *framework.Cluster) {
972972
for _, ref := range ns.OwnerReferences {
973973
if ref.Name != otherOwner.Name {
974974
newOwnerRefs = append(newOwnerRefs, ref)
975+
} else if ref.Name == otherOwner.Name {
976+
By(fmt.Sprintf("Removing owner reference %s from namespace %s", otherOwner.Name, ns.Name))
975977
}
976978
}
977979

0 commit comments

Comments
 (0)