@@ -143,8 +143,8 @@ var emptyFramework, _ = framework.NewFramework(EmptyPluginRegistry, nil, []sched
143
143
144
144
// FakeFilterPlugin is a test filter plugin used by default scheduler.
145
145
type FakeFilterPlugin struct {
146
- numFilterCalled int32
147
- returnCode framework.Code
146
+ numFilterCalled int32
147
+ failedNodeReturnCodeMap map [ string ] framework.Code
148
148
}
149
149
150
150
// Name returns name of the plugin.
@@ -155,19 +155,19 @@ func (fp *FakeFilterPlugin) Name() string {
155
155
// reset is used to reset filter plugin.
156
156
func (fp * FakeFilterPlugin ) reset () {
157
157
fp .numFilterCalled = 0
158
- fp .returnCode = framework .Success
158
+ fp .failedNodeReturnCodeMap = map [ string ] framework.Code {}
159
159
}
160
160
161
161
// Filter is a test function that returns an error or nil, depending on the
162
- // value of "failFilter ".
162
+ // value of "failedNodeReturnCodeMap ".
163
163
func (fp * FakeFilterPlugin ) Filter (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) * framework.Status {
164
164
atomic .AddInt32 (& fp .numFilterCalled , 1 )
165
165
166
- if fp . returnCode == framework . Success {
167
- return nil
166
+ if returnCode , ok := fp . failedNodeReturnCodeMap [ nodeName ]; ok {
167
+ return framework . NewStatus ( returnCode , fmt . Sprintf ( "injecting failure for pod %v" , pod . Name ))
168
168
}
169
169
170
- return framework . NewStatus ( fp . returnCode , fmt . Sprintf ( "injecting failure for pod %v" , pod . Name ))
170
+ return nil
171
171
}
172
172
173
173
// newPlugin returns a plugin factory with specified Plugin.
@@ -274,25 +274,23 @@ func TestGenericScheduler(t *testing.T) {
274
274
}
275
275
276
276
tests := []struct {
277
- name string
278
- predicates map [string ]algorithmpredicates.FitPredicate
279
- prioritizers []priorities.PriorityConfig
280
- alwaysCheckAllPredicates bool
281
- nodes []string
282
- pvcs []* v1.PersistentVolumeClaim
283
- pod * v1.Pod
284
- pods []* v1.Pod
285
- buildPredMeta bool // build predicates metadata or not
286
- filterReturnCode framework.Code
287
- expectedHosts sets.String
288
- expectsErr bool
289
- wErr error
277
+ name string
278
+ predicates map [string ]algorithmpredicates.FitPredicate
279
+ prioritizers []priorities.PriorityConfig
280
+ alwaysCheckAllPredicates bool
281
+ nodes []string
282
+ pvcs []* v1.PersistentVolumeClaim
283
+ pod * v1.Pod
284
+ pods []* v1.Pod
285
+ buildPredMeta bool // build predicates metadata or not
286
+ filterFailedNodeReturnCodeMap map [string ]framework.Code
287
+ expectedHosts sets.String
288
+ wErr error
290
289
}{
291
290
{
292
291
predicates : map [string ]algorithmpredicates.FitPredicate {"false" : falsePredicate },
293
292
prioritizers : []priorities.PriorityConfig {{Map : EqualPriorityMap , Weight : 1 }},
294
293
nodes : []string {"machine1" , "machine2" },
295
- expectsErr : true ,
296
294
pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
297
295
name : "test 1" ,
298
296
wErr : & FitError {
@@ -356,7 +354,6 @@ func TestGenericScheduler(t *testing.T) {
356
354
prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
357
355
nodes : []string {"3" , "2" , "1" },
358
356
pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
359
- expectsErr : true ,
360
357
name : "test 7" ,
361
358
wErr : & FitError {
362
359
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
@@ -388,7 +385,6 @@ func TestGenericScheduler(t *testing.T) {
388
385
pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
389
386
prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
390
387
nodes : []string {"1" , "2" },
391
- expectsErr : true ,
392
388
name : "test 8" ,
393
389
wErr : & FitError {
394
390
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
@@ -443,9 +439,8 @@ func TestGenericScheduler(t *testing.T) {
443
439
},
444
440
},
445
441
},
446
- name : "unknown PVC" ,
447
- expectsErr : true ,
448
- wErr : fmt .Errorf ("persistentvolumeclaim \" unknownPVC\" not found" ),
442
+ name : "unknown PVC" ,
443
+ wErr : fmt .Errorf ("persistentvolumeclaim \" unknownPVC\" not found" ),
449
444
},
450
445
{
451
446
// Pod with deleting PVC
@@ -467,9 +462,8 @@ func TestGenericScheduler(t *testing.T) {
467
462
},
468
463
},
469
464
},
470
- name : "deleted PVC" ,
471
- expectsErr : true ,
472
- wErr : fmt .Errorf ("persistentvolumeclaim \" existingPVC\" is being deleted" ),
465
+ name : "deleted PVC" ,
466
+ wErr : fmt .Errorf ("persistentvolumeclaim \" existingPVC\" is being deleted" ),
473
467
},
474
468
{
475
469
// alwaysCheckAllPredicates is true
@@ -599,14 +593,13 @@ func TestGenericScheduler(t *testing.T) {
599
593
wErr : nil ,
600
594
},
601
595
{
602
- name : "test with filter plugin returning Unschedulable status" ,
603
- predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
604
- prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
605
- nodes : []string {"3" },
606
- pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
607
- expectedHosts : nil ,
608
- filterReturnCode : framework .Unschedulable ,
609
- expectsErr : true ,
596
+ name : "test with filter plugin returning Unschedulable status" ,
597
+ predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
598
+ prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
599
+ nodes : []string {"3" },
600
+ pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
601
+ expectedHosts : nil ,
602
+ filterFailedNodeReturnCodeMap : map [string ]framework.Code {"3" : framework .Unschedulable },
610
603
wErr : & FitError {
611
604
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
612
605
NumAllNodes : 1 ,
@@ -617,14 +610,13 @@ func TestGenericScheduler(t *testing.T) {
617
610
},
618
611
},
619
612
{
620
- name : "test with filter plugin returning UnschedulableAndUnresolvable status" ,
621
- predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
622
- prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
623
- nodes : []string {"3" },
624
- pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
625
- expectedHosts : nil ,
626
- filterReturnCode : framework .UnschedulableAndUnresolvable ,
627
- expectsErr : true ,
613
+ name : "test with filter plugin returning UnschedulableAndUnresolvable status" ,
614
+ predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
615
+ prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
616
+ nodes : []string {"3" },
617
+ pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
618
+ expectedHosts : nil ,
619
+ filterFailedNodeReturnCodeMap : map [string ]framework.Code {"3" : framework .UnschedulableAndUnresolvable },
628
620
wErr : & FitError {
629
621
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
630
622
NumAllNodes : 1 ,
@@ -634,10 +626,20 @@ func TestGenericScheduler(t *testing.T) {
634
626
},
635
627
},
636
628
},
629
+ {
630
+ name : "test with partial failed filter plugin" ,
631
+ predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
632
+ prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
633
+ nodes : []string {"1" , "2" },
634
+ pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
635
+ expectedHosts : nil ,
636
+ filterFailedNodeReturnCodeMap : map [string ]framework.Code {"1" : framework .Unschedulable },
637
+ wErr : nil ,
638
+ },
637
639
}
638
640
for _ , test := range tests {
639
641
t .Run (test .name , func (t * testing.T ) {
640
- filterPlugin .returnCode = test .filterReturnCode
642
+ filterPlugin .failedNodeReturnCodeMap = test .filterFailedNodeReturnCodeMap
641
643
642
644
cache := internalcache .New (time .Duration (0 ), wait .NeverStop )
643
645
for _ , pod := range test .pods {
@@ -678,6 +680,9 @@ func TestGenericScheduler(t *testing.T) {
678
680
if test .expectedHosts != nil && ! test .expectedHosts .Has (result .SuggestedHost ) {
679
681
t .Errorf ("Expected: %s, got: %s" , test .expectedHosts , result .SuggestedHost )
680
682
}
683
+ if test .wErr == nil && len (test .nodes ) != result .EvaluatedNodes {
684
+ t .Errorf ("Expected EvaluatedNodes: %d, got: %d" , len (test .nodes ), result .EvaluatedNodes )
685
+ }
681
686
682
687
filterPlugin .reset ()
683
688
})
@@ -1366,17 +1371,19 @@ func TestSelectNodesForPreemption(t *testing.T) {
1366
1371
labelKeys := []string {"hostname" , "zone" , "region" }
1367
1372
for _ , test := range tests {
1368
1373
t .Run (test .name , func (t * testing.T ) {
1374
+ filterFailedNodeReturnCodeMap := map [string ]framework.Code {}
1369
1375
cache := internalcache .New (time .Duration (0 ), wait .NeverStop )
1370
1376
for _ , pod := range test .pods {
1371
1377
cache .AddPod (pod )
1372
1378
}
1373
1379
for _ , name := range test .nodes {
1380
+ filterFailedNodeReturnCodeMap [name ] = test .filterReturnCode
1374
1381
cache .AddNode (& v1.Node {ObjectMeta : metav1.ObjectMeta {Name : name , Labels : map [string ]string {"hostname" : name }}})
1375
1382
}
1376
1383
1377
1384
predMetaProducer := algorithmpredicates .EmptyPredicateMetadataProducer
1378
1385
1379
- filterPlugin .returnCode = test . filterReturnCode
1386
+ filterPlugin .failedNodeReturnCodeMap = filterFailedNodeReturnCodeMap
1380
1387
scheduler := NewGenericScheduler (
1381
1388
nil ,
1382
1389
internalqueue .NewSchedulingQueue (nil , nil ),
0 commit comments