Skip to content

Commit d003e4c

Browse files
authored
Merge pull request kubernetes#127923 from unvavo/add-test-tainttoleration-for-queueinghint
add integration test for tainttoleration in requeueing scenarios
2 parents 769695a + 2c254d3 commit d003e4c

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

test/integration/scheduler/queue_test.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,60 @@ func TestCoreResourceEnqueue(t *testing.T) {
335335
},
336336
{
337337
name: "Pod updated with toleration requeued to activeQ",
338-
initialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Capacity(map[v1.ResourceName]string{v1.ResourceCPU: "2"}).Taints([]v1.Taint{{Key: "taint-key", Effect: v1.TaintEffectNoSchedule}}).Obj()},
338+
initialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Taints([]v1.Taint{{Key: "taint-key", Effect: v1.TaintEffectNoSchedule}}).Obj()},
339339
pods: []*v1.Pod{
340340
// - Pod1 doesn't have the required toleration and will be rejected by the TaintToleration plugin.
341-
st.MakePod().Name("pod1").Req(map[v1.ResourceName]string{v1.ResourceCPU: "2"}).Container("image").Obj(),
341+
st.MakePod().Name("pod1").Container("image").Obj(),
342+
st.MakePod().Name("pod2").Container("image").Obj(),
342343
},
343344
triggerFn: func(testCtx *testutils.TestContext) (map[framework.ClusterEvent]uint64, error) {
344345
// Trigger a PodUpdate event by adding a toleration to Pod1.
345-
// It makes Pod1 schedulable.
346-
if _, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Update(testCtx.Ctx, st.MakePod().Name("pod1").Req(map[v1.ResourceName]string{v1.ResourceCPU: "2"}).Container("image").Toleration("taint-key").Obj(), metav1.UpdateOptions{}); err != nil {
346+
// It makes Pod1 schedulable. Pod2 is not requeued because of not having toleration.
347+
if _, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Update(testCtx.Ctx, st.MakePod().Name("pod1").Container("image").Toleration("taint-key").Obj(), metav1.UpdateOptions{}); err != nil {
347348
return nil, fmt.Errorf("failed to update the pod: %w", err)
348349
}
349350
return map[framework.ClusterEvent]uint64{framework.PodTolerationChange: 1}, nil
350351
},
351352
wantRequeuedPods: sets.New("pod1"),
352353
},
354+
{
355+
name: "Pod rejected by the TaintToleration plugin is requeued when the Node's taint is updated",
356+
initialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Taints([]v1.Taint{{Key: v1.TaintNodeNotReady, Effect: v1.TaintEffectNoSchedule}}).Obj()},
357+
pods: []*v1.Pod{
358+
// - Pod1, pod2 and pod3 don't have the required toleration and will be rejected by the TaintToleration plugin.
359+
st.MakePod().Name("pod1").Toleration("taint-key").Container("image").Obj(),
360+
st.MakePod().Name("pod2").Toleration("taint-key2").Container("image").Obj(),
361+
st.MakePod().Name("pod3").Container("image").Obj(),
362+
},
363+
triggerFn: func(testCtx *testutils.TestContext) (map[framework.ClusterEvent]uint64, error) {
364+
// Trigger a NodeUpdate event that changes the existing taint to a taint that matches the toleration that pod1 has.
365+
// It makes Pod1 schedulable. Pod2 and pod3 are not requeued because of not having the corresponding toleration.
366+
if _, err := testCtx.ClientSet.CoreV1().Nodes().Update(testCtx.Ctx, st.MakeNode().Name("fake-node").Taints([]v1.Taint{{Key: "taint-key", Effect: v1.TaintEffectNoSchedule}}).Obj(), metav1.UpdateOptions{}); err != nil {
367+
return nil, fmt.Errorf("failed to update the Node: %w", err)
368+
}
369+
return map[framework.ClusterEvent]uint64{framework.NodeTaintChange: 1}, nil
370+
},
371+
wantRequeuedPods: sets.New("pod1"),
372+
enableSchedulingQueueHint: []bool{true},
373+
},
374+
{
375+
name: "Pod rejected by the TaintToleration plugin is requeued when a Node that has the correspoding taint is added",
376+
initialNodes: []*v1.Node{st.MakeNode().Name("fake-node1").Taints([]v1.Taint{{Key: v1.TaintNodeNotReady, Effect: v1.TaintEffectNoSchedule}}).Obj()},
377+
pods: []*v1.Pod{
378+
// - Pod1 and Pod2 don't have the required toleration and will be rejected by the TaintToleration plugin.
379+
st.MakePod().Name("pod1").Toleration("taint-key").Container("image").Obj(),
380+
st.MakePod().Name("pod2").Container("image").Obj(),
381+
},
382+
triggerFn: func(testCtx *testutils.TestContext) (map[framework.ClusterEvent]uint64, error) {
383+
// Trigger a NodeCreated event with the taint.
384+
// It makes Pod1 schedulable. Pod2 is not requeued because of not having toleration.
385+
if _, err := testCtx.ClientSet.CoreV1().Nodes().Create(testCtx.Ctx, st.MakeNode().Name("fake-node2").Taints([]v1.Taint{{Key: "taint-key", Effect: v1.TaintEffectNoSchedule}}).Obj(), metav1.CreateOptions{}); err != nil {
386+
return nil, fmt.Errorf("failed to create the Node: %w", err)
387+
}
388+
return map[framework.ClusterEvent]uint64{framework.NodeAdd: 1}, nil
389+
},
390+
wantRequeuedPods: sets.New("pod1"),
391+
},
353392
{
354393
name: "Pod rejected by the NodeResourcesFit plugin is requeued when the Pod is updated to scale down",
355394
initialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Capacity(map[v1.ResourceName]string{v1.ResourceCPU: "2"}).Obj()},

0 commit comments

Comments
 (0)