@@ -144,7 +144,7 @@ var emptyFramework, _ = framework.NewFramework(EmptyPluginRegistry, nil, []sched
144
144
// FakeFilterPlugin is a test filter plugin used by default scheduler.
145
145
type FakeFilterPlugin struct {
146
146
numFilterCalled int32
147
- failFilter bool
147
+ returnCode framework. Code
148
148
}
149
149
150
150
var filterPlugin = & FakeFilterPlugin {}
@@ -157,19 +157,19 @@ func (fp *FakeFilterPlugin) Name() string {
157
157
// reset is used to reset filter plugin.
158
158
func (fp * FakeFilterPlugin ) reset () {
159
159
fp .numFilterCalled = 0
160
- fp .failFilter = false
160
+ fp .returnCode = framework . Success
161
161
}
162
162
163
163
// Filter is a test function that returns an error or nil, depending on the
164
164
// value of "failFilter".
165
165
func (fp * FakeFilterPlugin ) Filter (pc * framework.PluginContext , pod * v1.Pod , nodeName string ) * framework.Status {
166
166
atomic .AddInt32 (& fp .numFilterCalled , 1 )
167
167
168
- if fp .failFilter {
169
- return framework . NewStatus ( framework . Unschedulable , fmt . Sprintf ( "injecting failure for pod %v" , pod . Name ))
168
+ if fp .returnCode == framework . Success {
169
+ return nil
170
170
}
171
171
172
- return nil
172
+ return framework . NewStatus ( fp . returnCode , fmt . Sprintf ( "injecting failure for pod %v" , pod . Name ))
173
173
}
174
174
175
175
// NewFilterPlugin is the factory for filter plugin.
@@ -282,7 +282,7 @@ func TestGenericScheduler(t *testing.T) {
282
282
pod * v1.Pod
283
283
pods []* v1.Pod
284
284
buildPredMeta bool // build predicates metadata or not
285
- failFilter bool
285
+ filterReturnCode framework. Code
286
286
expectedHosts sets.String
287
287
expectsErr bool
288
288
wErr error
@@ -598,14 +598,14 @@ func TestGenericScheduler(t *testing.T) {
598
598
wErr : nil ,
599
599
},
600
600
{
601
- name : "test with failed filter plugin" ,
602
- predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
603
- prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
604
- nodes : []string {"3" },
605
- pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
606
- expectedHosts : nil ,
607
- failFilter : true ,
608
- expectsErr : true ,
601
+ name : "test with filter plugin returning Unschedulable status " ,
602
+ predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
603
+ prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
604
+ nodes : []string {"3" },
605
+ pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
606
+ expectedHosts : nil ,
607
+ filterReturnCode : framework . Unschedulable ,
608
+ expectsErr : true ,
609
609
wErr : & FitError {
610
610
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
611
611
NumAllNodes : 1 ,
@@ -615,10 +615,28 @@ func TestGenericScheduler(t *testing.T) {
615
615
},
616
616
},
617
617
},
618
+ {
619
+ name : "test with filter plugin returning UnschedulableAndUnresolvable status" ,
620
+ predicates : map [string ]algorithmpredicates.FitPredicate {"true" : truePredicate },
621
+ prioritizers : []priorities.PriorityConfig {{Function : numericPriority , Weight : 1 }},
622
+ nodes : []string {"3" },
623
+ pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
624
+ expectedHosts : nil ,
625
+ filterReturnCode : framework .UnschedulableAndUnresolvable ,
626
+ expectsErr : true ,
627
+ wErr : & FitError {
628
+ Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "test-filter" , UID : types .UID ("test-filter" )}},
629
+ NumAllNodes : 1 ,
630
+ FailedPredicates : FailedPredicateMap {},
631
+ FilteredNodesStatuses : framework.NodeToStatusMap {
632
+ "3" : framework .NewStatus (framework .UnschedulableAndUnresolvable , "injecting failure for pod test-filter" ),
633
+ },
634
+ },
635
+ },
618
636
}
619
637
for _ , test := range tests {
620
638
t .Run (test .name , func (t * testing.T ) {
621
- filterPlugin .failFilter = test .failFilter
639
+ filterPlugin .returnCode = test .filterReturnCode
622
640
623
641
cache := internalcache .New (time .Duration (0 ), wait .NeverStop )
624
642
for _ , pod := range test .pods {
@@ -1561,14 +1579,15 @@ func TestPickOneNodeForPreemption(t *testing.T) {
1561
1579
1562
1580
func TestNodesWherePreemptionMightHelp (t * testing.T ) {
1563
1581
// Prepare 4 node names.
1564
- nodeNames := []string {}
1582
+ nodeNames := make ( []string , 0 , 4 )
1565
1583
for i := 1 ; i < 5 ; i ++ {
1566
1584
nodeNames = append (nodeNames , fmt .Sprintf ("machine%d" , i ))
1567
1585
}
1568
1586
1569
1587
tests := []struct {
1570
1588
name string
1571
1589
failedPredMap FailedPredicateMap
1590
+ nodesStatuses framework.NodeToStatusMap
1572
1591
expected map [string ]bool // set of expected node names. Value is ignored.
1573
1592
}{
1574
1593
{
@@ -1652,11 +1671,41 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
1652
1671
},
1653
1672
expected : map [string ]bool {"machine1" : true , "machine3" : true , "machine4" : true },
1654
1673
},
1674
+ {
1675
+ name : "UnschedulableAndUnresolvable status should be skipped but Unschedulable should be tried" ,
1676
+ failedPredMap : FailedPredicateMap {},
1677
+ nodesStatuses : framework.NodeToStatusMap {
1678
+ "machine2" : framework .NewStatus (framework .UnschedulableAndUnresolvable , "" ),
1679
+ "machine3" : framework .NewStatus (framework .Unschedulable , "" ),
1680
+ "machine4" : framework .NewStatus (framework .UnschedulableAndUnresolvable , "" ),
1681
+ },
1682
+ expected : map [string ]bool {"machine1" : true , "machine3" : true },
1683
+ },
1684
+ {
1685
+ name : "Failed predicates and statuses should be evaluated" ,
1686
+ failedPredMap : FailedPredicateMap {
1687
+ "machine1" : []algorithmpredicates.PredicateFailureReason {algorithmpredicates .ErrPodAffinityNotMatch },
1688
+ "machine2" : []algorithmpredicates.PredicateFailureReason {algorithmpredicates .ErrPodAffinityNotMatch },
1689
+ "machine3" : []algorithmpredicates.PredicateFailureReason {algorithmpredicates .ErrPodNotMatchHostName },
1690
+ "machine4" : []algorithmpredicates.PredicateFailureReason {algorithmpredicates .ErrPodNotMatchHostName },
1691
+ },
1692
+ nodesStatuses : framework.NodeToStatusMap {
1693
+ "machine1" : framework .NewStatus (framework .Unschedulable , "" ),
1694
+ "machine2" : framework .NewStatus (framework .UnschedulableAndUnresolvable , "" ),
1695
+ "machine3" : framework .NewStatus (framework .Unschedulable , "" ),
1696
+ "machine4" : framework .NewStatus (framework .UnschedulableAndUnresolvable , "" ),
1697
+ },
1698
+ expected : map [string ]bool {"machine1" : true },
1699
+ },
1655
1700
}
1656
1701
1657
1702
for _ , test := range tests {
1658
1703
t .Run (test .name , func (t * testing.T ) {
1659
- nodes := nodesWherePreemptionMightHelp (makeNodeList (nodeNames ), test .failedPredMap )
1704
+ fitErr := FitError {
1705
+ FailedPredicates : test .failedPredMap ,
1706
+ FilteredNodesStatuses : test .nodesStatuses ,
1707
+ }
1708
+ nodes := nodesWherePreemptionMightHelp (makeNodeList (nodeNames ), & fitErr )
1660
1709
if len (test .expected ) != len (nodes ) {
1661
1710
t .Errorf ("number of nodes is not the same as expected. exptectd: %d, got: %d. Nodes: %v" , len (test .expected ), len (nodes ), nodes )
1662
1711
}
0 commit comments