Fix a bug that DefaultPreemption plugin is disabled when using scheduler policy

This commit is contained in:
Wei Huang 2020-11-10 17:46:37 -08:00
parent f102cc887e
commit 47a7c374c6
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005
6 changed files with 38 additions and 11 deletions

View File

@ -348,6 +348,7 @@ profiles:
{Name: "TaintToleration"}, {Name: "TaintToleration"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },

View File

@ -20,6 +20,7 @@ go_library(
"//pkg/scheduler/framework:go_default_library", "//pkg/scheduler/framework:go_default_library",
"//pkg/scheduler/framework/plugins:go_default_library", "//pkg/scheduler/framework/plugins:go_default_library",
"//pkg/scheduler/framework/plugins/defaultbinder: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/noderesources:go_default_library",
"//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/runtime:go_default_library",

View File

@ -75,7 +75,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeAffinity"}, {Name: "NodeAffinity"},
{Name: "TaintToleration"}, {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. // 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: "NodeUnschedulable"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
"BindPlugin": {{Name: "DefaultBinder"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"BindPlugin": {{Name: "DefaultBinder"}},
}, },
}, },
// Do not change this JSON after the corresponding release has been tagged. // 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: "NodeLabel"},
{Name: "ServiceAffinity"}, {Name: "ServiceAffinity"},
}, },
"PreScorePlugin": {{Name: "PodTopologySpread"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": {{Name: "PodTopologySpread"}},
"ScorePlugin": { "ScorePlugin": {
{Name: "NodeResourcesLeastAllocated", Weight: 1}, {Name: "NodeResourcesLeastAllocated", Weight: 1},
{Name: "NodeLabel", Weight: 4}, {Name: "NodeLabel", Weight: 4},
@ -191,7 +194,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeLabel"}, {Name: "NodeLabel"},
{Name: "ServiceAffinity"}, {Name: "ServiceAffinity"},
}, },
"PreScorePlugin": {{Name: "PodTopologySpread"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": {{Name: "PodTopologySpread"}},
"ScorePlugin": { "ScorePlugin": {
{Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "NodeResourcesBalancedAllocation", Weight: 2},
{Name: "NodeResourcesLeastAllocated", Weight: 2}, {Name: "NodeResourcesLeastAllocated", Weight: 2},
@ -254,7 +258,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "AzureDiskLimits"}, {Name: "AzureDiskLimits"},
{Name: "VolumeZone"}, {Name: "VolumeZone"},
}, },
"PreScorePlugin": {{Name: "PodTopologySpread"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": {{Name: "PodTopologySpread"}},
"ScorePlugin": { "ScorePlugin": {
{Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "NodeResourcesBalancedAllocation", Weight: 2},
{Name: "ImageLocality", Weight: 2}, {Name: "ImageLocality", Weight: 2},
@ -324,6 +329,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -400,6 +406,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -487,6 +494,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -585,6 +593,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -686,6 +695,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -792,6 +802,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -910,6 +921,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -1031,6 +1043,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -1152,6 +1165,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -1277,6 +1291,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeZone"}, {Name: "VolumeZone"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},

View File

@ -39,6 +39,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework" "k8s.io/kubernetes/pkg/scheduler/framework"
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins" frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "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/noderesources"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" 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 // Combine all framework configurations. If this results in any duplication, framework
// instantiation should fail. // 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. // before. We add them by default.
plugins := schedulerapi.Plugins{ plugins := schedulerapi.Plugins{
QueueSort: &schedulerapi.PluginSet{ QueueSort: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{{Name: queuesort.Name}}, Enabled: []schedulerapi.Plugin{{Name: queuesort.Name}},
}, },
PostFilter: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{{Name: defaultpreemption.Name}},
},
Bind: &schedulerapi.PluginSet{ Bind: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{{Name: defaultbinder.Name}}, Enabled: []schedulerapi.Plugin{{Name: defaultbinder.Name}},
}, },

View File

@ -140,7 +140,7 @@ func TestCreateFromConfig(t *testing.T) {
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
}, },
PostFilter: &schedulerapi.PluginSet{}, PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}},
PreScore: &schedulerapi.PluginSet{ PreScore: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{ Enabled: []schedulerapi.Plugin{
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
@ -238,7 +238,7 @@ func TestCreateFromConfig(t *testing.T) {
{Name: "ServiceAffinity"}, {Name: "ServiceAffinity"},
}, },
}, },
PostFilter: &schedulerapi.PluginSet{}, PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}},
PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}}, PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}},
Score: &schedulerapi.PluginSet{ Score: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{ Enabled: []schedulerapi.Plugin{
@ -313,7 +313,7 @@ func TestCreateFromConfig(t *testing.T) {
{Name: "ServiceAffinity"}, {Name: "ServiceAffinity"},
}, },
}, },
PostFilter: &schedulerapi.PluginSet{}, PostFilter: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultPreemption"}}},
PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}}, PreScore: &schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "InterPodAffinity"}}},
Score: &schedulerapi.PluginSet{ Score: &schedulerapi.PluginSet{
Enabled: []schedulerapi.Plugin{ Enabled: []schedulerapi.Plugin{

View File

@ -90,6 +90,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
{Name: "NodeResourcesFit"}, {Name: "NodeResourcesFit"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"ScorePlugin": { "ScorePlugin": {
{Name: "ImageLocality", Weight: 1}, {Name: "ImageLocality", Weight: 1},
}, },
@ -127,6 +128,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
@ -160,7 +162,8 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
"BindPlugin": {{Name: "DefaultBinder"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"BindPlugin": {{Name: "DefaultBinder"}},
}, },
}, },
{ {
@ -182,6 +185,7 @@ priorities:
{Name: "NodeResourcesFit"}, {Name: "NodeResourcesFit"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"ScorePlugin": { "ScorePlugin": {
{Name: "ImageLocality", Weight: 1}, {Name: "ImageLocality", Weight: 1},
}, },
@ -218,6 +222,7 @@ kind: Policy
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
}, },
"PostFilterPlugin": {{Name: "DefaultPreemption"}},
"PreScorePlugin": { "PreScorePlugin": {
{Name: "PodTopologySpread"}, {Name: "PodTopologySpread"},
{Name: "InterPodAffinity"}, {Name: "InterPodAffinity"},
@ -250,7 +255,8 @@ priorities: []
{Name: "NodeUnschedulable"}, {Name: "NodeUnschedulable"},
{Name: "TaintToleration"}, {Name: "TaintToleration"},
}, },
"BindPlugin": {{Name: "DefaultBinder"}}, "PostFilterPlugin": {{Name: "DefaultPreemption"}},
"BindPlugin": {{Name: "DefaultBinder"}},
}, },
}, },
} { } {