Skip to content

Commit 05b6c32

Browse files
authored
Merge pull request kubernetes#87261 from Huang-Wei/sched-q-sort
Implement default queue sort logic as a scheduler plugin
2 parents fdd575f + c712230 commit 05b6c32

File tree

23 files changed

+648
-270
lines changed

23 files changed

+648
-270
lines changed

pkg/scheduler/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//pkg/scheduler/framework/plugins:go_default_library",
2222
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
2323
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
24+
"//pkg/scheduler/framework/plugins/queuesort:go_default_library",
2425
"//pkg/scheduler/framework/v1alpha1:go_default_library",
2526
"//pkg/scheduler/internal/cache:go_default_library",
2627
"//pkg/scheduler/internal/cache/debugger:go_default_library",
@@ -71,6 +72,7 @@ go_test(
7172
"//pkg/scheduler/framework/plugins/nodelabel:go_default_library",
7273
"//pkg/scheduler/framework/plugins/nodeports:go_default_library",
7374
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
75+
"//pkg/scheduler/framework/plugins/queuesort:go_default_library",
7476
"//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library",
7577
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
7678
"//pkg/scheduler/framework/v1alpha1:go_default_library",

pkg/scheduler/algorithmprovider/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ go_library(
2424
"//pkg/scheduler/framework/plugins/nodeunschedulable:go_default_library",
2525
"//pkg/scheduler/framework/plugins/nodevolumelimits:go_default_library",
2626
"//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library",
27+
"//pkg/scheduler/framework/plugins/queuesort:go_default_library",
2728
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
2829
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
2930
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
@@ -52,6 +53,7 @@ go_test(
5253
"//pkg/scheduler/framework/plugins/nodeunschedulable:go_default_library",
5354
"//pkg/scheduler/framework/plugins/nodevolumelimits:go_default_library",
5455
"//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library",
56+
"//pkg/scheduler/framework/plugins/queuesort:go_default_library",
5557
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
5658
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
5759
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",

pkg/scheduler/algorithmprovider/registry.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable"
3838
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits"
3939
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread"
40+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
4041
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
4142
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
4243
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
@@ -83,6 +84,11 @@ func ListAlgorithmProviders() string {
8384
func getDefaultConfig(hardPodAffinityWeight int64) *Config {
8485
return &Config{
8586
FrameworkPlugins: &schedulerapi.Plugins{
87+
QueueSort: &schedulerapi.PluginSet{
88+
Enabled: []schedulerapi.Plugin{
89+
{Name: queuesort.Name},
90+
},
91+
},
8692
PreFilter: &schedulerapi.PluginSet{
8793
Enabled: []schedulerapi.Plugin{
8894
{Name: noderesources.FitName},

pkg/scheduler/algorithmprovider/registry_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/google/go-cmp/cmp"
24+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
2425

2526
"k8s.io/apimachinery/pkg/runtime"
2627
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -48,6 +49,11 @@ func TestClusterAutoscalerProvider(t *testing.T) {
4849
hardPodAffinityWeight := int64(1)
4950
wantConfig := &Config{
5051
FrameworkPlugins: &schedulerapi.Plugins{
52+
QueueSort: &schedulerapi.PluginSet{
53+
Enabled: []schedulerapi.Plugin{
54+
{Name: queuesort.Name},
55+
},
56+
},
5157
PreFilter: &schedulerapi.PluginSet{
5258
Enabled: []schedulerapi.Plugin{
5359
{Name: noderesources.FitName},
@@ -120,6 +126,11 @@ func TestApplyFeatureGates(t *testing.T) {
120126
featuresEnabled: false,
121127
wantConfig: &Config{
122128
FrameworkPlugins: &schedulerapi.Plugins{
129+
QueueSort: &schedulerapi.PluginSet{
130+
Enabled: []schedulerapi.Plugin{
131+
{Name: queuesort.Name},
132+
},
133+
},
123134
PreFilter: &schedulerapi.PluginSet{
124135
Enabled: []schedulerapi.Plugin{
125136
{Name: noderesources.FitName},
@@ -178,6 +189,11 @@ func TestApplyFeatureGates(t *testing.T) {
178189
featuresEnabled: true,
179190
wantConfig: &Config{
180191
FrameworkPlugins: &schedulerapi.Plugins{
192+
QueueSort: &schedulerapi.PluginSet{
193+
Enabled: []schedulerapi.Plugin{
194+
{Name: queuesort.Name},
195+
},
196+
},
181197
PreFilter: &schedulerapi.PluginSet{
182198
Enabled: []schedulerapi.Plugin{
183199
{Name: noderesources.FitName},

pkg/scheduler/apis/config/testing/compatibility_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
6161
]
6262
}`,
6363
wantPlugins: map[string][]config.Plugin{
64+
"QueueSortPlugin": {{Name: "PrioritySort"}},
6465
"PreFilterPlugin": {
6566
{Name: "NodeResourcesFit"},
6667
{Name: "NodePorts"},
@@ -87,6 +88,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
8788
]
8889
}`,
8990
wantPlugins: map[string][]config.Plugin{
91+
"QueueSortPlugin": {{Name: "PrioritySort"}},
9092
"FilterPlugin": {
9193
{Name: "NodeUnschedulable"},
9294
{Name: "TaintToleration"},
@@ -115,6 +117,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
115117
]
116118
}`,
117119
wantPlugins: map[string][]config.Plugin{
120+
"QueueSortPlugin": {{Name: "PrioritySort"}},
118121
"PreFilterPlugin": {
119122
{Name: "NodePorts"},
120123
{Name: "NodeResourcesFit"},
@@ -167,6 +170,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
167170
]
168171
}`,
169172
wantPlugins: map[string][]config.Plugin{
173+
"QueueSortPlugin": {{Name: "PrioritySort"}},
170174
"PreFilterPlugin": {
171175
{Name: "NodePorts"},
172176
{Name: "NodeResourcesFit"},
@@ -224,6 +228,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
224228
]
225229
}`,
226230
wantPlugins: map[string][]config.Plugin{
231+
"QueueSortPlugin": {{Name: "PrioritySort"}},
227232
"PreFilterPlugin": {
228233
{Name: "NodePorts"},
229234
{Name: "NodeResourcesFit"},
@@ -290,6 +295,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
290295
]
291296
}`,
292297
wantPlugins: map[string][]config.Plugin{
298+
"QueueSortPlugin": {{Name: "PrioritySort"}},
293299
"PreFilterPlugin": {
294300
{Name: "NodePorts"},
295301
{Name: "NodeResourcesFit"},
@@ -364,6 +370,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
364370
]
365371
}`,
366372
wantPlugins: map[string][]config.Plugin{
373+
"QueueSortPlugin": {{Name: "PrioritySort"}},
367374
"PreFilterPlugin": {
368375
{Name: "NodePorts"},
369376
{Name: "NodeResourcesFit"},
@@ -449,6 +456,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
449456
}]
450457
}`,
451458
wantPlugins: map[string][]config.Plugin{
459+
"QueueSortPlugin": {{Name: "PrioritySort"}},
452460
"PreFilterPlugin": {
453461
{Name: "NodePorts"},
454462
{Name: "NodeResourcesFit"},
@@ -545,6 +553,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
545553
}]
546554
}`,
547555
wantPlugins: map[string][]config.Plugin{
556+
"QueueSortPlugin": {{Name: "PrioritySort"}},
548557
"PreFilterPlugin": {
549558
{Name: "NodePorts"},
550559
{Name: "NodeResourcesFit"},
@@ -642,6 +651,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
642651
}]
643652
}`,
644653
wantPlugins: map[string][]config.Plugin{
654+
"QueueSortPlugin": {{Name: "PrioritySort"}},
645655
"PreFilterPlugin": {
646656
{Name: "NodePorts"},
647657
{Name: "NodeResourcesFit"},
@@ -743,6 +753,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
743753
}]
744754
}`,
745755
wantPlugins: map[string][]config.Plugin{
756+
"QueueSortPlugin": {{Name: "PrioritySort"}},
746757
"PreFilterPlugin": {
747758
{Name: "NodePorts"},
748759
{Name: "NodeResourcesFit"},
@@ -856,6 +867,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
856867
}]
857868
}`,
858869
wantPlugins: map[string][]config.Plugin{
870+
"QueueSortPlugin": {{Name: "PrioritySort"}},
859871
"PreFilterPlugin": {
860872
{Name: "NodePorts"},
861873
{Name: "NodeResourcesFit"},
@@ -971,6 +983,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
971983
}]
972984
}`,
973985
wantPlugins: map[string][]config.Plugin{
986+
"QueueSortPlugin": {{Name: "PrioritySort"}},
974987
"PreFilterPlugin": {
975988
{Name: "NodePorts"},
976989
{Name: "NodeResourcesFit"},
@@ -1086,6 +1099,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10861099
}]
10871100
}`,
10881101
wantPlugins: map[string][]config.Plugin{
1102+
"QueueSortPlugin": {{Name: "PrioritySort"}},
10891103
"PreFilterPlugin": {
10901104
{Name: "NodePorts"},
10911105
{Name: "NodeResourcesFit"},
@@ -1206,6 +1220,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12061220
}]
12071221
}`,
12081222
wantPlugins: map[string][]config.Plugin{
1223+
"QueueSortPlugin": {{Name: "PrioritySort"}},
12091224
"PreFilterPlugin": {
12101225
{Name: "NodePorts"},
12111226
{Name: "NodeResourcesFit"},
@@ -1279,6 +1294,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12791294
features.EvenPodsSpread: true,
12801295
},
12811296
wantPlugins: map[string][]config.Plugin{
1297+
"QueueSortPlugin": {{Name: "PrioritySort"}},
12821298
"PreFilterPlugin": {
12831299
{Name: "PodTopologySpread"},
12841300
},
@@ -1309,6 +1325,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
13091325
features.ResourceLimitsPriorityFunction: true,
13101326
},
13111327
wantPlugins: map[string][]config.Plugin{
1328+
"QueueSortPlugin": {{Name: "PrioritySort"}},
13121329
"PostFilterPlugin": {
13131330
{Name: "NodeResourceLimits"},
13141331
},
@@ -1382,6 +1399,9 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
13821399
func TestAlgorithmProviderCompatibility(t *testing.T) {
13831400
// Add serialized versions of scheduler config that exercise available options to ensure compatibility between releases
13841401
defaultPlugins := map[string][]config.Plugin{
1402+
"QueueSortPlugin": {
1403+
{Name: "PrioritySort"},
1404+
},
13851405
"PreFilterPlugin": {
13861406
{Name: "NodeResourcesFit"},
13871407
{Name: "NodePorts"},
@@ -1438,6 +1458,9 @@ func TestAlgorithmProviderCompatibility(t *testing.T) {
14381458
name: "ClusterAutoscalerProvider",
14391459
provider: algorithmprovider.ClusterAutoscalerProvider,
14401460
wantPlugins: map[string][]config.Plugin{
1461+
"QueueSortPlugin": {
1462+
{Name: "PrioritySort"},
1463+
},
14411464
"PreFilterPlugin": {
14421465
{Name: "NodeResourcesFit"},
14431466
{Name: "NodePorts"},

pkg/scheduler/core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ go_test(
5757
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
5858
"//pkg/scheduler/framework/plugins/nodeunschedulable:go_default_library",
5959
"//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library",
60+
"//pkg/scheduler/framework/plugins/queuesort:go_default_library",
6061
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
6162
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
6263
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",

pkg/scheduler/core/extender_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/kubernetes/pkg/scheduler/algorithm"
3737
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
3838
extenderv1 "k8s.io/kubernetes/pkg/scheduler/apis/extender/v1"
39+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
3940
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
4041
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
4142
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
@@ -366,6 +367,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
366367
{
367368
registerPlugins: []st.RegisterPluginFunc{
368369
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
370+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
369371
},
370372
extenders: []FakeExtender{
371373
{
@@ -382,6 +384,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
382384
{
383385
registerPlugins: []st.RegisterPluginFunc{
384386
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
387+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
385388
},
386389
extenders: []FakeExtender{
387390
{
@@ -398,6 +401,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
398401
{
399402
registerPlugins: []st.RegisterPluginFunc{
400403
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
404+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
401405
},
402406
extenders: []FakeExtender{
403407
{
@@ -418,6 +422,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
418422
{
419423
registerPlugins: []st.RegisterPluginFunc{
420424
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
425+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
421426
},
422427
extenders: []FakeExtender{
423428
{
@@ -434,6 +439,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
434439
{
435440
registerPlugins: []st.RegisterPluginFunc{
436441
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
442+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
437443
},
438444
extenders: []FakeExtender{
439445
{
@@ -453,6 +459,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
453459
{
454460
registerPlugins: []st.RegisterPluginFunc{
455461
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
462+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
456463
},
457464
extenders: []FakeExtender{
458465
{
@@ -478,6 +485,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
478485
registerPlugins: []st.RegisterPluginFunc{
479486
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
480487
st.RegisterScorePlugin("Machine2Prioritizer", newMachine2PrioritizerPlugin(), 20),
488+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
481489
},
482490
extenders: []FakeExtender{
483491
{
@@ -505,6 +513,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
505513
registerPlugins: []st.RegisterPluginFunc{
506514
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
507515
st.RegisterScorePlugin("Machine2Prioritizer", newMachine2PrioritizerPlugin(), 1),
516+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
508517
},
509518
extenders: []FakeExtender{
510519
{
@@ -530,6 +539,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
530539
// because of the errors from errorPredicateExtender.
531540
registerPlugins: []st.RegisterPluginFunc{
532541
st.RegisterFilterPlugin("TrueFilter", NewTrueFilterPlugin),
542+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
533543
},
534544
extenders: []FakeExtender{
535545
{
@@ -568,8 +578,9 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
568578

569579
registry := framework.Registry{}
570580
plugins := &schedulerapi.Plugins{
571-
Filter: &schedulerapi.PluginSet{},
572-
Score: &schedulerapi.PluginSet{},
581+
QueueSort: &schedulerapi.PluginSet{},
582+
Filter: &schedulerapi.PluginSet{},
583+
Score: &schedulerapi.PluginSet{},
573584
}
574585
var pluginConfigs []schedulerapi.PluginConfig
575586
for _, f := range test.registerPlugins {

0 commit comments

Comments
 (0)