@@ -188,7 +188,7 @@ func TestCoreResourceEnqueue(t *testing.T) {
188
188
tests := []struct {
189
189
name string
190
190
// initialNode is the Node to be created at first.
191
- initialNode * v1.Node
191
+ initialNodes [] * v1.Node
192
192
// initialPod is the Pod to be created at first if it's not empty.
193
193
initialPod * v1.Pod
194
194
// pods are the list of Pods to be created.
@@ -202,8 +202,8 @@ func TestCoreResourceEnqueue(t *testing.T) {
202
202
enableSchedulingQueueHint []bool
203
203
}{
204
204
{
205
- name : "Pod without a required toleration to a node isn't requeued to activeQ" ,
206
- initialNode : st .MakeNode ().Name ("fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Taints ([]v1.Taint {{Key : v1 .TaintNodeNotReady , Effect : v1 .TaintEffectNoSchedule }}).Obj (),
205
+ name : "Pod without a required toleration to a node isn't requeued to activeQ" ,
206
+ initialNodes : [] * v1. Node { st .MakeNode ().Name ("fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Taints ([]v1.Taint {{Key : v1 .TaintNodeNotReady , Effect : v1 .TaintEffectNoSchedule }}).Obj ()} ,
207
207
pods : []* v1.Pod {
208
208
// - Pod1 doesn't have the required toleration and will be rejected by the TaintToleration plugin.
209
209
// (TaintToleration plugin is evaluated before NodeResourcesFit plugin.)
@@ -224,9 +224,9 @@ func TestCoreResourceEnqueue(t *testing.T) {
224
224
enableSchedulingQueueHint : []bool {false , true },
225
225
},
226
226
{
227
- name : "Pod rejected by the PodAffinity plugin is requeued when a new Node is created and turned to ready" ,
228
- initialNode : st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj (),
229
- initialPod : st .MakePod ().Label ("anti" , "anti" ).Name ("pod1" ).PodAntiAffinityExists ("anti" , "node" , st .PodAntiAffinityWithRequiredReq ).Container ("image" ).Node ("fake-node" ).Obj (),
227
+ name : "Pod rejected by the PodAffinity plugin is requeued when a new Node is created and turned to ready" ,
228
+ initialNodes : [] * v1. Node { st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj ()} ,
229
+ initialPod : st .MakePod ().Label ("anti" , "anti" ).Name ("pod1" ).PodAntiAffinityExists ("anti" , "node" , st .PodAntiAffinityWithRequiredReq ).Container ("image" ).Node ("fake-node" ).Obj (),
230
230
pods : []* v1.Pod {
231
231
// - Pod2 will be rejected by the PodAffinity plugin.
232
232
st .MakePod ().Label ("anti" , "anti" ).Name ("pod2" ).PodAntiAffinityExists ("anti" , "node" , st .PodAntiAffinityWithRequiredReq ).Container ("image" ).Obj (),
@@ -254,8 +254,8 @@ func TestCoreResourceEnqueue(t *testing.T) {
254
254
enableSchedulingQueueHint : []bool {false , true },
255
255
},
256
256
{
257
- name : "Pod updated with toleration requeued to activeQ" ,
258
- initialNode : st .MakeNode ().Name ("fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Taints ([]v1.Taint {{Key : "taint-key" , Effect : v1 .TaintEffectNoSchedule }}).Obj (),
257
+ name : "Pod updated with toleration requeued to activeQ" ,
258
+ 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 ()} ,
259
259
pods : []* v1.Pod {
260
260
// - Pod1 doesn't have the required toleration and will be rejected by the TaintToleration plugin.
261
261
st .MakePod ().Name ("pod1" ).Req (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Container ("image" ).Obj (),
@@ -272,8 +272,8 @@ func TestCoreResourceEnqueue(t *testing.T) {
272
272
enableSchedulingQueueHint : []bool {false , true },
273
273
},
274
274
{
275
- name : "Pod got resource scaled down requeued to activeQ" ,
276
- initialNode : st .MakeNode ().Name ("fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj (),
275
+ name : "Pod got resource scaled down requeued to activeQ" ,
276
+ initialNodes : [] * v1. Node { st .MakeNode ().Name ("fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj ()} ,
277
277
pods : []* v1.Pod {
278
278
// - Pod1 requests a large amount of CPU and will be rejected by the NodeResourcesFit plugin.
279
279
st .MakePod ().Name ("pod1" ).Req (map [v1.ResourceName ]string {v1 .ResourceCPU : "4" }).Container ("image" ).Obj (),
@@ -290,8 +290,8 @@ func TestCoreResourceEnqueue(t *testing.T) {
290
290
enableSchedulingQueueHint : []bool {false , true },
291
291
},
292
292
{
293
- name : "Updating pod condition doesn't retry scheduling if the Pod was rejected by TaintToleration" ,
294
- initialNode : st .MakeNode ().Name ("fake-node" ).Taints ([]v1.Taint {{Key : v1 .TaintNodeNotReady , Effect : v1 .TaintEffectNoSchedule }}).Obj (),
293
+ name : "Updating pod condition doesn't retry scheduling if the Pod was rejected by TaintToleration" ,
294
+ initialNodes : [] * v1. Node { st .MakeNode ().Name ("fake-node" ).Taints ([]v1.Taint {{Key : v1 .TaintNodeNotReady , Effect : v1 .TaintEffectNoSchedule }}).Obj ()} ,
295
295
pods : []* v1.Pod {
296
296
// - Pod1 doesn't have the required toleration and will be rejected by the TaintToleration plugin.
297
297
st .MakePod ().Name ("pod1" ).Container ("image" ).Obj (),
@@ -327,6 +327,41 @@ func TestCoreResourceEnqueue(t *testing.T) {
327
327
// because QHint of TaintToleration would decide to ignore a Pod update.
328
328
enableSchedulingQueueHint : []bool {true },
329
329
},
330
+ {
331
+ // The test case makes sure that PreFilter plugins returning PreFilterResult are also inserted into pInfo.UnschedulablePlugins
332
+ // meaning, they're taken into consideration during requeuing flow of the queue.
333
+ // https://github.com/kubernetes/kubernetes/issues/122018
334
+ name : "Pod rejected by the PreFilter of NodeAffinity plugin and Filter of NodeResourcesFit is requeued based on both plugins" ,
335
+ initialNodes : []* v1.Node {
336
+ st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj (),
337
+ st .MakeNode ().Name ("fake-node2" ).Label ("node" , "fake-node2" ).Label ("zone" , "zone1" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj (),
338
+ },
339
+ pods : []* v1.Pod {
340
+ // - Pod1 will be rejected by the NodeAffinity plugin and NodeResourcesFit plugin.
341
+ st .MakePod ().Label ("unscheduled" , "plugins" ).Name ("pod1" ).NodeAffinityIn ("metadata.name" , []string {"fake-node" }).Req (map [v1.ResourceName ]string {v1 .ResourceCPU : "4" }).Obj (),
342
+ },
343
+ triggerFn : func (testCtx * testutils.TestContext ) error {
344
+ // Trigger a NodeDeleted event.
345
+ // It will not requeue pod1 to activeQ,
346
+ // because both NodeAffinity and NodeResourceFit don't register Node/delete event.
347
+ err := testCtx .ClientSet .CoreV1 ().Nodes ().Delete (testCtx .Ctx , "fake-node" , metav1.DeleteOptions {})
348
+ if err != nil {
349
+ return fmt .Errorf ("failed to delete fake-node node" )
350
+ }
351
+
352
+ // Trigger a NodeCreated event.
353
+ // It will requeue pod1 to activeQ, because QHint of NodeAffinity return Queue.
354
+ // It makes sure PreFilter plugins returned PreFilterResult takes an effect for sure,
355
+ // because NodeResourceFit QHint returns QueueSkip for this event actually.
356
+ node := st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj ()
357
+ if _ , err := testCtx .ClientSet .CoreV1 ().Nodes ().Create (testCtx .Ctx , node , metav1.CreateOptions {}); err != nil {
358
+ return fmt .Errorf ("failed to create a new node: %w" , err )
359
+ }
360
+
361
+ return nil
362
+ },
363
+ wantRequeuedPods : sets .New ("pod1" ),
364
+ },
330
365
}
331
366
332
367
for _ , tt := range tests {
@@ -350,9 +385,11 @@ func TestCoreResourceEnqueue(t *testing.T) {
350
385
defer testCtx .Scheduler .SchedulingQueue .Close ()
351
386
352
387
cs , ns , ctx := testCtx .ClientSet , testCtx .NS .Name , testCtx .Ctx
353
- // Create initialNode.
354
- if _ , err := cs .CoreV1 ().Nodes ().Create (ctx , tt .initialNode , metav1.CreateOptions {}); err != nil {
355
- t .Fatalf ("Failed to create an initial Node %q: %v" , tt .initialNode .Name , err )
388
+ // Create one Node with a taint.
389
+ for _ , node := range tt .initialNodes {
390
+ if _ , err := cs .CoreV1 ().Nodes ().Create (ctx , node , metav1.CreateOptions {}); err != nil {
391
+ t .Fatalf ("Failed to create an initial Node %q: %v" , node .Name , err )
392
+ }
356
393
}
357
394
358
395
if tt .initialPod != nil {
0 commit comments