From 52f5ba3a58d37e934ed39bc2ca71fa245e0bbd09 Mon Sep 17 00:00:00 2001 From: Abdullah Gharaibeh Date: Wed, 9 Jun 2021 14:03:06 -0400 Subject: [PATCH] Remove SchedulerAlgorithmSource from scheduler's internal CC API --- cmd/kube-scheduler/app/config/config.go | 2 + cmd/kube-scheduler/app/options/deprecated.go | 31 +++-- cmd/kube-scheduler/app/options/options.go | 6 +- .../app/options/options_test.go | 15 +-- cmd/kube-scheduler/app/server.go | 2 +- .../apis/config/testing/compatibility_test.go | 119 +----------------- pkg/scheduler/apis/config/types.go | 19 --- .../apis/config/v1beta1/conversion.go | 2 - .../apis/config/v1beta1/conversion_test.go | 62 --------- .../config/v1beta1/zz_generated.conversion.go | 1 - .../apis/config/v1beta2/conversion.go | 2 - .../apis/config/v1beta2/conversion_test.go | 62 --------- .../config/v1beta2/zz_generated.conversion.go | 1 - .../apis/config/validation/validation_test.go | 8 -- .../apis/config/zz_generated.deepcopy.go | 27 ---- pkg/scheduler/factory.go | 12 +- pkg/scheduler/factory_test.go | 17 ++- pkg/scheduler/scheduler.go | 41 +++--- test/integration/scheduler/scheduler_test.go | 20 ++- test/integration/util/util.go | 17 ++- 20 files changed, 69 insertions(+), 397 deletions(-) delete mode 100644 pkg/scheduler/apis/config/v1beta1/conversion_test.go delete mode 100644 pkg/scheduler/apis/config/v1beta2/conversion_test.go diff --git a/cmd/kube-scheduler/app/config/config.go b/cmd/kube-scheduler/app/config/config.go index 2b36c1c880d..fe708e34139 100644 --- a/cmd/kube-scheduler/app/config/config.go +++ b/cmd/kube-scheduler/app/config/config.go @@ -31,6 +31,8 @@ type Config struct { // ComponentConfig is the scheduler server's configuration object. ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration + LegacyPolicySource *kubeschedulerconfig.SchedulerPolicySource + // LoopbackClientConfig is a config for a privileged loopback connection LoopbackClientConfig *restclient.Config diff --git a/cmd/kube-scheduler/app/options/deprecated.go b/cmd/kube-scheduler/app/options/deprecated.go index a8532896d78..aedf605b7c5 100644 --- a/cmd/kube-scheduler/app/options/deprecated.go +++ b/cmd/kube-scheduler/app/options/deprecated.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/util/validation/field" + schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config/validation" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" @@ -84,48 +85,44 @@ func (o *DeprecatedOptions) Validate() []error { return errs } -// ApplyAlgorithmSourceTo sets cfg.AlgorithmSource from flags passed on the command line in the following precedence order: +// ApplyPolicySourceTo sets cfg.PolicySource from flags passed on the command line in the following precedence order: // // 1. --use-legacy-policy-config to use a policy file. // 2. --policy-configmap to use a policy config map value. -func (o *DeprecatedOptions) ApplyAlgorithmSourceTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) { +func (o *DeprecatedOptions) ApplyPolicySourceTo(c *schedulerappconfig.Config) { if o == nil { return } switch { case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""): - cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{ - Policy: &kubeschedulerconfig.SchedulerPolicySource{ - File: &kubeschedulerconfig.SchedulerPolicyFileSource{ - Path: o.PolicyConfigFile, - }, + c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{ + File: &kubeschedulerconfig.SchedulerPolicyFileSource{ + Path: o.PolicyConfigFile, }, } case len(o.PolicyConfigMapName) > 0: - cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{ - Policy: &kubeschedulerconfig.SchedulerPolicySource{ - ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ - Name: o.PolicyConfigMapName, - Namespace: o.PolicyConfigMapNamespace, - }, + c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{ + ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ + Name: o.PolicyConfigMapName, + Namespace: o.PolicyConfigMapNamespace, }, } } } // ApplyTo sets a default profile plugin config if no config file is specified -// It also calls ApplyAlgorithmSourceTo to set Policy settings in AlgorithmSource, if applicable. +// It also calls ApplyPolicySourceTo to set Policy source if applicable. // Deprecated flags have an effect iff no config file was provided, in which // case this function expects a default KubeSchedulerConfiguration instance, // which has a single profile. -func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) { +func (o *DeprecatedOptions) ApplyTo(c *schedulerappconfig.Config) { if o == nil { return } // The following deprecated options affect the only existing profile that is // added by default. - profile := &cfg.Profiles[0] + profile := &c.ComponentConfig.Profiles[0] if len(o.SchedulerName) > 0 { profile.SchedulerName = o.SchedulerName } @@ -137,5 +134,5 @@ func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfig } profile.PluginConfig = append(profile.PluginConfig, plCfg) - o.ApplyAlgorithmSourceTo(cfg) + o.ApplyPolicySourceTo(c) } diff --git a/cmd/kube-scheduler/app/options/options.go b/cmd/kube-scheduler/app/options/options.go index 8d0e8b9904f..0b9d9ef1647 100644 --- a/cmd/kube-scheduler/app/options/options.go +++ b/cmd/kube-scheduler/app/options/options.go @@ -179,7 +179,7 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error { c.ComponentConfig = o.ComponentConfig // apply deprecated flags if no config file is loaded (this is the old behaviour). - o.Deprecated.ApplyTo(&c.ComponentConfig) + o.Deprecated.ApplyTo(c) if err := o.CombinedInsecureServing.ApplyTo(c, &c.ComponentConfig); err != nil { return err } @@ -195,11 +195,11 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error { c.ComponentConfig = *cfg // apply any deprecated Policy flags, if applicable - o.Deprecated.ApplyAlgorithmSourceTo(&c.ComponentConfig) + o.Deprecated.ApplyPolicySourceTo(c) // if the user has set CC profiles and is trying to use a Policy config, error out // these configs are no longer merged and they should not be used simultaneously - if !emptySchedulerProfileConfig(c.ComponentConfig.Profiles) && c.ComponentConfig.AlgorithmSource.Policy != nil { + if !emptySchedulerProfileConfig(c.ComponentConfig.Profiles) && c.LegacyPolicySource != nil { return fmt.Errorf("cannot set a Plugin config and Policy config") } diff --git a/cmd/kube-scheduler/app/options/options_test.go b/cmd/kube-scheduler/app/options/options_test.go index 5894439d44b..bc0ba8c9893 100644 --- a/cmd/kube-scheduler/app/options/options_test.go +++ b/cmd/kube-scheduler/app/options/options_test.go @@ -330,7 +330,6 @@ profiles: defer os.Setenv("KUBERNETES_SERVICE_HOST", originalHost) } - defaultSource := "DefaultProvider" defaultPodInitialBackoffSeconds := int64(1) defaultPodMaxBackoffSeconds := int64(10) defaultPercentageOfNodesToScore := int32(0) @@ -386,7 +385,6 @@ profiles: APIVersion: v1beta2.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -459,7 +457,6 @@ profiles: APIVersion: v1beta1.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -560,7 +557,6 @@ profiles: APIVersion: v1beta2.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "", // defaults empty when not running from config file MetricsBindAddress: "", // defaults empty when not running from config file DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -629,7 +625,6 @@ profiles: APIVersion: v1beta2.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "", // defaults empty when not running from config file MetricsBindAddress: "", // defaults empty when not running from config file DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -672,7 +667,6 @@ profiles: APIVersion: v1beta2.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -750,7 +744,6 @@ profiles: APIVersion: v1beta1.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -829,7 +822,6 @@ profiles: APIVersion: v1beta2.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -895,7 +887,6 @@ profiles: APIVersion: v1beta1.SchemeGroupVersion.String(), }, Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, HealthzBindAddress: "0.0.0.0:10251", MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -974,8 +965,7 @@ profiles: TypeMeta: metav1.TypeMeta{ APIVersion: v1beta2.SchemeGroupVersion.String(), }, - Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + Parallelism: 16, DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, @@ -1030,8 +1020,7 @@ profiles: TypeMeta: metav1.TypeMeta{ APIVersion: v1beta2.SchemeGroupVersion.String(), }, - Parallelism: 16, - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + Parallelism: 16, DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 4ce283dea1b..dc6cc055415 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -333,7 +333,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion), scheduler.WithKubeConfig(cc.KubeConfig), scheduler.WithProfiles(cc.ComponentConfig.Profiles...), - scheduler.WithAlgorithmSource(cc.ComponentConfig.AlgorithmSource), + scheduler.WithLegacyPolicySource(cc.LegacyPolicySource), scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore), scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry), scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds), diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index e1cbd51402b..73b9d6bfb4a 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -1365,14 +1365,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { Data: map[string]string{config.SchedulerPolicyConfigMapKey: tc.JSON}, } client := fake.NewSimpleClientset(&policyConfigMap) - algorithmSrc := config.SchedulerAlgorithmSource{ - Policy: &config.SchedulerPolicySource{ - ConfigMap: &config.SchedulerPolicyConfigMapSource{ - Namespace: policyConfigMap.Namespace, - Name: policyConfigMap.Name, - }, - }, - } informerFactory := informers.NewSharedInformerFactory(client, 0) recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()})) @@ -1381,7 +1373,12 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { informerFactory, recorderFactory, make(chan struct{}), - scheduler.WithAlgorithmSource(algorithmSrc), + scheduler.WithLegacyPolicySource(&config.SchedulerPolicySource{ + ConfigMap: &config.SchedulerPolicyConfigMapSource{ + Namespace: policyConfigMap.Namespace, + Name: policyConfigMap.Name, + }, + }), ) if err != nil { @@ -1412,110 +1409,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { } } -func TestAlgorithmProviderCompatibility(t *testing.T) { - // Add serialized versions of scheduler config that exercise available options to ensure compatibility between releases - defaultPlugins := 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: "NodeResourcesLeastAllocated", 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"}}, - } - - testcases := []struct { - name string - provider string - wantPlugins map[string][]config.Plugin - }{ - { - name: "No Provider specified", - wantPlugins: defaultPlugins, - }, - { - name: "DefaultProvider", - provider: config.SchedulerDefaultProviderName, - wantPlugins: defaultPlugins, - }, - } - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - var opts []scheduler.Option - if len(tc.provider) != 0 { - opts = append(opts, scheduler.WithAlgorithmSource(config.SchedulerAlgorithmSource{ - Provider: &tc.provider, - })) - } - - client := fake.NewSimpleClientset() - informerFactory := informers.NewSharedInformerFactory(client, 0) - recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()})) - - sched, err := scheduler.New( - client, - informerFactory, - recorderFactory, - make(chan struct{}), - opts..., - ) - - if err != nil { - t.Fatalf("Error constructing: %v", err) - } - - defProf := sched.Profiles["default-scheduler"] - gotPlugins := defProf.ListPlugins() - if diff := cmp.Diff(tc.wantPlugins, gotPlugins); diff != "" { - t.Errorf("unexpected plugins diff (-want, +got): %s", diff) - } - }) - } -} - func TestPluginsConfigurationCompatibility(t *testing.T) { defaultPlugins := map[string][]config.Plugin{ "QueueSortPlugin": { diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index 9dec5b48d99..e829aa7c61a 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -30,9 +30,6 @@ const ( // scheduler's policy ConfigMap that contains scheduler's policy config. SchedulerPolicyConfigMapKey = "policy.cfg" - // SchedulerDefaultProviderName defines the default provider names - SchedulerDefaultProviderName = "DefaultProvider" - // DefaultInsecureSchedulerPort is the default port for the scheduler status server. // May be overridden by a flag at startup. // Deprecated: use the secure KubeSchedulerPort instead. @@ -60,11 +57,6 @@ type KubeSchedulerConfiguration struct { // Parallelism defines the amount of parallelism in algorithms for scheduling a Pods. Must be greater than 0. Defaults to 16 Parallelism int32 - // AlgorithmSource specifies the scheduler algorithm source. - // TODO(#87526): Remove AlgorithmSource from this package - // DEPRECATED: AlgorithmSource is removed in the v1beta1 ComponentConfig - AlgorithmSource SchedulerAlgorithmSource - // LeaderElection defines the configuration of leader election client. LeaderElection componentbaseconfig.LeaderElectionConfiguration @@ -136,15 +128,6 @@ type KubeSchedulerProfile struct { PluginConfig []PluginConfig } -// SchedulerAlgorithmSource is the source of a scheduler algorithm. One source -// field must be specified, and source fields are mutually exclusive. -type SchedulerAlgorithmSource struct { - // Policy is a policy based algorithm source. - Policy *SchedulerPolicySource - // Provider is the name of a scheduling algorithm provider to use. - Provider *string -} - // SchedulerPolicySource configures a means to obtain a scheduler Policy. One // source field must be specified, and source fields are mutually exclusive. type SchedulerPolicySource struct { @@ -305,7 +288,6 @@ func (p *Plugins) Apply(customPlugins *Plugins) { } func mergePluginSets(defaultPluginSet, customPluginSet PluginSet) PluginSet { - disabledPlugins := sets.NewString() for _, disabledPlugin := range customPluginSet.Disabled { disabledPlugins.Insert(disabledPlugin.Name) @@ -323,7 +305,6 @@ func mergePluginSets(defaultPluginSet, customPluginSet PluginSet) PluginSet { } enabledPlugins = append(enabledPlugins, customPluginSet.Enabled...) - return PluginSet{Enabled: enabledPlugins} } diff --git a/pkg/scheduler/apis/config/v1beta1/conversion.go b/pkg/scheduler/apis/config/v1beta1/conversion.go index 431ef15fe49..436912691bf 100644 --- a/pkg/scheduler/apis/config/v1beta1/conversion.go +++ b/pkg/scheduler/apis/config/v1beta1/conversion.go @@ -25,7 +25,6 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kube-scheduler/config/v1beta1" "k8s.io/kubernetes/pkg/scheduler/apis/config" - "k8s.io/utils/pointer" ) var ( @@ -142,7 +141,6 @@ func Convert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigura if err := autoConvert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil { return err } - out.AlgorithmSource.Provider = pointer.StringPtr(v1beta1.SchedulerDefaultProviderName) return convertToInternalPluginConfigArgs(out) } diff --git a/pkg/scheduler/apis/config/v1beta1/conversion_test.go b/pkg/scheduler/apis/config/v1beta1/conversion_test.go deleted file mode 100644 index 6872f282a38..00000000000 --- a/pkg/scheduler/apis/config/v1beta1/conversion_test.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/kube-scheduler/config/v1beta1" - "k8s.io/kubernetes/pkg/scheduler/apis/config" - "k8s.io/utils/pointer" -) - -func TestV1beta1ToConfigKubeSchedulerConfigurationConversion(t *testing.T) { - cases := []struct { - name string - config v1beta1.KubeSchedulerConfiguration - want config.KubeSchedulerConfiguration - }{ - { - name: "default conversion v1beta1 to config", - config: v1beta1.KubeSchedulerConfiguration{}, - want: config.KubeSchedulerConfiguration{ - AlgorithmSource: config.SchedulerAlgorithmSource{ - Provider: pointer.StringPtr(v1beta1.SchedulerDefaultProviderName), - }, - }, - }, - } - - scheme := runtime.NewScheme() - if err := AddToScheme(scheme); err != nil { - t.Fatal(err) - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - var got config.KubeSchedulerConfiguration - if err := scheme.Convert(&tc.config, &got, nil); err != nil { - t.Errorf("failed to convert: %+v", err) - } - if diff := cmp.Diff(tc.want, got); diff != "" { - t.Errorf("unexpected conversion (-want, +got):\n%s", diff) - } - }) - } -} diff --git a/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go index 66b69707378..b7011164fcb 100644 --- a/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go @@ -386,7 +386,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta1_KubeSchedulerConfi if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil { return err } - // WARNING: in.AlgorithmSource requires manual conversion: does not exist in peer-type if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } diff --git a/pkg/scheduler/apis/config/v1beta2/conversion.go b/pkg/scheduler/apis/config/v1beta2/conversion.go index b9e533d6293..65a973d6d83 100644 --- a/pkg/scheduler/apis/config/v1beta2/conversion.go +++ b/pkg/scheduler/apis/config/v1beta2/conversion.go @@ -25,7 +25,6 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/kube-scheduler/config/v1beta2" "k8s.io/kubernetes/pkg/scheduler/apis/config" - "k8s.io/utils/pointer" ) var ( @@ -50,7 +49,6 @@ func Convert_v1beta2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigura if err := autoConvert_v1beta2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil { return err } - out.AlgorithmSource.Provider = pointer.StringPtr(v1beta2.SchedulerDefaultProviderName) return convertToInternalPluginConfigArgs(out) } diff --git a/pkg/scheduler/apis/config/v1beta2/conversion_test.go b/pkg/scheduler/apis/config/v1beta2/conversion_test.go deleted file mode 100644 index 6c5589cbb21..00000000000 --- a/pkg/scheduler/apis/config/v1beta2/conversion_test.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta2 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/kube-scheduler/config/v1beta2" - "k8s.io/kubernetes/pkg/scheduler/apis/config" - "k8s.io/utils/pointer" -) - -func TestV1beta2ToConfigKubeSchedulerConfigurationConversion(t *testing.T) { - cases := []struct { - name string - config v1beta2.KubeSchedulerConfiguration - want config.KubeSchedulerConfiguration - }{ - { - name: "default conversion v1beta2 to config", - config: v1beta2.KubeSchedulerConfiguration{}, - want: config.KubeSchedulerConfiguration{ - AlgorithmSource: config.SchedulerAlgorithmSource{ - Provider: pointer.StringPtr(v1beta2.SchedulerDefaultProviderName), - }, - }, - }, - } - - scheme := runtime.NewScheme() - if err := AddToScheme(scheme); err != nil { - t.Fatal(err) - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - var got config.KubeSchedulerConfiguration - if err := scheme.Convert(&tc.config, &got, nil); err != nil { - t.Errorf("failed to convert: %+v", err) - } - if diff := cmp.Diff(tc.want, got); diff != "" { - t.Errorf("unexpected conversion (-want, +got):\n%s", diff) - } - }) - } -} diff --git a/pkg/scheduler/apis/config/v1beta2/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1beta2/zz_generated.conversion.go index a8b8c3b2500..4362b96fa71 100644 --- a/pkg/scheduler/apis/config/v1beta2/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1beta2/zz_generated.conversion.go @@ -366,7 +366,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta2_KubeSchedulerConfi if err := v1.Convert_int32_To_Pointer_int32(&in.Parallelism, &out.Parallelism, s); err != nil { return err } - // WARNING: in.AlgorithmSource requires manual conversion: does not exist in peer-type if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } diff --git a/pkg/scheduler/apis/config/validation/validation_test.go b/pkg/scheduler/apis/config/validation/validation_test.go index e24ca350af4..ed8368d57df 100644 --- a/pkg/scheduler/apis/config/validation/validation_test.go +++ b/pkg/scheduler/apis/config/validation/validation_test.go @@ -45,14 +45,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { QPS: 10, Burst: 10, }, - AlgorithmSource: config.SchedulerAlgorithmSource{ - Policy: &config.SchedulerPolicySource{ - ConfigMap: &config.SchedulerPolicyConfigMapSource{ - Namespace: "name", - Name: "name", - }, - }, - }, LeaderElection: componentbaseconfig.LeaderElectionConfiguration{ ResourceLock: "configmap", LeaderElect: true, diff --git a/pkg/scheduler/apis/config/zz_generated.deepcopy.go b/pkg/scheduler/apis/config/zz_generated.deepcopy.go index b4ca51e5e45..ae389777afa 100644 --- a/pkg/scheduler/apis/config/zz_generated.deepcopy.go +++ b/pkg/scheduler/apis/config/zz_generated.deepcopy.go @@ -153,7 +153,6 @@ func (in *InterPodAffinityArgs) DeepCopyObject() runtime.Object { func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) { *out = *in out.TypeMeta = in.TypeMeta - in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource) out.LeaderElection = in.LeaderElection out.ClientConnection = in.ClientConnection out.DebuggingConfiguration = in.DebuggingConfiguration @@ -769,32 +768,6 @@ func (in *ResourceSpec) DeepCopy() *ResourceSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SchedulerAlgorithmSource) DeepCopyInto(out *SchedulerAlgorithmSource) { - *out = *in - if in.Policy != nil { - in, out := &in.Policy, &out.Policy - *out = new(SchedulerPolicySource) - (*in).DeepCopyInto(*out) - } - if in.Provider != nil { - in, out := &in.Provider, &out.Provider - *out = new(string) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SchedulerAlgorithmSource. -func (in *SchedulerAlgorithmSource) DeepCopy() *SchedulerAlgorithmSource { - if in == nil { - return nil - } - out := new(SchedulerAlgorithmSource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SchedulerPolicyConfigMapSource) DeepCopyInto(out *SchedulerPolicyConfigMapSource) { *out = *in diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 232496883fb..20cded928da 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -195,10 +195,8 @@ func (c *Configurator) create() (*Scheduler, error) { }, nil } -// 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) - +// createFromConfig creates a scheduler from ComonentConfig profiles. +func (c *Configurator) createFromConfig() (*Scheduler, error) { defaultPlugins := algorithmprovider.GetDefaultConfig() for i := range c.profiles { @@ -211,9 +209,8 @@ func (c *Configurator) createFromProvider(providerName string) (*Scheduler, erro return c.create() } -// createFromConfig creates a scheduler from the configuration file -// Only reachable when using v1alpha1 component config -func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, error) { +// createFromPolicy creates a scheduler from the legacy policy file +func (c *Configurator) createFromPolicy(policy schedulerapi.Policy) (*Scheduler, error) { lr := frameworkplugins.NewLegacyRegistry() args := &frameworkplugins.ConfigProducerArgs{} @@ -226,7 +223,6 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, predicateKeys := sets.NewString() if policy.Predicates == nil { - klog.V(2).InfoS("Using predicates from algorithm provider", "algorithmProvider", schedulerapi.SchedulerDefaultProviderName) predicateKeys = lr.DefaultPredicates } else { for _, predicate := range policy.Predicates { diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index b84f054acf5..b019ac83349 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -64,13 +64,12 @@ func TestCreate(t *testing.T) { stopCh := make(chan struct{}) defer close(stopCh) factory := newConfigFactory(client, stopCh) - if _, err := factory.createFromProvider(schedulerapi.SchedulerDefaultProviderName); err != nil { + if _, err := factory.createFromConfig(); err != nil { t.Error(err) } } -// createAlgorithmSourceFromPolicy creates the schedulerAlgorithmSource from policy string -func createAlgorithmSourceFromPolicy(configData []byte, clientSet clientset.Interface) schedulerapi.SchedulerAlgorithmSource { +func createPolicySource(configData []byte, clientSet clientset.Interface) *schedulerapi.SchedulerPolicySource { configPolicyName := "scheduler-custom-policy-config" policyConfigMap := v1.ConfigMap{ TypeMeta: metav1.TypeMeta{ @@ -82,12 +81,10 @@ func createAlgorithmSourceFromPolicy(configData []byte, clientSet clientset.Inte clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{}) - return schedulerapi.SchedulerAlgorithmSource{ - Policy: &schedulerapi.SchedulerPolicySource{ - ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{ - Namespace: policyConfigMap.Namespace, - Name: policyConfigMap.Name, - }, + return &schedulerapi.SchedulerPolicySource{ + ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{ + Namespace: policyConfigMap.Namespace, + Name: policyConfigMap.Name, }, } } @@ -405,7 +402,7 @@ func TestCreateFromConfig(t *testing.T) { informerFactory, recorderFactory, make(chan struct{}), - WithAlgorithmSource(createAlgorithmSourceFromPolicy(tc.configData, client)), + WithLegacyPolicySource(createPolicySource(tc.configData, client)), WithBuildFrameworkCapturer(func(p schedulerapi.KubeSchedulerProfile) { if p.SchedulerName != v1.DefaultSchedulerName { t.Errorf("unexpected scheduler name: want %q, got %q", v1.DefaultSchedulerName, p.SchedulerName) diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 2e107355080..c85ef95d8f1 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -96,7 +96,7 @@ type Scheduler struct { type schedulerOptions struct { componentConfigVersion string kubeConfig *restclient.Config - schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource + legacyPolicySource *schedulerapi.SchedulerPolicySource percentageOfNodesToScore int32 podInitialBackoffSeconds int64 podMaxBackoffSeconds int64 @@ -143,10 +143,10 @@ func WithParallelism(threads int32) Option { } } -// WithAlgorithmSource sets schedulerAlgorithmSource for Scheduler, the default is a source with DefaultProvider. -func WithAlgorithmSource(source schedulerapi.SchedulerAlgorithmSource) Option { +// WithPolicySource sets legacy policy config file source. +func WithLegacyPolicySource(source *schedulerapi.SchedulerPolicySource) Option { return func(o *schedulerOptions) { - o.schedulerAlgorithmSource = source + o.legacyPolicySource = source } } @@ -201,9 +201,6 @@ var defaultSchedulerOptions = schedulerOptions{ // Profiles' default plugins are set from the algorithm provider. {SchedulerName: v1.DefaultSchedulerName}, }, - schedulerAlgorithmSource: schedulerapi.SchedulerAlgorithmSource{ - Provider: defaultAlgorithmSourceProviderName(), - }, percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()), podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()), @@ -260,25 +257,23 @@ func New(client clientset.Interface, metrics.Register() var sched *Scheduler - source := options.schedulerAlgorithmSource - switch { - case source.Provider != nil: - // Create the config from a named algorithm provider. - sc, err := configurator.createFromProvider(*source.Provider) + if options.legacyPolicySource == nil { + sc, err := configurator.createFromConfig() if err != nil { - return nil, fmt.Errorf("couldn't create scheduler using provider %q: %v", *source.Provider, err) + return nil, fmt.Errorf("couldn't create scheduler: %v", err) } sched = sc - case source.Policy != nil: + + } else { // Create the config from a user specified policy source. policy := &schedulerapi.Policy{} switch { - case source.Policy.File != nil: - if err := initPolicyFromFile(source.Policy.File.Path, policy); err != nil { + case options.legacyPolicySource.File != nil: + if err := initPolicyFromFile(options.legacyPolicySource.File.Path, policy); err != nil { return nil, err } - case source.Policy.ConfigMap != nil: - if err := initPolicyFromConfigMap(client, source.Policy.ConfigMap, policy); err != nil { + case options.legacyPolicySource.ConfigMap != nil: + if err := initPolicyFromConfigMap(client, options.legacyPolicySource.ConfigMap, policy); err != nil { return nil, err } } @@ -286,14 +281,13 @@ func New(client clientset.Interface, // In this case, c.extenders should be nil since we're using a policy (and therefore not componentconfig, // which would have set extenders in the above instantiation of Configurator from CC options) configurator.extenders = policy.Extenders - sc, err := configurator.createFromConfig(*policy) + sc, err := configurator.createFromPolicy(*policy) if err != nil { return nil, fmt.Errorf("couldn't create scheduler from policy: %v", err) } sched = sc - default: - return nil, fmt.Errorf("unsupported algorithm source: %v", source) } + // Additional tweaks to the config produced by the configurator. sched.StopEverything = stopEverything sched.client = client @@ -698,11 +692,6 @@ func (sched *Scheduler) skipPodSchedule(fwk framework.Framework, pod *v1.Pod) bo return isAssumed } -func defaultAlgorithmSourceProviderName() *string { - provider := schedulerapi.SchedulerDefaultProviderName - return &provider -} - // NewInformerFactory creates a SharedInformerFactory and initializes a scheduler specific // in-place podInformer. func NewInformerFactory(cs clientset.Interface, resyncPeriod time.Duration) informers.SharedInformerFactory { diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 4fc2ec58260..fc944eedcf0 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -282,12 +282,10 @@ priorities: [] informerFactory, profile.NewRecorderFactory(eventBroadcaster), nil, - scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{ - Policy: &kubeschedulerconfig.SchedulerPolicySource{ - ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ - Namespace: policyConfigMap.Namespace, - Name: policyConfigMap.Name, - }, + scheduler.WithLegacyPolicySource(&kubeschedulerconfig.SchedulerPolicySource{ + ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ + Namespace: policyConfigMap.Namespace, + Name: policyConfigMap.Name, }, }), scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{ @@ -335,12 +333,10 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) { informerFactory, profile.NewRecorderFactory(eventBroadcaster), nil, - scheduler.WithAlgorithmSource(kubeschedulerconfig.SchedulerAlgorithmSource{ - Policy: &kubeschedulerconfig.SchedulerPolicySource{ - ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ - Namespace: "non-existent-config", - Name: "non-existent-config", - }, + scheduler.WithLegacyPolicySource(&kubeschedulerconfig.SchedulerPolicySource{ + ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{ + Namespace: "non-existent-config", + Name: "non-existent-config", }, }), scheduler.WithProfiles(kubeschedulerconfig.KubeSchedulerProfile{ diff --git a/test/integration/util/util.go b/test/integration/util/util.go index dea63cf6e27..dfbe9b731d9 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -91,7 +91,6 @@ func StartScheduler(clientSet clientset.Interface, kubeConfig *restclient.Config ctx.Done(), scheduler.WithKubeConfig(kubeConfig), scheduler.WithProfiles(cfg.Profiles...), - scheduler.WithAlgorithmSource(cfg.AlgorithmSource), scheduler.WithPercentageOfNodesToScore(cfg.PercentageOfNodesToScore), scheduler.WithPodMaxBackoffSeconds(cfg.PodMaxBackoffSeconds), scheduler.WithPodInitialBackoffSeconds(cfg.PodInitialBackoffSeconds), @@ -403,7 +402,7 @@ func InitTestSchedulerWithOptions( }) if policy != nil { - opts = append(opts, scheduler.WithAlgorithmSource(CreateAlgorithmSourceFromPolicy(policy, testCtx.ClientSet))) + opts = append(opts, scheduler.WithLegacyPolicySource(CreateSchedulerPolicySource(policy, testCtx.ClientSet))) } opts = append(opts, scheduler.WithKubeConfig(testCtx.KubeConfig)) testCtx.Scheduler, err = scheduler.New( @@ -424,8 +423,8 @@ func InitTestSchedulerWithOptions( return testCtx } -// CreateAlgorithmSourceFromPolicy creates the schedulerAlgorithmSource from the policy parameter -func CreateAlgorithmSourceFromPolicy(policy *schedulerapi.Policy, clientSet clientset.Interface) schedulerapi.SchedulerAlgorithmSource { +// CreateSchedulerPolicySource creates a source from the given policy. +func CreateSchedulerPolicySource(policy *schedulerapi.Policy, clientSet clientset.Interface) *schedulerapi.SchedulerPolicySource { // Serialize the Policy object into a ConfigMap later. info, ok := runtime.SerializerInfoForMediaType(scheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON) if !ok { @@ -441,12 +440,10 @@ func CreateAlgorithmSourceFromPolicy(policy *schedulerapi.Policy, clientSet clie policyConfigMap.APIVersion = "v1" clientSet.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), &policyConfigMap, metav1.CreateOptions{}) - return schedulerapi.SchedulerAlgorithmSource{ - Policy: &schedulerapi.SchedulerPolicySource{ - ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{ - Namespace: policyConfigMap.Namespace, - Name: policyConfigMap.Name, - }, + return &schedulerapi.SchedulerPolicySource{ + ConfigMap: &schedulerapi.SchedulerPolicyConfigMapSource{ + Namespace: policyConfigMap.Namespace, + Name: policyConfigMap.Name, }, } }