@@ -271,7 +271,48 @@ func TestCoreResourceEnqueue(t *testing.T) {
271
271
// It causes pod1 to be requeued.
272
272
// It causes pod2 not to be requeued.
273
273
if _ , err := testCtx .ClientSet .CoreV1 ().Nodes ().Update (testCtx .Ctx , st .MakeNode ().Name ("fake-node1" ).Label ("group" , "b" ).Obj (), metav1.UpdateOptions {}); err != nil {
274
- return fmt .Errorf ("failed to remove taints off the node: %w" , err )
274
+ return fmt .Errorf ("failed to update the pod: %w" , err )
275
+ }
276
+ return nil
277
+ },
278
+ wantRequeuedPods : sets .New ("pod1" ),
279
+ },
280
+ {
281
+ name : "Pod rejected by the NodeAffinity plugin is not requeued when an updated Node haven't changed the 'match' verdict" ,
282
+ initialNodes : []* v1.Node {
283
+ st .MakeNode ().Name ("node1" ).Label ("group" , "a" ).Capacity (map [v1.ResourceName ]string {v1 .ResourceCPU : "2" }).Obj (),
284
+ st .MakeNode ().Name ("node2" ).Label ("group" , "b" ).Obj ()},
285
+ pods : []* v1.Pod {
286
+ // - The initial pod would be accepted by the NodeAffinity plugin for node1, but will be blocked by the NodeResources plugin.
287
+ // - The pod will be blocked by the NodeAffinity plugin for node2, therefore we know NodeAffinity will be queried for qhint for both testing nodes.
288
+ st .MakePod ().Name ("pod1" ).NodeAffinityIn ("group" , []string {"a" }, st .NodeSelectorTypeMatchExpressions ).Req (map [v1.ResourceName ]string {v1 .ResourceCPU : "4" }).Container ("image" ).Obj (),
289
+ },
290
+ triggerFn : func (testCtx * testutils.TestContext ) error {
291
+ // Trigger a NodeUpdate event to add new label.
292
+ // It won't cause pod to be requeued, because there was a match already before the update, meaning this plugin wasn't blocking the scheduling.
293
+ if _ , err := testCtx .ClientSet .CoreV1 ().Nodes ().Update (testCtx .Ctx , st .MakeNode ().Name ("node1" ).Label ("group" , "a" ).Label ("node" , "fake-node" ).Obj (), metav1.UpdateOptions {}); err != nil {
294
+ return fmt .Errorf ("failed to update the pod: %w" , err )
295
+ }
296
+ return nil
297
+ },
298
+ wantRequeuedPods : sets.Set [string ]{},
299
+ enableSchedulingQueueHint : []bool {true },
300
+ },
301
+ {
302
+ name : "Pod rejected by the NodeAffinity plugin is requeued when a Node is added" ,
303
+ initialNodes : []* v1.Node {st .MakeNode ().Name ("fake-node1" ).Label ("group" , "a" ).Obj ()},
304
+ pods : []* v1.Pod {
305
+ // - Pod1 will be rejected by the NodeAffinity plugin.
306
+ st .MakePod ().Name ("pod1" ).NodeAffinityIn ("group" , []string {"b" }, st .NodeSelectorTypeMatchExpressions ).Container ("image" ).Obj (),
307
+ // - Pod2 will be rejected by the NodeAffinity plugin.
308
+ st .MakePod ().Name ("pod2" ).NodeAffinityIn ("group" , []string {"c" }, st .NodeSelectorTypeMatchExpressions ).Container ("image" ).Obj (),
309
+ },
310
+ triggerFn : func (testCtx * testutils.TestContext ) error {
311
+ // Trigger a NodeAdd event with the awaited label.
312
+ // It causes pod1 to be requeued.
313
+ // It causes pod2 not to be requeued.
314
+ if _ , err := testCtx .ClientSet .CoreV1 ().Nodes ().Create (testCtx .Ctx , st .MakeNode ().Name ("fake-node2" ).Label ("group" , "b" ).Obj (), metav1.CreateOptions {}); err != nil {
315
+ return fmt .Errorf ("failed to update the pod: %w" , err )
275
316
}
276
317
return nil
277
318
},
0 commit comments