From 87c8349bdc24cd0f984b025c18605483e7e0c57c Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Thu, 15 Oct 2020 20:29:42 -0400 Subject: [PATCH] Graduate DefaultPodTopologySpread to beta And set to enabled by default Change-Id: Ie4cc4758c52492924cb0663450f2747908cb5882 --- cmd/kube-scheduler/app/server_test.go | 4 - pkg/features/kube_features.go | 4 +- pkg/scheduler/BUILD | 1 + .../algorithmprovider/registry_test.go | 171 +++++++++--------- pkg/scheduler/apis/config/scheme/BUILD | 3 - .../apis/config/scheme/scheme_test.go | 9 +- .../apis/config/testing/compatibility_test.go | 58 +++--- .../apis/config/v1beta1/defaults_test.go | 45 ++--- pkg/scheduler/factory_test.go | 8 +- .../default_preemption_test.go | 2 + .../framework/plugins/legacy_registry_test.go | 30 ++- .../framework/runtime/framework_test.go | 4 +- test/integration/scheduler/scheduler_test.go | 4 - 13 files changed, 150 insertions(+), 193 deletions(-) diff --git a/cmd/kube-scheduler/app/server_test.go b/cmd/kube-scheduler/app/server_test.go index f4296805499..4b5c60acd03 100644 --- a/cmd/kube-scheduler/app/server_test.go +++ b/cmd/kube-scheduler/app/server_test.go @@ -186,7 +186,6 @@ profiles: {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, - {Name: "SelectorSpread"}, }, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 1}, @@ -197,7 +196,6 @@ profiles: {Name: "NodePreferAvoidPods", Weight: 10000}, {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 1}, - {Name: "SelectorSpread", Weight: 1}, }, "BindPlugin": {{Name: "DefaultBinder"}}, "ReservePlugin": {{Name: "VolumeBinding"}}, @@ -316,7 +314,6 @@ profiles: {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, - {Name: "SelectorSpread"}, }, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 1}, @@ -327,7 +324,6 @@ profiles: {Name: "NodePreferAvoidPods", Weight: 10000}, {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 1}, - {Name: "SelectorSpread", Weight: 1}, }, "BindPlugin": {{Name: "DefaultBinder"}}, "ReservePlugin": {{Name: "VolumeBinding"}}, diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 5a79a7fa99f..62c010b2f7f 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -296,7 +296,7 @@ const ( CSIStorageCapacity featuregate.Feature = "CSIStorageCapacity" // owner: @alculquicondor - // alpha: v1.19 + // beta: v1.20 // // Enables the use of PodTopologySpread scheduling plugin to do default // spreading and disables legacy SelectorSpread plugin. @@ -733,7 +733,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS HugePageStorageMediumSize: {Default: true, PreRelease: featuregate.Beta}, ExternalPolicyForExternalIP: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.22 AnyVolumeDataSource: {Default: false, PreRelease: featuregate.Alpha}, - DefaultPodTopologySpread: {Default: false, PreRelease: featuregate.Alpha}, + DefaultPodTopologySpread: {Default: true, PreRelease: featuregate.Beta}, SetHostnameAsFQDN: {Default: true, PreRelease: featuregate.Beta}, WinOverlay: {Default: true, PreRelease: featuregate.Beta}, WinDSR: {Default: false, PreRelease: featuregate.Alpha}, diff --git a/pkg/scheduler/BUILD b/pkg/scheduler/BUILD index 81468356a43..4c8d0bf5079 100644 --- a/pkg/scheduler/BUILD +++ b/pkg/scheduler/BUILD @@ -69,6 +69,7 @@ go_test( "//pkg/scheduler/framework/plugins/nodelabel:go_default_library", "//pkg/scheduler/framework/plugins/nodeports:go_default_library", "//pkg/scheduler/framework/plugins/noderesources:go_default_library", + "//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library", "//pkg/scheduler/framework/plugins/volumebinding:go_default_library", diff --git a/pkg/scheduler/algorithmprovider/registry_test.go b/pkg/scheduler/algorithmprovider/registry_test.go index 52039e7f086..12eee457a94 100644 --- a/pkg/scheduler/algorithmprovider/registry_test.go +++ b/pkg/scheduler/algorithmprovider/registry_test.go @@ -20,14 +20,13 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "k8s.io/apiserver/pkg/util/feature" "k8s.io/component-base/featuregate" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption" - - utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kubernetes/pkg/features" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/imagelocality" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity" @@ -91,7 +90,6 @@ func TestClusterAutoscalerProvider(t *testing.T) { {Name: interpodaffinity.Name}, {Name: podtopologyspread.Name}, {Name: tainttoleration.Name}, - {Name: selectorspread.Name}, }, }, Score: &schedulerapi.PluginSet{ @@ -104,7 +102,6 @@ func TestClusterAutoscalerProvider(t *testing.T) { {Name: nodepreferavoidpods.Name, Weight: 10000}, {Name: podtopologyspread.Name, Weight: 2}, {Name: tainttoleration.Name, Weight: 1}, - {Name: selectorspread.Name, Weight: 1}, }, }, Reserve: &schedulerapi.PluginSet{ @@ -134,11 +131,91 @@ func TestClusterAutoscalerProvider(t *testing.T) { func TestApplyFeatureGates(t *testing.T) { tests := []struct { name string - feature featuregate.Feature + features map[featuregate.Feature]bool wantConfig *schedulerapi.Plugins }{ { name: "Feature gates disabled", + wantConfig: &schedulerapi.Plugins{ + QueueSort: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: queuesort.Name}, + }, + }, + PreFilter: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: noderesources.FitName}, + {Name: nodeports.Name}, + {Name: podtopologyspread.Name}, + {Name: interpodaffinity.Name}, + {Name: volumebinding.Name}, + }, + }, + Filter: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: nodeunschedulable.Name}, + {Name: nodename.Name}, + {Name: tainttoleration.Name}, + {Name: nodeaffinity.Name}, + {Name: nodeports.Name}, + {Name: noderesources.FitName}, + {Name: volumerestrictions.Name}, + {Name: nodevolumelimits.EBSName}, + {Name: nodevolumelimits.GCEPDName}, + {Name: nodevolumelimits.CSIName}, + {Name: nodevolumelimits.AzureDiskName}, + {Name: volumebinding.Name}, + {Name: volumezone.Name}, + {Name: podtopologyspread.Name}, + {Name: interpodaffinity.Name}, + }, + }, + PostFilter: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: defaultpreemption.Name}, + }, + }, + PreScore: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: interpodaffinity.Name}, + {Name: podtopologyspread.Name}, + {Name: tainttoleration.Name}, + }, + }, + Score: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: noderesources.BalancedAllocationName, Weight: 1}, + {Name: imagelocality.Name, Weight: 1}, + {Name: interpodaffinity.Name, Weight: 1}, + {Name: noderesources.LeastAllocatedName, Weight: 1}, + {Name: nodeaffinity.Name, Weight: 1}, + {Name: nodepreferavoidpods.Name, Weight: 10000}, + {Name: podtopologyspread.Name, Weight: 2}, + {Name: tainttoleration.Name, Weight: 1}, + }, + }, + Reserve: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: volumebinding.Name}, + }, + }, + PreBind: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: volumebinding.Name}, + }, + }, + Bind: &schedulerapi.PluginSet{ + Enabled: []schedulerapi.Plugin{ + {Name: defaultbinder.Name}, + }, + }, + }, + }, + { + name: "DefaultPodTopologySpread disabled", + features: map[featuregate.Feature]bool{ + features.DefaultPodTopologySpread: false, + }, wantConfig: &schedulerapi.Plugins{ QueueSort: &schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{ @@ -216,90 +293,12 @@ func TestApplyFeatureGates(t *testing.T) { }, }, }, - { - name: "NewDefaultPodTopologySpread enabled", - feature: features.DefaultPodTopologySpread, - wantConfig: &schedulerapi.Plugins{ - QueueSort: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: queuesort.Name}, - }, - }, - PreFilter: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: noderesources.FitName}, - {Name: nodeports.Name}, - {Name: podtopologyspread.Name}, - {Name: interpodaffinity.Name}, - {Name: volumebinding.Name}, - }, - }, - Filter: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: nodeunschedulable.Name}, - {Name: nodename.Name}, - {Name: tainttoleration.Name}, - {Name: nodeaffinity.Name}, - {Name: nodeports.Name}, - {Name: noderesources.FitName}, - {Name: volumerestrictions.Name}, - {Name: nodevolumelimits.EBSName}, - {Name: nodevolumelimits.GCEPDName}, - {Name: nodevolumelimits.CSIName}, - {Name: nodevolumelimits.AzureDiskName}, - {Name: volumebinding.Name}, - {Name: volumezone.Name}, - {Name: podtopologyspread.Name}, - {Name: interpodaffinity.Name}, - }, - }, - PostFilter: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: defaultpreemption.Name}, - }, - }, - PreScore: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: interpodaffinity.Name}, - {Name: podtopologyspread.Name}, - {Name: tainttoleration.Name}, - }, - }, - Score: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: noderesources.BalancedAllocationName, Weight: 1}, - {Name: imagelocality.Name, Weight: 1}, - {Name: interpodaffinity.Name, Weight: 1}, - {Name: noderesources.LeastAllocatedName, Weight: 1}, - {Name: nodeaffinity.Name, Weight: 1}, - {Name: nodepreferavoidpods.Name, Weight: 10000}, - {Name: podtopologyspread.Name, Weight: 2}, - {Name: tainttoleration.Name, Weight: 1}, - }, - }, - Reserve: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: volumebinding.Name}, - }, - }, - PreBind: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: volumebinding.Name}, - }, - }, - Bind: &schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: defaultbinder.Name}, - }, - }, - }, - }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - if test.feature != "" { - defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, test.feature, true)() + for k, v := range test.features { + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)() } r := NewRegistry() diff --git a/pkg/scheduler/apis/config/scheme/BUILD b/pkg/scheduler/apis/config/scheme/BUILD index 1c7c14eb4e4..7331f914ffb 100644 --- a/pkg/scheduler/apis/config/scheme/BUILD +++ b/pkg/scheduler/apis/config/scheme/BUILD @@ -38,9 +38,6 @@ go_test( "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", - "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", - "//staging/src/k8s.io/component-base/featuregate:go_default_library", - "//staging/src/k8s.io/component-base/featuregate/testing:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1beta1:go_default_library", "//vendor/github.com/google/go-cmp/cmp:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", diff --git a/pkg/scheduler/apis/config/scheme/scheme_test.go b/pkg/scheduler/apis/config/scheme/scheme_test.go index a494de5f85c..1a0a2c037af 100644 --- a/pkg/scheduler/apis/config/scheme/scheme_test.go +++ b/pkg/scheduler/apis/config/scheme/scheme_test.go @@ -24,9 +24,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apiserver/pkg/util/feature" - "k8s.io/component-base/featuregate" - featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kube-scheduler/config/v1beta1" "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/utils/pointer" @@ -39,7 +36,6 @@ func TestCodecsDecodePluginConfig(t *testing.T) { testCases := []struct { name string data []byte - feature featuregate.Feature wantErr string wantProfiles []config.KubeSchedulerProfile }{ @@ -302,7 +298,7 @@ profiles: { Name: "PodTopologySpread", Args: &config.PodTopologySpreadArgs{ - DefaultingType: config.ListDefaulting, + DefaultingType: config.SystemDefaulting, }, }, }, @@ -313,9 +309,6 @@ profiles: decoder := Codecs.UniversalDecoder() for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - if tt.feature != "" { - defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, tt.feature, true)() - } obj, gvk, err := decoder.Decode(tt.data, nil, nil) if err != nil { if tt.wantErr != err.Error() { diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index 87992d152b4..6f3185728b7 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -136,11 +136,11 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeLabel"}, {Name: "ServiceAffinity"}, }, - "PreScorePlugin": {{Name: "SelectorSpread"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesLeastAllocated", Weight: 1}, {Name: "NodeLabel", Weight: 4}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "ServiceAffinity", Weight: 3}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -191,12 +191,12 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeLabel"}, {Name: "ServiceAffinity"}, }, - "PreScorePlugin": {{Name: "SelectorSpread"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "NodeResourcesLeastAllocated", Weight: 2}, {Name: "NodeLabel", Weight: 8}, // Weight is 4 * number of LabelPreference priorities - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "ServiceAffinity", Weight: 6}, // Weight is the 3 * number of custom ServiceAntiAffinity priorities }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -254,14 +254,14 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "AzureDiskLimits"}, {Name: "VolumeZone"}, }, - "PreScorePlugin": {{Name: "SelectorSpread"}}, + "PreScorePlugin": {{Name: "PodTopologySpread"}}, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 2}, {Name: "ImageLocality", Weight: 2}, {Name: "NodeResourcesLeastAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodeLabel", Weight: 4}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "ServiceAffinity", Weight: 3}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -326,7 +326,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -335,7 +335,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "InterPodAffinity", Weight: 2}, {Name: "NodeResourcesLeastAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -402,7 +402,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -413,7 +413,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeResourcesMostAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -489,7 +489,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -500,7 +500,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeResourcesMostAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -587,7 +587,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -598,7 +598,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeResourcesMostAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -688,7 +688,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -699,7 +699,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeResourcesMostAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -794,7 +794,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -805,7 +805,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeResourcesMostAllocated", Weight: 2}, {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -912,7 +912,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -924,7 +924,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, {Name: "RequestedToCapacityRatio", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -1033,7 +1033,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -1045,7 +1045,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, {Name: "RequestedToCapacityRatio", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -1154,7 +1154,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -1166,7 +1166,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, {Name: "RequestedToCapacityRatio", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -1279,7 +1279,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, "PreScorePlugin": { {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, + {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -1291,7 +1291,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { {Name: "NodeAffinity", Weight: 2}, {Name: "NodePreferAvoidPods", Weight: 2}, {Name: "RequestedToCapacityRatio", Weight: 2}, - {Name: "SelectorSpread", Weight: 2}, + {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 2}, }, "BindPlugin": {{Name: "DefaultBinder"}}, @@ -1408,7 +1408,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, - {Name: "SelectorSpread"}, }, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 1}, @@ -1419,7 +1418,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) { {Name: "NodePreferAvoidPods", Weight: 10000}, {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 1}, - {Name: "SelectorSpread", Weight: 1}, }, "BindPlugin": {{Name: "DefaultBinder"}}, "ReservePlugin": {{Name: "VolumeBinding"}}, @@ -1478,7 +1476,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, - {Name: "SelectorSpread"}, }, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 1}, @@ -1489,7 +1486,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) { {Name: "NodePreferAvoidPods", Weight: 10000}, {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 1}, - {Name: "SelectorSpread", Weight: 1}, }, "ReservePlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}}, @@ -1567,7 +1563,6 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { {Name: "InterPodAffinity"}, {Name: "PodTopologySpread"}, {Name: "TaintToleration"}, - {Name: "SelectorSpread"}, }, "ScorePlugin": { {Name: "NodeResourcesBalancedAllocation", Weight: 1}, @@ -1578,7 +1573,6 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { {Name: "NodePreferAvoidPods", Weight: 10000}, {Name: "PodTopologySpread", Weight: 2}, {Name: "TaintToleration", Weight: 1}, - {Name: "SelectorSpread", Weight: 1}, }, "ReservePlugin": {{Name: "VolumeBinding"}}, "PreBindPlugin": {{Name: "VolumeBinding"}}, diff --git a/pkg/scheduler/apis/config/v1beta1/defaults_test.go b/pkg/scheduler/apis/config/v1beta1/defaults_test.go index f334da90baa..584a23a6632 100644 --- a/pkg/scheduler/apis/config/v1beta1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1beta1/defaults_test.go @@ -265,10 +265,10 @@ func TestSchedulerDefaults(t *testing.T) { func TestPluginArgsDefaults(t *testing.T) { tests := []struct { - name string - feature featuregate.Feature - in runtime.Object - want runtime.Object + name string + features map[featuregate.Feature]bool + in runtime.Object + want runtime.Object }{ { name: "InterPodAffinityArgs empty", @@ -368,7 +368,7 @@ func TestPluginArgsDefaults(t *testing.T) { name: "PodTopologySpreadArgs resources empty", in: &v1beta1.PodTopologySpreadArgs{}, want: &v1beta1.PodTopologySpreadArgs{ - DefaultingType: v1beta1.ListDefaulting, + DefaultingType: v1beta1.SystemDefaulting, }, }, { @@ -390,38 +390,17 @@ func TestPluginArgsDefaults(t *testing.T) { MaxSkew: 2, }, }, + // TODO(#94008): Make SystemDefaulting in v1beta2. DefaultingType: v1beta1.ListDefaulting, }, }, { - name: "PodTopologySpreadArgs empty, DefaultPodTopologySpread feature enabled", - feature: features.DefaultPodTopologySpread, - in: &v1beta1.PodTopologySpreadArgs{}, - want: &v1beta1.PodTopologySpreadArgs{ - DefaultingType: v1beta1.SystemDefaulting, - }, - }, - { - name: "PodTopologySpreadArgs with constraints, DefaultPodTopologySpread feature enabled", - feature: features.DefaultPodTopologySpread, - in: &v1beta1.PodTopologySpreadArgs{ - DefaultConstraints: []v1.TopologySpreadConstraint{ - { - TopologyKey: v1.LabelHostname, - WhenUnsatisfiable: v1.ScheduleAnyway, - MaxSkew: 3, - }, - }, + name: "PodTopologySpreadArgs empty, DefaultPodTopologySpread feature disabled", + features: map[featuregate.Feature]bool{ + features.DefaultPodTopologySpread: false, }, + in: &v1beta1.PodTopologySpreadArgs{}, want: &v1beta1.PodTopologySpreadArgs{ - DefaultConstraints: []v1.TopologySpreadConstraint{ - { - TopologyKey: v1.LabelHostname, - WhenUnsatisfiable: v1.ScheduleAnyway, - MaxSkew: 3, - }, - }, - // TODO(#94008): Make SystemDefaulting in v1beta2. DefaultingType: v1beta1.ListDefaulting, }, }, @@ -430,8 +409,8 @@ func TestPluginArgsDefaults(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) t.Run(tc.name, func(t *testing.T) { - if tc.feature != "" { - defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, tc.feature, true)() + for k, v := range tc.features { + defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)() } scheme.Default(tc.in) if diff := cmp.Diff(tc.in, tc.want); diff != "" { diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index b254bd02fec..80b1b0fe1cb 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -43,6 +43,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" @@ -239,7 +240,12 @@ func TestCreateFromEmptyConfig(t *testing.T) { t.Fatal(err) } prof := factory.profiles[0] - wantConfig := []schedulerapi.PluginConfig{} + wantConfig := []schedulerapi.PluginConfig{ + { + Name: podtopologyspread.Name, + Args: &schedulerapi.PodTopologySpreadArgs{DefaultingType: schedulerapi.SystemDefaulting}, + }, + } if diff := cmp.Diff(wantConfig, prof.PluginConfig); diff != "" { t.Errorf("wrong plugin config (-want, +got): %s", diff) } diff --git a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go index ffbf02b825c..ebf2ddd5572 100644 --- a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go +++ b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go @@ -664,10 +664,12 @@ func TestDryRunPreemption(t *testing.T) { st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), ) registeredPlugins = append(registeredPlugins, tt.registerPlugins...) + informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(), 0) fwk, err := st.NewFramework( registeredPlugins, frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithSnapshotSharedLister(snapshot), + frameworkruntime.WithInformerFactory(informerFactory), ) if err != nil { t.Fatal(err) diff --git a/pkg/scheduler/framework/plugins/legacy_registry_test.go b/pkg/scheduler/framework/plugins/legacy_registry_test.go index 77bf0391e33..6bd76943b69 100644 --- a/pkg/scheduler/framework/plugins/legacy_registry_test.go +++ b/pkg/scheduler/framework/plugins/legacy_registry_test.go @@ -121,7 +121,6 @@ func TestAppendPriorityConfigs(t *testing.T) { Enabled: []config.Plugin{ {Name: podtopologyspread.Name}, {Name: interpodaffinity.Name}, - {Name: selectorspread.Name}, {Name: tainttoleration.Name}, }, }, @@ -134,17 +133,21 @@ func TestAppendPriorityConfigs(t *testing.T) { {Name: noderesources.LeastAllocatedName, Weight: 1}, {Name: nodeaffinity.Name, Weight: 1}, {Name: nodepreferavoidpods.Name, Weight: 10000}, - {Name: selectorspread.Name, Weight: 1}, {Name: tainttoleration.Name, Weight: 1}, }, }, }, + wantPluginConfig: []config.PluginConfig{ + { + Name: podtopologyspread.Name, + Args: &config.PodTopologySpreadArgs{ + DefaultingType: config.SystemDefaulting, + }, + }, + }, }, { name: "DefaultPodTopologySpread enabled, SelectorSpreadPriority only", - features: map[featuregate.Feature]bool{ - features.DefaultPodTopologySpread: true, - }, keys: map[string]int64{ SelectorSpreadPriority: 3, }, @@ -171,9 +174,6 @@ func TestAppendPriorityConfigs(t *testing.T) { }, { name: "DefaultPodTopologySpread enabled, EvenPodsSpreadPriority only", - features: map[featuregate.Feature]bool{ - features.DefaultPodTopologySpread: true, - }, keys: map[string]int64{ EvenPodsSpreadPriority: 4, }, @@ -199,9 +199,9 @@ func TestAppendPriorityConfigs(t *testing.T) { }, }, { - name: "DefaultPodTopologySpread enabled, SelectorSpreadPriority+EvenPodsSpreadPriority", + name: "DefaultPodTopologySpread disabled, SelectorSpreadPriority+EvenPodsSpreadPriority", features: map[featuregate.Feature]bool{ - features.DefaultPodTopologySpread: true, + features.DefaultPodTopologySpread: false, }, keys: map[string]int64{ SelectorSpreadPriority: 1, @@ -211,19 +211,13 @@ func TestAppendPriorityConfigs(t *testing.T) { PreScore: &config.PluginSet{ Enabled: []config.Plugin{ {Name: podtopologyspread.Name}, + {Name: selectorspread.Name}, }, }, Score: &config.PluginSet{ Enabled: []config.Plugin{ {Name: podtopologyspread.Name, Weight: 2}, - }, - }, - }, - wantPluginConfig: []config.PluginConfig{ - { - Name: podtopologyspread.Name, - Args: &config.PodTopologySpreadArgs{ - DefaultingType: config.SystemDefaulting, + {Name: selectorspread.Name, Weight: 1}, }, }, }, diff --git a/pkg/scheduler/framework/runtime/framework_test.go b/pkg/scheduler/framework/runtime/framework_test.go index cb11e1ebc13..f3b76705c28 100644 --- a/pkg/scheduler/framework/runtime/framework_test.go +++ b/pkg/scheduler/framework/runtime/framework_test.go @@ -531,7 +531,7 @@ func TestNewFrameworkPluginDefaults(t *testing.T) { Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}}, }, "PodTopologySpread": &config.PodTopologySpreadArgs{ - DefaultingType: config.ListDefaulting, + DefaultingType: config.SystemDefaulting, }, "VolumeBinding": &config.VolumeBindingArgs{ BindTimeoutSeconds: 600, @@ -593,7 +593,7 @@ func TestNewFrameworkPluginDefaults(t *testing.T) { Resources: []config.ResourceSpec{{Name: "resource", Weight: 3}}, }, "PodTopologySpread": &config.PodTopologySpreadArgs{ - DefaultingType: config.ListDefaulting, + DefaultingType: config.SystemDefaulting, }, "RequestedToCapacityRatio": &config.RequestedToCapacityRatioArgs{ Resources: []config.ResourceSpec{{Name: "resource", Weight: 2}}, diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 4493a5c27d7..dccbe40244c 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -130,7 +130,6 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { "PreScorePlugin": { {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -141,7 +140,6 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) { {Name: "NodeResourcesLeastAllocated", Weight: 1}, {Name: "NodeAffinity", Weight: 1}, {Name: "NodePreferAvoidPods", Weight: 10000}, - {Name: "SelectorSpread", Weight: 1}, {Name: "TaintToleration", Weight: 1}, }, "ReservePlugin": {{Name: "VolumeBinding"}}, @@ -223,7 +221,6 @@ kind: Policy "PreScorePlugin": { {Name: "PodTopologySpread"}, {Name: "InterPodAffinity"}, - {Name: "SelectorSpread"}, {Name: "TaintToleration"}, }, "ScorePlugin": { @@ -234,7 +231,6 @@ kind: Policy {Name: "NodeResourcesLeastAllocated", Weight: 1}, {Name: "NodeAffinity", Weight: 1}, {Name: "NodePreferAvoidPods", Weight: 10000}, - {Name: "SelectorSpread", Weight: 1}, {Name: "TaintToleration", Weight: 1}, }, "ReservePlugin": {{Name: "VolumeBinding"}},