Skip to content

Commit 408c9da

Browse files
author
zouyee
committed
LeastRequestedPriority/MostRequestedPriority/BalancedResourceAllocation as Score plugins
Signed-off-by: Zou Nengren <[email protected]>
1 parent 3ebee37 commit 408c9da

File tree

11 files changed

+1224
-72
lines changed

11 files changed

+1224
-72
lines changed

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
9696
"TestLabelsPresence",
9797
),
9898
wantPrioritizers: sets.NewString(
99-
"LeastRequestedPriority",
10099
"ServiceSpreadingPriority",
101100
"TestServiceAntiAffinity",
102101
"TestLabelPreference",
@@ -109,6 +108,9 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
109108
{Name: "VolumeRestrictions"},
110109
{Name: "TaintToleration"},
111110
},
111+
"ScorePlugin": {
112+
{Name: "NodeResourcesLeastAllocated", Weight: 1},
113+
},
112114
},
113115
},
114116

@@ -141,8 +143,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
141143
),
142144
wantPrioritizers: sets.NewString(
143145
"EqualPriority",
144-
"LeastRequestedPriority",
145-
"BalancedResourceAllocation",
146146
"SelectorSpreadPriority",
147147
"TestServiceAntiAffinity",
148148
"TestLabelPreference",
@@ -157,6 +157,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
157157
{Name: "VolumeRestrictions"},
158158
{Name: "TaintToleration"},
159159
},
160+
"ScorePlugin": {
161+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
162+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
163+
},
160164
},
161165
},
162166

@@ -198,8 +202,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
198202
),
199203
wantPrioritizers: sets.NewString(
200204
"EqualPriority",
201-
"LeastRequestedPriority",
202-
"BalancedResourceAllocation",
203205
"SelectorSpreadPriority",
204206
"TestServiceAntiAffinity",
205207
"TestLabelPreference",
@@ -216,7 +218,9 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
216218
{Name: "VolumeZone"},
217219
},
218220
"ScorePlugin": {
221+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
219222
{Name: "ImageLocality", Weight: 2},
223+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
220224
{Name: "NodeAffinity", Weight: 2},
221225
},
222226
},
@@ -264,8 +268,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
264268
),
265269
wantPrioritizers: sets.NewString(
266270
"EqualPriority",
267-
"LeastRequestedPriority",
268-
"BalancedResourceAllocation",
269271
"SelectorSpreadPriority",
270272
"InterPodAffinityPriority",
271273
),
@@ -282,7 +284,9 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
282284
{Name: "InterPodAffinity"},
283285
},
284286
"ScorePlugin": {
287+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
285288
{Name: "ImageLocality", Weight: 2},
289+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
286290
{Name: "NodeAffinity", Weight: 2},
287291
{Name: "TaintToleration", Weight: 2},
288292
},
@@ -335,11 +339,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
335339
),
336340
wantPrioritizers: sets.NewString(
337341
"EqualPriority",
338-
"LeastRequestedPriority",
339-
"BalancedResourceAllocation",
340342
"SelectorSpreadPriority",
341343
"InterPodAffinityPriority",
342-
"MostRequestedPriority",
343344
),
344345
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
345346
"FilterPlugin": {
@@ -354,7 +355,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
354355
{Name: "InterPodAffinity"},
355356
},
356357
"ScorePlugin": {
358+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
357359
{Name: "ImageLocality", Weight: 2},
360+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
361+
{Name: "NodeResourcesMostAllocated", Weight: 2},
358362
{Name: "NodeAffinity", Weight: 2},
359363
{Name: "NodePreferAvoidPods", Weight: 2},
360364
{Name: "TaintToleration", Weight: 2},
@@ -417,11 +421,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
417421
),
418422
wantPrioritizers: sets.NewString(
419423
"EqualPriority",
420-
"LeastRequestedPriority",
421-
"BalancedResourceAllocation",
422424
"SelectorSpreadPriority",
423425
"InterPodAffinityPriority",
424-
"MostRequestedPriority",
425426
),
426427
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
427428
"FilterPlugin": {
@@ -436,7 +437,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
436437
{Name: "InterPodAffinity"},
437438
},
438439
"ScorePlugin": {
440+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
439441
{Name: "ImageLocality", Weight: 2},
442+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
443+
{Name: "NodeResourcesMostAllocated", Weight: 2},
440444
{Name: "NodeAffinity", Weight: 2},
441445
{Name: "NodePreferAvoidPods", Weight: 2},
442446
{Name: "TaintToleration", Weight: 2},
@@ -512,11 +516,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
512516
),
513517
wantPrioritizers: sets.NewString(
514518
"EqualPriority",
515-
"LeastRequestedPriority",
516-
"BalancedResourceAllocation",
517519
"SelectorSpreadPriority",
518520
"InterPodAffinityPriority",
519-
"MostRequestedPriority",
520521
),
521522
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
522523
"FilterPlugin": {
@@ -531,7 +532,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
531532
{Name: "InterPodAffinity"},
532533
},
533534
"ScorePlugin": {
535+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
534536
{Name: "ImageLocality", Weight: 2},
537+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
538+
{Name: "NodeResourcesMostAllocated", Weight: 2},
535539
{Name: "NodeAffinity", Weight: 2},
536540
{Name: "NodePreferAvoidPods", Weight: 2},
537541
{Name: "TaintToleration", Weight: 2},
@@ -608,11 +612,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
608612
),
609613
wantPrioritizers: sets.NewString(
610614
"EqualPriority",
611-
"LeastRequestedPriority",
612-
"BalancedResourceAllocation",
613615
"SelectorSpreadPriority",
614616
"InterPodAffinityPriority",
615-
"MostRequestedPriority",
616617
),
617618
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
618619
"FilterPlugin": {
@@ -628,7 +629,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
628629
{Name: "InterPodAffinity"},
629630
},
630631
"ScorePlugin": {
632+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
631633
{Name: "ImageLocality", Weight: 2},
634+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
635+
{Name: "NodeResourcesMostAllocated", Weight: 2},
632636
{Name: "NodeAffinity", Weight: 2},
633637
{Name: "NodePreferAvoidPods", Weight: 2},
634638
{Name: "TaintToleration", Weight: 2},
@@ -710,11 +714,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
710714
),
711715
wantPrioritizers: sets.NewString(
712716
"EqualPriority",
713-
"LeastRequestedPriority",
714-
"BalancedResourceAllocation",
715717
"SelectorSpreadPriority",
716718
"InterPodAffinityPriority",
717-
"MostRequestedPriority",
718719
),
719720
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
720721
"FilterPlugin": {
@@ -730,7 +731,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
730731
{Name: "InterPodAffinity"},
731732
},
732733
"ScorePlugin": {
734+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
733735
{Name: "ImageLocality", Weight: 2},
736+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
737+
{Name: "NodeResourcesMostAllocated", Weight: 2},
734738
{Name: "NodeAffinity", Weight: 2},
735739
{Name: "NodePreferAvoidPods", Weight: 2},
736740
{Name: "TaintToleration", Weight: 2},
@@ -824,11 +828,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
824828
),
825829
wantPrioritizers: sets.NewString(
826830
"EqualPriority",
827-
"LeastRequestedPriority",
828-
"BalancedResourceAllocation",
829831
"SelectorSpreadPriority",
830832
"InterPodAffinityPriority",
831-
"MostRequestedPriority",
832833
"RequestedToCapacityRatioPriority",
833834
),
834835
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
@@ -845,7 +846,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
845846
{Name: "InterPodAffinity"},
846847
},
847848
"ScorePlugin": {
849+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
848850
{Name: "ImageLocality", Weight: 2},
851+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
852+
{Name: "NodeResourcesMostAllocated", Weight: 2},
849853
{Name: "NodeAffinity", Weight: 2},
850854
{Name: "NodePreferAvoidPods", Weight: 2},
851855
{Name: "TaintToleration", Weight: 2},
@@ -940,11 +944,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
940944
),
941945
wantPrioritizers: sets.NewString(
942946
"EqualPriority",
943-
"LeastRequestedPriority",
944-
"BalancedResourceAllocation",
945947
"SelectorSpreadPriority",
946948
"InterPodAffinityPriority",
947-
"MostRequestedPriority",
948949
"RequestedToCapacityRatioPriority",
949950
),
950951
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
@@ -962,7 +963,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
962963
{Name: "InterPodAffinity"},
963964
},
964965
"ScorePlugin": {
966+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
965967
{Name: "ImageLocality", Weight: 2},
968+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
969+
{Name: "NodeResourcesMostAllocated", Weight: 2},
966970
{Name: "NodeAffinity", Weight: 2},
967971
{Name: "NodePreferAvoidPods", Weight: 2},
968972
{Name: "TaintToleration", Weight: 2},
@@ -1057,11 +1061,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10571061
),
10581062
wantPrioritizers: sets.NewString(
10591063
"EqualPriority",
1060-
"LeastRequestedPriority",
1061-
"BalancedResourceAllocation",
10621064
"SelectorSpreadPriority",
10631065
"InterPodAffinityPriority",
1064-
"MostRequestedPriority",
10651066
"RequestedToCapacityRatioPriority",
10661067
),
10671068
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
@@ -1079,7 +1080,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10791080
{Name: "InterPodAffinity"},
10801081
},
10811082
"ScorePlugin": {
1083+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
10821084
{Name: "ImageLocality", Weight: 2},
1085+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
1086+
{Name: "NodeResourcesMostAllocated", Weight: 2},
10831087
{Name: "NodeAffinity", Weight: 2},
10841088
{Name: "NodePreferAvoidPods", Weight: 2},
10851089
{Name: "TaintToleration", Weight: 2},
@@ -1178,11 +1182,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11781182
),
11791183
wantPrioritizers: sets.NewString(
11801184
"EqualPriority",
1181-
"LeastRequestedPriority",
1182-
"BalancedResourceAllocation",
11831185
"SelectorSpreadPriority",
11841186
"InterPodAffinityPriority",
1185-
"MostRequestedPriority",
11861187
"RequestedToCapacityRatioPriority",
11871188
),
11881189
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
@@ -1200,7 +1201,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12001201
{Name: "InterPodAffinity"},
12011202
},
12021203
"ScorePlugin": {
1204+
{Name: "NodeResourcesBalancedAllocation", Weight: 2},
12031205
{Name: "ImageLocality", Weight: 2},
1206+
{Name: "NodeResourcesLeastAllocated", Weight: 2},
1207+
{Name: "NodeResourcesMostAllocated", Weight: 2},
12041208
{Name: "NodeAffinity", Weight: 2},
12051209
{Name: "NodePreferAvoidPods", Weight: 2},
12061210
{Name: "TaintToleration", Weight: 2},
@@ -1241,10 +1245,13 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12411245
"InterPodAffinity": "MatchInterPodAffinity",
12421246
}
12431247
scoreToPriorityMap := map[string]string{
1244-
"ImageLocality": "ImageLocalityPriority",
1245-
"NodeAffinity": "NodeAffinityPriority",
1246-
"NodePreferAvoidPods": "NodePreferAvoidPodsPriority",
1247-
"TaintToleration": "TaintTolerationPriority",
1248+
"ImageLocality": "ImageLocalityPriority",
1249+
"NodeAffinity": "NodeAffinityPriority",
1250+
"NodePreferAvoidPods": "NodePreferAvoidPodsPriority",
1251+
"TaintToleration": "TaintTolerationPriority",
1252+
"NodeResourcesLeastAllocated": "LeastRequestedPriority",
1253+
"NodeResourcesBalancedAllocation": "BalancedResourceAllocation",
1254+
"NodeResourcesMostAllocated": "MostRequestedPriority",
12481255
}
12491256

12501257
for v, tc := range schedulerFiles {

pkg/scheduler/framework/plugins/default_registry.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,18 @@ type RegistryArgs struct {
5353
// runs custom plugins, can pass a different Registry when initializing the scheduler.
5454
func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
5555
return framework.Registry{
56-
imagelocality.Name: imagelocality.New,
57-
tainttoleration.Name: tainttoleration.New,
58-
noderesources.Name: noderesources.New,
59-
nodename.Name: nodename.New,
60-
nodeports.Name: nodeports.New,
61-
nodepreferavoidpods.Name: nodepreferavoidpods.New,
62-
nodeaffinity.Name: nodeaffinity.New,
63-
podtopologyspread.Name: podtopologyspread.New,
64-
nodeunschedulable.Name: nodeunschedulable.New,
56+
imagelocality.Name: imagelocality.New,
57+
tainttoleration.Name: tainttoleration.New,
58+
noderesources.Name: noderesources.New,
59+
nodename.Name: nodename.New,
60+
nodeports.Name: nodeports.New,
61+
nodepreferavoidpods.Name: nodepreferavoidpods.New,
62+
nodeaffinity.Name: nodeaffinity.New,
63+
podtopologyspread.Name: podtopologyspread.New,
64+
nodeunschedulable.Name: nodeunschedulable.New,
65+
noderesources.BalancedAllocationName: noderesources.NewBalancedAllocation,
66+
noderesources.MostAllocatedName: noderesources.NewMostAllocated,
67+
noderesources.LeastAllocatedName: noderesources.NewLeastAllocated,
6568
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
6669
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
6770
},
@@ -190,6 +193,24 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
190193
return
191194
})
192195

196+
registry.RegisterPriority(priorities.MostRequestedPriority,
197+
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
198+
plugins.Score = appendToPluginSet(plugins.Score, noderesources.MostAllocatedName, &args.Weight)
199+
return
200+
})
201+
202+
registry.RegisterPriority(priorities.BalancedResourceAllocation,
203+
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
204+
plugins.Score = appendToPluginSet(plugins.Score, noderesources.BalancedAllocationName, &args.Weight)
205+
return
206+
})
207+
208+
registry.RegisterPriority(priorities.LeastRequestedPriority,
209+
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
210+
plugins.Score = appendToPluginSet(plugins.Score, noderesources.LeastAllocatedName, &args.Weight)
211+
return
212+
})
213+
193214
return registry
194215
}
195216

0 commit comments

Comments
 (0)