@@ -27,7 +27,7 @@ import (
27
27
"testing"
28
28
"time"
29
29
30
- "k8s.io/api/core/v1"
30
+ v1 "k8s.io/api/core/v1"
31
31
"k8s.io/apimachinery/pkg/api/resource"
32
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
33
"k8s.io/apimachinery/pkg/runtime"
65
65
errPrioritize = fmt .Errorf ("priority map encounters an error" )
66
66
)
67
67
68
+ const ErrReasonFake = "Nodes failed the fake predicate"
69
+
68
70
type trueFilterPlugin struct {}
69
71
70
72
// Name returns name of the plugin.
@@ -91,7 +93,7 @@ func (pl *falseFilterPlugin) Name() string {
91
93
92
94
// Filter invoked at the filter extension point.
93
95
func (pl * falseFilterPlugin ) Filter (_ context.Context , _ * framework.CycleState , pod * v1.Pod , nodeInfo * nodeinfo.NodeInfo ) * framework.Status {
94
- return framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () )
96
+ return framework .NewStatus (framework .Unschedulable , ErrReasonFake )
95
97
}
96
98
97
99
// NewFalseFilterPlugin initializes a falseFilterPlugin and returns it.
@@ -115,7 +117,7 @@ func (pl *matchFilterPlugin) Filter(_ context.Context, _ *framework.CycleState,
115
117
if pod .Name == node .Name {
116
118
return nil
117
119
}
118
- return framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () )
120
+ return framework .NewStatus (framework .Unschedulable , ErrReasonFake )
119
121
}
120
122
121
123
// NewMatchFilterPlugin initializes a matchFilterPlugin and returns it.
@@ -135,7 +137,7 @@ func (pl *noPodsFilterPlugin) Filter(_ context.Context, _ *framework.CycleState,
135
137
if len (nodeInfo .Pods ()) == 0 {
136
138
return nil
137
139
}
138
- return framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () )
140
+ return framework .NewStatus (framework .Unschedulable , ErrReasonFake )
139
141
}
140
142
141
143
// NewNoPodsFilterPlugin initializes a noPodsFilterPlugin and returns it.
@@ -391,8 +393,8 @@ func TestGenericScheduler(t *testing.T) {
391
393
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
392
394
NumAllNodes : 2 ,
393
395
FilteredNodesStatuses : framework.NodeToStatusMap {
394
- "machine1" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
395
- "machine2" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
396
+ "machine1" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
397
+ "machine2" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
396
398
},
397
399
},
398
400
},
@@ -464,9 +466,9 @@ func TestGenericScheduler(t *testing.T) {
464
466
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
465
467
NumAllNodes : 3 ,
466
468
FilteredNodesStatuses : framework.NodeToStatusMap {
467
- "3" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
468
- "2" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
469
- "1" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
469
+ "3" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
470
+ "2" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
471
+ "1" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
470
472
},
471
473
},
472
474
},
@@ -494,8 +496,8 @@ func TestGenericScheduler(t *testing.T) {
494
496
Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
495
497
NumAllNodes : 2 ,
496
498
FilteredNodesStatuses : framework.NodeToStatusMap {
497
- "1" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
498
- "2" : framework .NewStatus (framework .Unschedulable , algorithmpredicates . ErrFakePredicate . GetReason () ),
499
+ "1" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
500
+ "2" : framework .NewStatus (framework .Unschedulable , ErrReasonFake ),
499
501
},
500
502
},
501
503
},
@@ -860,7 +862,7 @@ func TestFindFitAllError(t *testing.T) {
860
862
t .Errorf ("failed to find node %v in %v" , node .Name , nodeToStatusMap )
861
863
}
862
864
reasons := status .Reasons ()
863
- if len (reasons ) != 1 || reasons [0 ] != algorithmpredicates . ErrFakePredicate . GetReason () {
865
+ if len (reasons ) != 1 || reasons [0 ] != ErrReasonFake {
864
866
t .Errorf ("unexpected failure reasons: %v" , reasons )
865
867
}
866
868
})
@@ -896,7 +898,7 @@ func TestFindFitSomeError(t *testing.T) {
896
898
t .Errorf ("failed to find node %v in %v" , node .Name , nodeToStatusMap )
897
899
}
898
900
reasons := status .Reasons ()
899
- if len (reasons ) != 1 || reasons [0 ] != algorithmpredicates . ErrFakePredicate . GetReason () {
901
+ if len (reasons ) != 1 || reasons [0 ] != ErrReasonFake {
900
902
t .Errorf ("unexpected failures: %v" , reasons )
901
903
}
902
904
})
@@ -985,24 +987,6 @@ func makeNode(node string, milliCPU, memory int64) *v1.Node {
985
987
}
986
988
}
987
989
988
- func TestHumanReadableFitError (t * testing.T ) {
989
- err := & FitError {
990
- Pod : & v1.Pod {ObjectMeta : metav1.ObjectMeta {Name : "2" , UID : types .UID ("2" )}},
991
- NumAllNodes : 3 ,
992
- FilteredNodesStatuses : framework.NodeToStatusMap {
993
- "1" : framework .NewStatus (framework .Unschedulable , algorithmpredicates .ErrNodeUnderMemoryPressure .GetReason ()),
994
- "2" : framework .NewStatus (framework .Unschedulable , algorithmpredicates .ErrNodeUnderDiskPressure .GetReason ()),
995
- "3" : framework .NewStatus (framework .Unschedulable , algorithmpredicates .ErrNodeUnderDiskPressure .GetReason ()),
996
- },
997
- }
998
- if strings .Contains (err .Error (), "0/3 nodes are available" ) {
999
- if strings .Contains (err .Error (), "2 node(s) had disk pressure" ) && strings .Contains (err .Error (), "1 node(s) had memory pressure" ) {
1000
- return
1001
- }
1002
- }
1003
- t .Errorf ("Error message doesn't have all the information content: [" + err .Error () + "]" )
1004
- }
1005
-
1006
990
// The point of this test is to show that you:
1007
991
// - get the same priority for a zero-request pod as for a pod with the defaults requests,
1008
992
// both when the zero-request pod is already on the machine and when the zero-request pod
@@ -1903,29 +1887,17 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
1903
1887
{
1904
1888
name : "Mix of failed predicates works fine" ,
1905
1889
nodesStatuses : framework.NodeToStatusMap {
1906
- "machine1" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeUnderDiskPressure .GetReason ()),
1907
- "machine2" : framework .NewStatus (framework .UnschedulableAndUnresolvable , volumerestrictions .ErrReasonDiskConflict ),
1908
- "machine3" : framework .NewStatus (framework .Unschedulable , algorithmpredicates .NewInsufficientResourceError (v1 .ResourceMemory , 1000 , 600 , 400 ).GetReason ()),
1909
- },
1910
- expected : map [string ]bool {"machine3" : true , "machine4" : true },
1911
- },
1912
- {
1913
- name : "Node condition errors should be considered unresolvable" ,
1914
- nodesStatuses : framework.NodeToStatusMap {
1915
- "machine1" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeUnderDiskPressure .GetReason ()),
1916
- "machine2" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeUnderPIDPressure .GetReason ()),
1917
- "machine3" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeUnderMemoryPressure .GetReason ()),
1890
+ "machine1" : framework .NewStatus (framework .UnschedulableAndUnresolvable , volumerestrictions .ErrReasonDiskConflict ),
1891
+ "machine2" : framework .NewStatus (framework .Unschedulable , algorithmpredicates .NewInsufficientResourceError (v1 .ResourceMemory , 1000 , 600 , 400 ).GetReason ()),
1918
1892
},
1919
- expected : map [string ]bool {"machine4" : true },
1893
+ expected : map [string ]bool {"machine2" : true , "machine3" : true , " machine4" : true },
1920
1894
},
1921
1895
{
1922
1896
name : "Node condition errors should be considered unresolvable" ,
1923
1897
nodesStatuses : framework.NodeToStatusMap {
1924
- "machine1" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeNotReady .GetReason ()),
1925
- "machine2" : framework .NewStatus (framework .UnschedulableAndUnresolvable , algorithmpredicates .ErrNodeNetworkUnavailable .GetReason ()),
1926
- "machine3" : framework .NewStatus (framework .UnschedulableAndUnresolvable , nodeunschedulable .ErrReasonUnknownCondition ),
1898
+ "machine1" : framework .NewStatus (framework .UnschedulableAndUnresolvable , nodeunschedulable .ErrReasonUnknownCondition ),
1927
1899
},
1928
- expected : map [string ]bool {"machine4" : true },
1900
+ expected : map [string ]bool {"machine2" : true , "machine3" : true , " machine4" : true },
1929
1901
},
1930
1902
{
1931
1903
name : "ErrVolume... errors should not be tried as it indicates that the pod is unschedulable due to no matching volumes for pod on node" ,
0 commit comments