@@ -374,7 +374,68 @@ func TestCoreResourceEnqueue(t *testing.T) {
374
374
375
375
return nil
376
376
},
377
- wantRequeuedPods : sets .New ("pod2" ),
377
+ wantRequeuedPods : sets .New ("pod2" ),
378
+ enableSchedulingQueueHint : []bool {false , true },
379
+ },
380
+ {
381
+ name : "Pod rejected by the PodAffinity plugin is requeued when deleting the existed pod's label to make it match the podAntiAffinity" ,
382
+ initialNodes : []* v1.Node {st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Obj ()},
383
+ initialPod : st .MakePod ().Name ("pod1" ).Label ("anti1" , "anti1" ).Label ("anti2" , "anti2" ).Container ("image" ).Node ("fake-node" ).Obj (),
384
+ pods : []* v1.Pod {
385
+ // - Pod2 and pod3 will be rejected by the PodAffinity plugin.
386
+ st .MakePod ().Name ("pod2" ).Label ("anti1" , "anti1" ).PodAntiAffinityExists ("anti1" , "node" , st .PodAntiAffinityWithRequiredReq ).Container ("image" ).Obj (),
387
+ st .MakePod ().Name ("pod3" ).Label ("anti2" , "anti2" ).PodAntiAffinityExists ("anti2" , "node" , st .PodAntiAffinityWithRequiredReq ).Container ("image" ).Obj (),
388
+ },
389
+
390
+ triggerFn : func (testCtx * testutils.TestContext ) error {
391
+ // Delete the pod's label 'anti1' which will make it match pod2's antiAffinity.
392
+ if _ , err := testCtx .ClientSet .CoreV1 ().Pods (testCtx .NS .Name ).Update (testCtx .Ctx , st .MakePod ().Name ("pod1" ).Label ("anti2" , "anti2" ).Container ("image" ).Node ("fake-node" ).Obj (), metav1.UpdateOptions {}); err != nil {
393
+ return fmt .Errorf ("failed to update pod1: %w" , err )
394
+ }
395
+ return nil
396
+ },
397
+ wantRequeuedPods : sets .New ("pod2" ),
398
+ enableSchedulingQueueHint : []bool {true },
399
+ },
400
+ {
401
+ name : "Pod rejected by the PodAffinity plugin is requeued when updating the existed pod's label to make it match the pod's podAffinity" ,
402
+ initialNodes : []* v1.Node {st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Obj ()},
403
+ initialPod : st .MakePod ().Name ("pod1" ).Container ("image" ).Node ("fake-node" ).Obj (),
404
+ pods : []* v1.Pod {
405
+ // - Pod2 and pod3 will be rejected by the PodAffinity plugin.
406
+ st .MakePod ().Name ("pod2" ).PodAffinityExists ("aaa" , "node" , st .PodAffinityWithRequiredReq ).Container ("image" ).Obj (),
407
+ st .MakePod ().Name ("pod3" ).PodAffinityExists ("bbb" , "node" , st .PodAffinityWithRequiredReq ).Container ("image" ).Obj (),
408
+ },
409
+
410
+ triggerFn : func (testCtx * testutils.TestContext ) error {
411
+ // Add label to the pod which will make it match pod2's nodeAffinity.
412
+ if _ , err := testCtx .ClientSet .CoreV1 ().Pods (testCtx .NS .Name ).Update (testCtx .Ctx , st .MakePod ().Name ("pod1" ).Label ("aaa" , "bbb" ).Container ("image" ).Node ("fake-node" ).Obj (), metav1.UpdateOptions {}); err != nil {
413
+ return fmt .Errorf ("failed to update pod1: %w" , err )
414
+ }
415
+ return nil
416
+ },
417
+ wantRequeuedPods : sets .New ("pod2" ),
418
+ enableSchedulingQueueHint : []bool {true },
419
+ },
420
+
421
+ {
422
+ name : "Pod rejected by the PodAffinity plugin is requeued when updating the label of the node to make it match the pod affinity" ,
423
+ initialNodes : []* v1.Node {st .MakeNode ().Name ("fake-node" ).Label ("node" , "fake-node" ).Obj ()},
424
+ pods : []* v1.Pod {
425
+ // - pod1 and pod2 will be rejected by the PodAffinity plugin.
426
+ st .MakePod ().Name ("pod1" ).PodAffinityExists ("bbb" , "zone" , st .PodAffinityWithRequiredReq ).Container ("image" ).Obj (),
427
+ st .MakePod ().Name ("pod2" ).PodAffinityExists ("ccc" , "region" , st .PodAffinityWithRequiredReq ).Container ("image" ).Obj (),
428
+ },
429
+
430
+ triggerFn : func (testCtx * testutils.TestContext ) error {
431
+ // Add label to the node which will make it match pod1's podAffinity.
432
+ if _ , err := testCtx .ClientSet .CoreV1 ().Nodes ().Update (testCtx .Ctx , st .MakeNode ().Name ("fake-node" ).Label ("zone" , "zone1" ).Obj (), metav1.UpdateOptions {}); err != nil {
433
+ return fmt .Errorf ("failed to update pod1: %w" , err )
434
+ }
435
+ return nil
436
+ },
437
+ wantRequeuedPods : sets .New ("pod1" ),
438
+ enableSchedulingQueueHint : []bool {true },
378
439
},
379
440
}
380
441
0 commit comments