From 2769e99dba25f2ee0e0f7169101bbece550dac13 Mon Sep 17 00:00:00 2001 From: Haleygo Date: Tue, 25 May 2021 16:05:56 +0800 Subject: [PATCH] remove scheduler deprecated algorithm-provider flag and clean up algorithmprovider pkg --- cluster/gce/gci/configure-helper.sh | 3 - cmd/kube-scheduler/app/options/deprecated.go | 8 -- .../app/options/deprecated_test.go | 2 - cmd/kube-scheduler/app/options/options.go | 1 - cmd/kube-scheduler/app/server_test.go | 62 ------------- pkg/scheduler/algorithmprovider/registry.go | 50 ++--------- .../algorithmprovider/registry_test.go | 89 +------------------ .../apis/config/testing/compatibility_test.go | 57 ------------ pkg/scheduler/factory.go | 7 +- 9 files changed, 12 insertions(+), 267 deletions(-) diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 4dd9191e9f8..147543109d6 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -2203,9 +2203,6 @@ function start-kube-scheduler { params+=("--config=/etc/srv/kubernetes/kube-scheduler/config") else params+=("--kubeconfig=/etc/srv/kubernetes/kube-scheduler/kubeconfig") - if [[ -n "${SCHEDULING_ALGORITHM_PROVIDER:-}" ]]; then - params+=("--algorithm-provider=${SCHEDULING_ALGORITHM_PROVIDER}") - fi if [[ -n "${SCHEDULER_POLICY_CONFIG:-}" ]]; then create-kubescheduler-policy-config params+=("--use-legacy-policy-config") diff --git a/cmd/kube-scheduler/app/options/deprecated.go b/cmd/kube-scheduler/app/options/deprecated.go index b5cbca3a948..a8532896d78 100644 --- a/cmd/kube-scheduler/app/options/deprecated.go +++ b/cmd/kube-scheduler/app/options/deprecated.go @@ -21,7 +21,6 @@ import ( "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/kubernetes/pkg/scheduler/algorithmprovider" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config/validation" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" @@ -36,7 +35,6 @@ type DeprecatedOptions struct { PolicyConfigMapName string PolicyConfigMapNamespace string UseLegacyPolicyConfig bool - AlgorithmProvider string HardPodAffinitySymmetricWeight int32 SchedulerName string } @@ -47,7 +45,6 @@ func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig return } - fs.StringVar(&o.AlgorithmProvider, "algorithm-provider", o.AlgorithmProvider, "DEPRECATED: the scheduling algorithm provider to use, this sets the default plugins for component config profiles. Choose one of: "+algorithmprovider.ListAlgorithmProviders()) fs.StringVar(&o.PolicyConfigFile, "policy-config-file", o.PolicyConfigFile, "DEPRECATED: file with scheduler policy configuration. This file is used if policy ConfigMap is not provided or --use-legacy-policy-config=true. Note: The scheduler will fail if this is combined with Plugin configs") usage := fmt.Sprintf("DEPRECATED: name of the ConfigMap object that contains scheduler's policy configuration. It must exist in the system namespace before scheduler initialization if --use-legacy-policy-config=false. The config must be provided as the value of an element in 'Data' map with the key='%v'. Note: The scheduler will fail if this is combined with Plugin configs", kubeschedulerconfig.SchedulerPolicyConfigMapKey) fs.StringVar(&o.PolicyConfigMapName, "policy-configmap", o.PolicyConfigMapName, usage) @@ -91,7 +88,6 @@ func (o *DeprecatedOptions) Validate() []error { // // 1. --use-legacy-policy-config to use a policy file. // 2. --policy-configmap to use a policy config map value. -// 3. --algorithm-provider to use a named algorithm provider. func (o *DeprecatedOptions) ApplyAlgorithmSourceTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) { if o == nil { return @@ -115,10 +111,6 @@ func (o *DeprecatedOptions) ApplyAlgorithmSourceTo(cfg *kubeschedulerconfig.Kube }, }, } - case len(o.AlgorithmProvider) > 0: - cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{ - Provider: &o.AlgorithmProvider, - } } } diff --git a/cmd/kube-scheduler/app/options/deprecated_test.go b/cmd/kube-scheduler/app/options/deprecated_test.go index 17830535a5c..7f9c3b9d1ad 100644 --- a/cmd/kube-scheduler/app/options/deprecated_test.go +++ b/cmd/kube-scheduler/app/options/deprecated_test.go @@ -29,7 +29,6 @@ func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) { config: &DeprecatedOptions{ PolicyConfigFile: "/some/file", UseLegacyPolicyConfig: true, - AlgorithmProvider: "", }, }, "bad-policy-config-file-null": { @@ -37,7 +36,6 @@ func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) { config: &DeprecatedOptions{ PolicyConfigFile: "", UseLegacyPolicyConfig: true, - AlgorithmProvider: "", }, }, "good affinity weight": { diff --git a/cmd/kube-scheduler/app/options/options.go b/cmd/kube-scheduler/app/options/options.go index 9f9a861276e..bd2d88d9ff9 100644 --- a/cmd/kube-scheduler/app/options/options.go +++ b/cmd/kube-scheduler/app/options/options.go @@ -148,7 +148,6 @@ func newDefaultComponentConfig() (*kubeschedulerconfig.KubeSchedulerConfiguratio func (o *Options) Flags() (nfs cliflag.NamedFlagSets) { fs := nfs.FlagSet("misc") fs.StringVar(&o.ConfigFile, "config", o.ConfigFile, `The path to the configuration file. The following flags can overwrite fields in this file: - --algorithm-provider --policy-config-file --policy-configmap --policy-configmap-namespace`) diff --git a/cmd/kube-scheduler/app/server_test.go b/cmd/kube-scheduler/app/server_test.go index ff6fed02d35..7b5059b08ef 100644 --- a/cmd/kube-scheduler/app/server_test.go +++ b/cmd/kube-scheduler/app/server_test.go @@ -268,73 +268,11 @@ profiles: name: "default algorithm provider", flags: []string{ "--kubeconfig", configKubeconfig, - "--algorithm-provider", "DefaultProvider", }, wantPlugins: map[string]map[string][]kubeschedulerconfig.Plugin{ "default-scheduler": defaultPlugins, }, }, - { - name: "cluster autoscaler provider", - flags: []string{ - "--kubeconfig", configKubeconfig, - "--algorithm-provider", "ClusterAutoscalerProvider", - }, - wantPlugins: map[string]map[string][]kubeschedulerconfig.Plugin{ - "default-scheduler": { - "QueueSortPlugin": { - {Name: "PrioritySort"}, - }, - "PreFilterPlugin": { - {Name: "NodeResourcesFit"}, - {Name: "NodePorts"}, - {Name: "PodTopologySpread"}, - {Name: "InterPodAffinity"}, - {Name: "VolumeBinding"}, - {Name: "NodeAffinity"}, - }, - "FilterPlugin": { - {Name: "NodeUnschedulable"}, - {Name: "NodeName"}, - {Name: "TaintToleration"}, - {Name: "NodeAffinity"}, - {Name: "NodePorts"}, - {Name: "NodeResourcesFit"}, - {Name: "VolumeRestrictions"}, - {Name: "EBSLimits"}, - {Name: "GCEPDLimits"}, - {Name: "NodeVolumeLimits"}, - {Name: "AzureDiskLimits"}, - {Name: "VolumeBinding"}, - {Name: "VolumeZone"}, - {Name: "PodTopologySpread"}, - {Name: "InterPodAffinity"}, - }, - "PostFilterPlugin": { - {Name: "DefaultPreemption"}, - }, - "PreScorePlugin": { - {Name: "InterPodAffinity"}, - {Name: "PodTopologySpread"}, - {Name: "TaintToleration"}, - {Name: "NodeAffinity"}, - }, - "ScorePlugin": { - {Name: "NodeResourcesBalancedAllocation", Weight: 1}, - {Name: "ImageLocality", Weight: 1}, - {Name: "InterPodAffinity", Weight: 1}, - {Name: "NodeResourcesMostAllocated", Weight: 1}, - {Name: "NodeAffinity", Weight: 1}, - {Name: "NodePreferAvoidPods", Weight: 10000}, - {Name: "PodTopologySpread", Weight: 2}, - {Name: "TaintToleration", Weight: 1}, - }, - "BindPlugin": {{Name: "DefaultBinder"}}, - "ReservePlugin": {{Name: "VolumeBinding"}}, - "PreBindPlugin": {{Name: "VolumeBinding"}}, - }, - }, - }, { name: "policy config file", flags: []string{ diff --git a/pkg/scheduler/algorithmprovider/registry.go b/pkg/scheduler/algorithmprovider/registry.go index c1adea5a44e..d8d25380988 100644 --- a/pkg/scheduler/algorithmprovider/registry.go +++ b/pkg/scheduler/algorithmprovider/registry.go @@ -17,8 +17,6 @@ limitations under the License. package algorithmprovider import ( - "fmt" - utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/klog/v2" "k8s.io/kubernetes/pkg/features" @@ -43,32 +41,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone" ) -// ClusterAutoscalerProvider defines the default autoscaler provider -const ClusterAutoscalerProvider = "ClusterAutoscalerProvider" - -// Registry is a collection of all available algorithm providers. -type Registry map[string]*schedulerapi.Plugins - -// NewRegistry returns an algorithm provider registry instance. -func NewRegistry() Registry { - defaultConfig := getDefaultConfig() - applyFeatureGates(defaultConfig) - - caConfig := getClusterAutoscalerConfig() - applyFeatureGates(caConfig) - - return Registry{ - schedulerapi.SchedulerDefaultProviderName: defaultConfig, - ClusterAutoscalerProvider: caConfig, - } -} - -// ListAlgorithmProviders lists registered algorithm providers. -func ListAlgorithmProviders() string { - return fmt.Sprintf("%s | %s", ClusterAutoscalerProvider, schedulerapi.SchedulerDefaultProviderName) -} - -func getDefaultConfig() *schedulerapi.Plugins { +func GetDefaultConfig() *schedulerapi.Plugins { plugins := &schedulerapi.Plugins{ QueueSort: schedulerapi.PluginSet{ Enabled: []schedulerapi.Plugin{ @@ -148,24 +121,17 @@ func getDefaultConfig() *schedulerapi.Plugins { }, }, } - if utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority) { - plugins.Score.Enabled = append(plugins.Score.Enabled, schedulerapi.Plugin{Name: volumebinding.Name, Weight: 1}) - } + + applyFeatureGates(plugins) + return plugins } -func getClusterAutoscalerConfig() *schedulerapi.Plugins { - caConfig := getDefaultConfig() - // Replace least with most requested. - for i := range caConfig.Score.Enabled { - if caConfig.Score.Enabled[i].Name == noderesources.LeastAllocatedName { - caConfig.Score.Enabled[i].Name = noderesources.MostAllocatedName - } - } - return caConfig -} - func applyFeatureGates(config *schedulerapi.Plugins) { + if utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority) { + config.Score.Enabled = append(config.Score.Enabled, schedulerapi.Plugin{Name: volumebinding.Name, Weight: 1}) + } + if !utilfeature.DefaultFeatureGate.Enabled(features.DefaultPodTopologySpread) { // When feature is enabled, the default spreading is done by // PodTopologySpread plugin, which is enabled by default. diff --git a/pkg/scheduler/algorithmprovider/registry_test.go b/pkg/scheduler/algorithmprovider/registry_test.go index 38b1c41618e..b7d4cd19396 100644 --- a/pkg/scheduler/algorithmprovider/registry_test.go +++ b/pkg/scheduler/algorithmprovider/registry_test.go @@ -45,91 +45,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone" ) -func TestClusterAutoscalerProvider(t *testing.T) { - 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}, - {Name: nodeaffinity.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}, - {Name: nodeaffinity.Name}, - }, - }, - Score: schedulerapi.PluginSet{ - Enabled: []schedulerapi.Plugin{ - {Name: noderesources.BalancedAllocationName, Weight: 1}, - {Name: imagelocality.Name, Weight: 1}, - {Name: interpodaffinity.Name, Weight: 1}, - {Name: noderesources.MostAllocatedName, 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}, - }, - }, - } - - r := NewRegistry() - gotConfig := r[ClusterAutoscalerProvider] - if diff := cmp.Diff(wantConfig, gotConfig); diff != "" { - t.Errorf("unexpected config diff (-want, +got): %s", diff) - } -} - func TestApplyFeatureGates(t *testing.T) { tests := []struct { name string @@ -307,8 +222,8 @@ func TestApplyFeatureGates(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)() } - r := NewRegistry() - gotConfig := r[schedulerapi.SchedulerDefaultProviderName] + gotConfig := GetDefaultConfig() + if diff := cmp.Diff(test.wantConfig, gotConfig); diff != "" { t.Errorf("unexpected config diff (-want, +got): %s", diff) } diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index 6eefc3c204a..e1cbd51402b 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -32,7 +32,6 @@ import ( featuregatetesting "k8s.io/component-base/featuregate/testing" _ "k8s.io/kubernetes/pkg/apis/core/install" "k8s.io/kubernetes/pkg/scheduler" - "k8s.io/kubernetes/pkg/scheduler/algorithmprovider" "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/core" ) @@ -1482,62 +1481,6 @@ func TestAlgorithmProviderCompatibility(t *testing.T) { provider: config.SchedulerDefaultProviderName, wantPlugins: defaultPlugins, }, - { - name: "ClusterAutoscalerProvider", - provider: algorithmprovider.ClusterAutoscalerProvider, - wantPlugins: map[string][]config.Plugin{ - "QueueSortPlugin": { - {Name: "PrioritySort"}, - }, - "PreFilterPlugin": { - {Name: "NodeResourcesFit"}, - {Name: "NodePorts"}, - {Name: "PodTopologySpread"}, - {Name: "InterPodAffinity"}, - {Name: "VolumeBinding"}, - {Name: "NodeAffinity"}, - }, - "FilterPlugin": { - {Name: "NodeUnschedulable"}, - {Name: "NodeName"}, - {Name: "TaintToleration"}, - {Name: "NodeAffinity"}, - {Name: "NodePorts"}, - {Name: "NodeResourcesFit"}, - {Name: "VolumeRestrictions"}, - {Name: "EBSLimits"}, - {Name: "GCEPDLimits"}, - {Name: "NodeVolumeLimits"}, - {Name: "AzureDiskLimits"}, - {Name: "VolumeBinding"}, - {Name: "VolumeZone"}, - {Name: "PodTopologySpread"}, - {Name: "InterPodAffinity"}, - }, - "PostFilterPlugin": { - {Name: "DefaultPreemption"}, - }, - "PreScorePlugin": { - {Name: "InterPodAffinity"}, - {Name: "PodTopologySpread"}, - {Name: "TaintToleration"}, - {Name: "NodeAffinity"}, - }, - "ScorePlugin": { - {Name: "NodeResourcesBalancedAllocation", Weight: 1}, - {Name: "ImageLocality", Weight: 1}, - {Name: "InterPodAffinity", Weight: 1}, - {Name: "NodeResourcesMostAllocated", Weight: 1}, - {Name: "NodeAffinity", Weight: 1}, - {Name: "NodePreferAvoidPods", Weight: 10000}, - {Name: "PodTopologySpread", Weight: 2}, - {Name: "TaintToleration", Weight: 1}, - }, - "ReservePlugin": {{Name: "VolumeBinding"}}, - "PreBindPlugin": {{Name: "VolumeBinding"}}, - "BindPlugin": {{Name: "DefaultBinder"}}, - }, - }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index fb501219672..abd55dab7ff 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -195,11 +195,8 @@ func (c *Configurator) create() (*Scheduler, error) { // createFromProvider creates a scheduler from the name of a registered algorithm provider. func (c *Configurator) createFromProvider(providerName string) (*Scheduler, error) { klog.V(2).InfoS("Creating scheduler from algorithm provider", "algorithmProvider", providerName) - r := algorithmprovider.NewRegistry() - defaultPlugins, exist := r[providerName] - if !exist { - return nil, fmt.Errorf("algorithm provider %q is not registered", providerName) - } + + defaultPlugins := algorithmprovider.GetDefaultConfig() for i := range c.profiles { prof := &c.profiles[i]