Skip to content

Commit f7c78c4

Browse files
committed
Fix Schedule flaky e2e tests
This PR addresses some Schedule e2e tests that are flaky. Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
1 parent 84ff7ef commit f7c78c4

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

e2e/single-cluster/agent_scheduling_customization_test.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ func ptr[T any](v T) *T {
1818
}
1919

2020
var _ = Describe("Agent Scheduling Customization", func() {
21-
var (
22-
cluster *fleet.Cluster
23-
)
24-
25-
BeforeEach(func() {
26-
var err error
27-
cluster = &fleet.Cluster{}
28-
err = clientUpstream.Get(context.TODO(), client.ObjectKey{
29-
Namespace: env.Namespace,
30-
Name: "local",
31-
}, cluster)
32-
Expect(err).ToNot(HaveOccurred())
33-
})
34-
3521
When("agentSchedulingCustomization.PriorityClass is configured on the cluster resource", func() {
3622
BeforeEach(func() {
3723
// Update the cluster with agentSchedulingCustomization
@@ -68,6 +54,13 @@ var _ = Describe("Agent Scheduling Customization", func() {
6854
g.Expect(err).ToNot(HaveOccurred())
6955

7056
latestCluster.Spec.AgentSchedulingCustomization = nil
57+
// Bump RedeployAgentGeneration to force a prompt agent re-import.
58+
// Removing the customization clears the status hash quickly, but the
59+
// re-import that prunes fleet-agent-priority-class is otherwise only
60+
// triggered on the controller's periodic resync (~5m). That cadence
61+
// races this AfterEach's PriorityClass-deletion wait and makes the
62+
// spec flaky, so we force the redeploy here to prune it immediately.
63+
latestCluster.Spec.RedeployAgentGeneration++
7164
err = clientUpstream.Update(context.TODO(), latestCluster)
7265
g.Expect(err).ToNot(HaveOccurred())
7366
}).Should(Succeed(), "Should be able to update cluster to remove agentSchedulingCustomization")
@@ -79,7 +72,7 @@ var _ = Describe("Agent Scheduling Customization", func() {
7972
Name: "local",
8073
}, latestCluster)
8174
g.Expect(err).ToNot(HaveOccurred())
82-
g.Expect(cluster.Status.AgentSchedulingCustomizationHash).To(Equal(""))
75+
g.Expect(latestCluster.Status.AgentSchedulingCustomizationHash).To(Equal(""))
8376
}).Should(Succeed(), "Should have cleared the AgentSchedulingCustomizationHash")
8477

8578
// Wait for PriorityClass to be deleted
@@ -166,6 +159,9 @@ var _ = Describe("Agent Scheduling Customization", func() {
166159
g.Expect(err).ToNot(HaveOccurred())
167160

168161
latestCluster.Spec.AgentSchedulingCustomization = nil
162+
// Force a prompt agent re-import so cleanup does not ride the
163+
// controller's periodic resync (~5m). See the PriorityClass block.
164+
latestCluster.Spec.RedeployAgentGeneration++
169165
err = clientUpstream.Update(context.TODO(), latestCluster)
170166
g.Expect(err).ToNot(HaveOccurred())
171167
}).Should(Succeed(), "Should be able to update cluster to remove agentSchedulingCustomization")
@@ -177,7 +173,7 @@ var _ = Describe("Agent Scheduling Customization", func() {
177173
Name: "local",
178174
}, latestCluster)
179175
g.Expect(err).ToNot(HaveOccurred())
180-
g.Expect(cluster.Status.AgentSchedulingCustomizationHash).To(Equal(""))
176+
g.Expect(latestCluster.Status.AgentSchedulingCustomizationHash).To(Equal(""))
181177
}).Should(Succeed(), "Should have cleared the AgentSchedulingCustomizationHash")
182178
})
183179

@@ -239,9 +235,32 @@ var _ = Describe("Agent Scheduling Customization", func() {
239235
g.Expect(err).ToNot(HaveOccurred())
240236

241237
latestCluster.Spec.AgentSchedulingCustomization = nil
238+
// Force a prompt agent re-import so cleanup does not ride the
239+
// controller's periodic resync (~5m). See the PriorityClass block.
240+
latestCluster.Spec.RedeployAgentGeneration++
242241
err = clientUpstream.Update(context.TODO(), latestCluster)
243242
g.Expect(err).ToNot(HaveOccurred())
244243
}).Should(Succeed(), "Should be able to update cluster to remove agentSchedulingCustomization")
244+
245+
// Wait for cleanup to complete so this block does not leak the
246+
// customization (PriorityClass/PDB) into any spec that runs after it.
247+
Eventually(func(g Gomega) {
248+
latestCluster := &fleet.Cluster{}
249+
err := clientUpstream.Get(context.TODO(), client.ObjectKey{
250+
Namespace: env.Namespace,
251+
Name: "local",
252+
}, latestCluster)
253+
g.Expect(err).ToNot(HaveOccurred())
254+
g.Expect(latestCluster.Status.AgentSchedulingCustomizationHash).To(Equal(""))
255+
}).Should(Succeed(), "Should have cleared the AgentSchedulingCustomizationHash")
256+
257+
Eventually(func() bool {
258+
pc := &schedulingv1.PriorityClass{}
259+
err := clientUpstream.Get(context.TODO(), client.ObjectKey{
260+
Name: "fleet-agent-priority-class",
261+
}, pc)
262+
return errors.IsNotFound(err)
263+
}).Should(BeTrue(), "PriorityClass should be deleted")
245264
})
246265

247266
It("should create both PriorityClass and PodDisruptionBudget", func() {

0 commit comments

Comments
 (0)