@@ -184,7 +184,7 @@ func TestPostFilter(t *testing.T) {
184
184
tests := []struct {
185
185
name string
186
186
pod * v1.Pod
187
- pods []* v1.Pod
187
+ existPods []* v1.Pod
188
188
nodes []* v1.Node
189
189
filteredNodesStatuses framework.NodeToStatusMap
190
190
elasticQuotas map [string ]* ElasticQuotaInfo
@@ -194,7 +194,7 @@ func TestPostFilter(t *testing.T) {
194
194
{
195
195
name : "in-namespace preemption" ,
196
196
pod : makePod ("t1-p1" , "ns1" , 50 , 0 , 0 , highPriority , "t1-p1" , "" ),
197
- pods : []* v1.Pod {
197
+ existPods : []* v1.Pod {
198
198
makePod ("t1-p2" , "ns1" , 50 , 0 , 0 , midPriority , "t1-p2" , "node-a" ),
199
199
makePod ("t1-p3" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p3" , "node-a" ),
200
200
makePod ("t1-p4" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p4" , "node-a" ),
@@ -237,7 +237,7 @@ func TestPostFilter(t *testing.T) {
237
237
{
238
238
name : "cross-namespace preemption" ,
239
239
pod : makePod ("t1-p1" , "ns1" , 50 , 0 , 0 , highPriority , "t1-p1" , "" ),
240
- pods : []* v1.Pod {
240
+ existPods : []* v1.Pod {
241
241
makePod ("t1-p2" , "ns1" , 50 , 0 , 0 , midPriority , "t1-p2" , "node-a" ),
242
242
makePod ("t1-p3" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p3" , "node-a" ),
243
243
makePod ("t1-p4" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p4" , "node-a" ),
@@ -278,9 +278,9 @@ func TestPostFilter(t *testing.T) {
278
278
wantStatus : framework .NewStatus (framework .Success ),
279
279
},
280
280
{
281
- name : "Without elasticQuotas" ,
281
+ name : "without elasticQuotas" ,
282
282
pod : makePod ("t1-p1" , "ns1" , 50 , 0 , 0 , highPriority , "t1-p1" , "" ),
283
- pods : []* v1.Pod {
283
+ existPods : []* v1.Pod {
284
284
makePod ("t1-p2" , "ns1" , 50 , 0 , 0 , midPriority , "t1-p2" , "node-a" ),
285
285
makePod ("t1-p3" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p3" , "node-a" ),
286
286
makePod ("t1-p4" , "ns2" , 50 , 0 , 0 , midPriority , "t1-p4" , "node-a" ),
@@ -299,24 +299,18 @@ func TestPostFilter(t *testing.T) {
299
299
300
300
for _ , tt := range tests {
301
301
t .Run (tt .name , func (t * testing.T ) {
302
- registeredPlugins := []st.RegisterPluginFunc {
303
- st .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
304
- st .RegisterBindPlugin (defaultbinder .Name , defaultbinder .New ),
305
- st .RegisterPluginAsExtensions (noderesources .Name , func (plArgs apiruntime.Object , fh framework.Handle ) (framework.Plugin , error ) {
306
- return noderesources .NewFit (plArgs , fh , plfeature.Features {})
307
- }, "Filter" , "PreFilter" ),
308
- }
302
+ registeredPlugins := makeRegisteredPlugin ()
309
303
310
304
podItems := []v1.Pod {}
311
- for _ , pod := range tt .pods {
305
+ for _ , pod := range tt .existPods {
312
306
podItems = append (podItems , * pod )
313
307
}
314
308
cs := clientsetfake .NewSimpleClientset (& v1.PodList {Items : podItems })
315
309
informerFactory := informers .NewSharedInformerFactory (cs , 0 )
316
310
podInformer := informerFactory .Core ().V1 ().Pods ().Informer ()
317
311
podInformer .GetStore ().Add (tt .pod )
318
- for i := range tt .pods {
319
- podInformer .GetStore ().Add (tt .pods [i ])
312
+ for i := range tt .existPods {
313
+ podInformer .GetStore ().Add (tt .existPods [i ])
320
314
}
321
315
ctx , cancel := context .WithCancel (context .Background ())
322
316
defer cancel ()
@@ -329,7 +323,7 @@ func TestPostFilter(t *testing.T) {
329
323
frameworkruntime .WithEventRecorder (& events.FakeRecorder {}),
330
324
frameworkruntime .WithInformerFactory (informerFactory ),
331
325
frameworkruntime .WithPodNominator (testutil .NewPodNominator (informerFactory .Core ().V1 ().Pods ().Lister ())),
332
- frameworkruntime .WithSnapshotSharedLister (testutil .NewFakeSharedLister (tt .pods , tt .nodes )),
326
+ frameworkruntime .WithSnapshotSharedLister (testutil .NewFakeSharedLister (tt .existPods , tt .nodes )),
333
327
)
334
328
if err != nil {
335
329
t .Fatal (err )
@@ -360,14 +354,8 @@ func TestPostFilter(t *testing.T) {
360
354
pdbLister : getPDBLister (informerFactory ),
361
355
}
362
356
gotResult , gotStatus := c .PostFilter (ctx , state , tt .pod , tt .filteredNodesStatuses )
363
- if gotStatus .Code () == framework .Error {
364
- if diff := gocmp .Diff (tt .wantStatus .Reasons (), gotStatus .Reasons ()); diff != "" {
365
- t .Errorf ("Unexpected status (-want, +got):\n %s" , diff )
366
- }
367
- } else {
368
- if diff := gocmp .Diff (tt .wantStatus , gotStatus ); diff != "" {
369
- t .Errorf ("Unexpected status (-want, +got):\n %s" , diff )
370
- }
357
+ if diff := gocmp .Diff (tt .wantStatus , gotStatus ); diff != "" {
358
+ t .Errorf ("Unexpected status (-want, +got):\n %s" , diff )
371
359
}
372
360
if diff := gocmp .Diff (tt .wantResult , gotResult ); diff != "" {
373
361
t .Errorf ("Unexpected postFilterResult (-want, +got):\n %s" , diff )
@@ -722,13 +710,7 @@ func TestDryRunPreemption(t *testing.T) {
722
710
723
711
for _ , tt := range tests {
724
712
t .Run (tt .name , func (t * testing.T ) {
725
- registeredPlugins := []st.RegisterPluginFunc {
726
- st .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
727
- st .RegisterBindPlugin (defaultbinder .Name , defaultbinder .New ),
728
- st .RegisterPluginAsExtensions (noderesources .Name , func (plArgs apiruntime.Object , fh framework.Handle ) (framework.Plugin , error ) {
729
- return noderesources .NewFit (plArgs , fh , plfeature.Features {})
730
- }, "Filter" , "PreFilter" ),
731
- }
713
+ registeredPlugins := makeRegisteredPlugin ()
732
714
733
715
cs := clientsetfake .NewSimpleClientset ()
734
716
ctx := context .Background ()
@@ -815,16 +797,16 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
815
797
tests := []struct {
816
798
name string
817
799
pod * v1.Pod
818
- pods []* v1.Pod
800
+ existPods []* v1.Pod
819
801
nodes []* v1.Node
820
802
nominatedNodeStatus * framework.Status
821
803
elasticQuotas map [string ]* ElasticQuotaInfo
822
804
expected bool
823
805
}{
824
806
{
825
- name : "Pod with PreemptNever preemption policy" ,
826
- pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Priority (highPriority ).PreemptionPolicy (v1 .PreemptNever ).Obj (),
827
- pods : []* v1.Pod {makePod ("t1-p0" , "ns1" , 50 , 10 , 0 , midPriority , "t1-p1" , "node-a" )},
807
+ name : "Pod with PreemptNever preemption policy" ,
808
+ pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Priority (highPriority ).PreemptionPolicy (v1 .PreemptNever ).Obj (),
809
+ existPods : []* v1.Pod {makePod ("t1-p0" , "ns1" , 50 , 10 , 0 , midPriority , "t1-p1" , "node-a" )},
828
810
nodes : []* v1.Node {
829
811
st .MakeNode ().Name ("node-a" ).Capacity (res ).Obj (),
830
812
},
@@ -846,9 +828,9 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
846
828
expected : false ,
847
829
},
848
830
{
849
- name : "Pod with nominated node" ,
850
- pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
851
- pods : []* v1.Pod {makePod ("t1-p0" , "ns1" , 50 , 10 , 0 , midPriority , "t1-p1" , "node-a" )},
831
+ name : "Pod with unschedulableAndUnresolvable nominated node" ,
832
+ pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
833
+ existPods : []* v1.Pod {makePod ("t1-p0" , "ns1" , 50 , 10 , 0 , midPriority , "t1-p1" , "node-a" )},
852
834
nodes : []* v1.Node {
853
835
st .MakeNode ().Name ("node-a" ).Capacity (res ).Obj (),
854
836
},
@@ -872,7 +854,7 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
872
854
{
873
855
name : "Pod with terminating pod in the same namespace" ,
874
856
pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Namespace ("ns1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
875
- pods : []* v1.Pod {
857
+ existPods : []* v1.Pod {
876
858
st .MakePod ().Name ("t1-p0" ).UID ("t1-p0" ).Namespace ("ns1" ).Priority (midPriority ).Node ("node-a" ).Terminating ().Obj (),
877
859
},
878
860
nodes : []* v1.Node {
@@ -896,9 +878,9 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
896
878
expected : false ,
897
879
},
898
880
{
899
- name : "Pod with terminating pod in the different namespace" ,
881
+ name : "Pod with terminating pod in another namespace" ,
900
882
pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Namespace ("ns1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
901
- pods : []* v1.Pod {
883
+ existPods : []* v1.Pod {
902
884
st .MakePod ().Name ("t1-p0" ).UID ("t1-p0" ).Namespace ("ns2" ).Priority (midPriority ).Node ("node-a" ).Terminating ().Obj (),
903
885
},
904
886
nodes : []* v1.Node {
@@ -934,9 +916,9 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
934
916
expected : false ,
935
917
},
936
918
{
937
- name : "Pod without ElasticQuotas and terminating pod exists" ,
919
+ name : "Pod without elasticQuotas and terminating pod exists in the same namespace " ,
938
920
pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Namespace ("ns1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
939
- pods : []* v1.Pod {
921
+ existPods : []* v1.Pod {
940
922
st .MakePod ().Name ("t1-p0" ).UID ("t1-p0" ).Namespace ("ns2" ).Priority (midPriority ).Node ("node-a" ).Terminating ().Obj (),
941
923
},
942
924
nodes : []* v1.Node {
@@ -947,9 +929,9 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
947
929
expected : false ,
948
930
},
949
931
{
950
- name : "Pod with other namespace's ElasticQuotas and terminating pod exists" ,
932
+ name : "Pod without ElasticQuotas and terminating pod exists in another namespace " ,
951
933
pod : st .MakePod ().Name ("t1-p1" ).UID ("t1-p1" ).Namespace ("ns1" ).Priority (highPriority ).NominatedNodeName ("node-a" ).Obj (),
952
- pods : []* v1.Pod {
934
+ existPods : []* v1.Pod {
953
935
st .MakePod ().Name ("t1-p0" ).UID ("t1-p0" ).Namespace ("ns2" ).Priority (midPriority ).Node ("node-a" ).Terminating ().Obj (),
954
936
},
955
937
nodes : []* v1.Node {
@@ -976,13 +958,7 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
976
958
977
959
for _ , tt := range tests {
978
960
t .Run (tt .name , func (t * testing.T ) {
979
- registeredPlugins := []st.RegisterPluginFunc {
980
- st .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
981
- st .RegisterBindPlugin (defaultbinder .Name , defaultbinder .New ),
982
- st .RegisterPluginAsExtensions (noderesources .Name , func (plArgs apiruntime.Object , fh framework.Handle ) (framework.Plugin , error ) {
983
- return noderesources .NewFit (plArgs , fh , plfeature.Features {})
984
- }, "Filter" , "PreFilter" ),
985
- }
961
+ registeredPlugins := makeRegisteredPlugin ()
986
962
cs := clientsetfake .NewSimpleClientset ()
987
963
ctx := context .Background ()
988
964
@@ -993,7 +969,7 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
993
969
frameworkruntime .WithClientSet (cs ),
994
970
frameworkruntime .WithEventRecorder (& events.FakeRecorder {}),
995
971
frameworkruntime .WithPodNominator (testutil .NewPodNominator (nil )),
996
- frameworkruntime .WithSnapshotSharedLister (testutil .NewFakeSharedLister (tt .pods , tt .nodes )),
972
+ frameworkruntime .WithSnapshotSharedLister (testutil .NewFakeSharedLister (tt .existPods , tt .nodes )),
997
973
frameworkruntime .WithInformerFactory (informers .NewSharedInformerFactory (cs , 0 )),
998
974
)
999
975
if err != nil {
@@ -1632,3 +1608,14 @@ func makeResourceList(cpu, mem int64) v1.ResourceList {
1632
1608
v1 .ResourceMemory : * resource .NewQuantity (mem , resource .BinarySI ),
1633
1609
}
1634
1610
}
1611
+
1612
+ func makeRegisteredPlugin () []st.RegisterPluginFunc {
1613
+ registeredPlugins := []st.RegisterPluginFunc {
1614
+ st .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
1615
+ st .RegisterBindPlugin (defaultbinder .Name , defaultbinder .New ),
1616
+ st .RegisterPluginAsExtensions (noderesources .Name , func (plArgs apiruntime.Object , fh framework.Handle ) (framework.Plugin , error ) {
1617
+ return noderesources .NewFit (plArgs , fh , plfeature.Features {})
1618
+ }, "Filter" , "PreFilter" ),
1619
+ }
1620
+ return registeredPlugins
1621
+ }
0 commit comments