From 47a7c374c6de36c9ebc91a0de6a895f45748c7f9 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Tue, 10 Nov 2020 17:46:37 -0800 Subject: [PATCH] Fix a bug that DefaultPreemption plugin is disabled when using scheduler policy --- cmd/kube-scheduler/app/server_test.go | 1 + pkg/scheduler/BUILD | 1 + .../apis/config/testing/compatibility_test.go | 25 +++++++++++++++---- pkg/scheduler/factory.go | 6 ++++- pkg/scheduler/factory_test.go | 6 ++--- test/integration/scheduler/scheduler_test.go | 10 ++++++-- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/cmd/kube-scheduler/app/server_test.go b/cmd/kube-scheduler/app/server_test.go index 4b5c60acd03..909bdb5ab9f 100644 --- a/cmd/kube-scheduler/app/server_test.go +++ b/cmd/kube-scheduler/app/server_test.go @@ -348,6 +348,7 @@ profiles: {Name: "TaintToleration"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, }, diff --git a/pkg/scheduler/BUILD b/pkg/scheduler/BUILD index d12fc963747..1f2f0d2f1f3 100644 --- a/pkg/scheduler/BUILD +++ b/pkg/scheduler/BUILD @@ -20,6 +20,7 @@ go_library( "//pkg/scheduler/framework:go_default_library", "//pkg/scheduler/framework/plugins:go_default_library", "//pkg/scheduler/framework/plugins/defaultbinder:go_default_library", + "//pkg/scheduler/framework/plugins/defaultpreemption:go_default_library", "//pkg/scheduler/framework/plugins/noderesources:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/runtime:go_default_library", diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index ef456785e03..85c4831f9da 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -75,7 +75,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeAffinity"}, {Name: "TaintToleration"}, }, - "BindPlugin": {{Name: "DefaultBinder"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "BindPlugin": {{Name: "DefaultBinder"}}, }, }, // This is a special test for the case where a policy is specified without specifying any filters. @@ -95,7 +96,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeUnschedulable"}, {Name: "TaintToleration"}, }, - "BindPlugin": {{Name: "DefaultBinder"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "BindPlugin": {{Name: "DefaultBinder"}}, }, }, // Do not change this JSON after the corresponding release has been tagged. @@ -136,7 +138,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeLabel"}, {Name: "ServiceAffinity"}, }, - "PreScorePlugin": {{Name: "PodTopologySpread"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesLeastAllocated", Weight: 1}, {Name: "NodeLabel", Weight: 4}, @@ -191,7 +194,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeLabel"}, {Name: "ServiceAffinity"}, }, - "PreScorePlugin": {{Name: "PodTopologySpread"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "NodeResourcesLeastAllocated", Weight: 2}, @@ -254,7 +258,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "AzureDiskLimits"}, {Name: "VolumeZone"}, }, - "PreScorePlugin": {{Name: "PodTopologySpread"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "ImageLocality", Weight: 2}, @@ -324,6 +329,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -400,6 +406,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -487,6 +494,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -585,6 +593,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -686,6 +695,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -792,6 +802,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -910,6 +921,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -1031,6 +1043,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -1152,6 +1165,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, @@ -1277,6 +1291,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "VolumeZone"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 90e52bf5a94..997ce81d794 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -39,6 +39,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework" frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" @@ -262,12 +263,15 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, // Combine all framework configurations. If this results in any duplication, framework // instantiation should fail. - // "PrioritySort" and "DefaultBinder" were neither predicates nor priorities + // "PrioritySort", "DefaultPreemption" and "DefaultBinder" were neither predicates nor priorities // before. We add them by default. plugins := schedulerapi.Plugins{ QueueSort: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{{Name: queuesort.Name}}, }, + PostFilter: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{{Name: defaultpreemption.Name}}, + }, Bind: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{{Name: defaultbinder.Name}}, }, diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index c8debd81e91..8a469120623 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -140,7 +140,7 @@ func TestCreateFromConfig(t *testing.T) { {Name: "InterPodAffinity"}, }, }, - PostFilter: &schedulerapi.PluginSet{}, + PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}}, PreScore: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{ {Name: "PodTopologySpread"}, @@ -238,7 +238,7 @@ func TestCreateFromConfig(t *testing.T) { {Name: "ServiceAffinity"}, }, }, - PostFilter: &schedulerapi.PluginSet{}, + PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}}, PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}}, Score: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{ @@ -313,7 +313,7 @@ func TestCreateFromConfig(t *testing.T) { {Name: "ServiceAffinity"}, }, }, - PostFilter: &schedulerapi.PluginSet{}, + PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}}, PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}}, Score: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{ diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 5d10ef3c51d..63153b0992e 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -90,6 +90,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { {Name: "NodeResourcesFit"}, {Name: "TaintToleration"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "ScorePlugin": { {Name: "ImageLocality", Weight: 1}, }, @@ -127,6 +128,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, @@ -160,7 +162,8 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { {Name: "NodeUnschedulable"}, {Name: "TaintToleration"}, }, - "BindPlugin": {{Name: "DefaultBinder"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "BindPlugin": {{Name: "DefaultBinder"}}, }, }, { @@ -182,6 +185,7 @@ priorities: {Name: "NodeResourcesFit"}, {Name: "TaintToleration"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "ScorePlugin": { {Name: "ImageLocality", Weight: 1}, }, @@ -218,6 +222,7 @@ kind: Policy {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, }, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, "PreScorePlugin": { {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, @@ -250,7 +255,8 @@ priorities: [] {Name: "NodeUnschedulable"}, {Name: "TaintToleration"}, }, - "BindPlugin": {{Name: "DefaultBinder"}}, + "PostFilterPlugin": {{Name: "DefaultPreemption"}}, + "BindPlugin": {{Name: "DefaultBinder"}}, }, }, } {