From 4b26ef22177eb54122e1345dfe2ee7030760725f Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Tue, 7 Jul 2020 17:39:59 -0700 Subject: [PATCH 1/2] Remove DisablePreemption field from SchedulerConfig v1beta1 DisablePreemption field can be removed as it can be deduced from PostFilterPlugins. --- cmd/kube-scheduler/app/server.go | 1 - .../apis/config/scheme/scheme_test.go | 1 - pkg/scheduler/apis/config/types.go | 3 --- pkg/scheduler/apis/config/v1beta1/defaults.go | 5 ----- .../apis/config/v1beta1/defaults_test.go | 5 ----- pkg/scheduler/scheduler.go | 19 ++----------------- .../kube-scheduler/config/v1beta1/types.go | 3 --- test/integration/scheduler/preemption_test.go | 2 +- test/integration/scheduler/util.go | 14 +++++++++++++- 9 files changed, 16 insertions(+), 37 deletions(-) diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index d4161b3cc8b..b7c22674874 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -321,7 +321,6 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions ctx.Done(), scheduler.WithProfiles(cc.ComponentConfig.Profiles...), scheduler.WithAlgorithmSource(cc.ComponentConfig.AlgorithmSource), - scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption), scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore), scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry), scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds), diff --git a/pkg/scheduler/apis/config/scheme/scheme_test.go b/pkg/scheduler/apis/config/scheme/scheme_test.go index 7155d5064e3..1fc41b7869d 100644 --- a/pkg/scheduler/apis/config/scheme/scheme_test.go +++ b/pkg/scheduler/apis/config/scheme/scheme_test.go @@ -475,7 +475,6 @@ clientConnection: contentType: "" kubeconfig: "" qps: 0 -disablePreemption: false enableContentionProfiling: false enableProfiling: false healthzBindAddress: "" diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index b35372b7244..2aaee6a866e 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -77,9 +77,6 @@ type KubeSchedulerConfiguration struct { // TODO: We might wanna make this a substruct like Debugging componentbaseconfig.DebuggingConfiguration componentbaseconfig.DebuggingConfiguration - // DisablePreemption disables the pod preemption feature. - DisablePreemption bool - // PercentageOfNodesToScore is the percentage of all nodes that once found feasible // for running a pod, the scheduler stops its search for more feasible nodes in // the cluster. This helps improve scheduler's performance. Scheduler always tries to find diff --git a/pkg/scheduler/apis/config/v1beta1/defaults.go b/pkg/scheduler/apis/config/v1beta1/defaults.go index 3369e16a3f4..ebf3b0f2353 100644 --- a/pkg/scheduler/apis/config/v1beta1/defaults.go +++ b/pkg/scheduler/apis/config/v1beta1/defaults.go @@ -103,11 +103,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *v1beta1.KubeSchedulerConfigurat } } - if obj.DisablePreemption == nil { - disablePreemption := false - obj.DisablePreemption = &disablePreemption - } - if obj.PercentageOfNodesToScore == nil { percentageOfNodesToScore := int32(config.DefaultPercentageOfNodesToScore) obj.PercentageOfNodesToScore = &percentageOfNodesToScore diff --git a/pkg/scheduler/apis/config/v1beta1/defaults_test.go b/pkg/scheduler/apis/config/v1beta1/defaults_test.go index f9a37960d61..f64175664f7 100644 --- a/pkg/scheduler/apis/config/v1beta1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1beta1/defaults_test.go @@ -65,7 +65,6 @@ func TestSchedulerDefaults(t *testing.T) { Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - DisablePreemption: pointer.BoolPtr(false), PercentageOfNodesToScore: pointer.Int32Ptr(0), PodInitialBackoffSeconds: pointer.Int64Ptr(1), PodMaxBackoffSeconds: pointer.Int64Ptr(10), @@ -106,7 +105,6 @@ func TestSchedulerDefaults(t *testing.T) { Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - DisablePreemption: pointer.BoolPtr(false), PercentageOfNodesToScore: pointer.Int32Ptr(0), PodInitialBackoffSeconds: pointer.Int64Ptr(1), PodMaxBackoffSeconds: pointer.Int64Ptr(10), @@ -162,7 +160,6 @@ func TestSchedulerDefaults(t *testing.T) { Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - DisablePreemption: pointer.BoolPtr(false), PercentageOfNodesToScore: pointer.Int32Ptr(0), PodInitialBackoffSeconds: pointer.Int64Ptr(1), PodMaxBackoffSeconds: pointer.Int64Ptr(10), @@ -212,7 +209,6 @@ func TestSchedulerDefaults(t *testing.T) { Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - DisablePreemption: pointer.BoolPtr(false), PercentageOfNodesToScore: pointer.Int32Ptr(0), PodInitialBackoffSeconds: pointer.Int64Ptr(1), PodMaxBackoffSeconds: pointer.Int64Ptr(10), @@ -248,7 +244,6 @@ func TestSchedulerDefaults(t *testing.T) { Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - DisablePreemption: pointer.BoolPtr(false), PercentageOfNodesToScore: pointer.Int32Ptr(0), PodInitialBackoffSeconds: pointer.Int64Ptr(1), PodMaxBackoffSeconds: pointer.Int64Ptr(10), diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 5d8557f4571..8af21c774a7 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -76,9 +76,6 @@ type Scheduler struct { // Close this to shut down the scheduler. StopEverything <-chan struct{} - // Disable pod preemption or not. - DisablePreemption bool - // SchedulingQueue holds pods to be scheduled SchedulingQueue internalqueue.SchedulingQueue @@ -97,7 +94,6 @@ func (sched *Scheduler) Cache() internalcache.Cache { type schedulerOptions struct { schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource - disablePreemption bool percentageOfNodesToScore int32 podInitialBackoffSeconds int64 podMaxBackoffSeconds int64 @@ -126,13 +122,6 @@ func WithAlgorithmSource(source schedulerapi.SchedulerAlgorithmSource) Option { } } -// WithPreemptionDisabled sets disablePreemption for Scheduler, the default value is false -func WithPreemptionDisabled(disablePreemption bool) Option { - return func(o *schedulerOptions) { - o.disablePreemption = disablePreemption - } -} - // WithPercentageOfNodesToScore sets percentageOfNodesToScore for Scheduler, the default value is 50 func WithPercentageOfNodesToScore(percentageOfNodesToScore int32) Option { return func(o *schedulerOptions) { @@ -187,7 +176,6 @@ var defaultSchedulerOptions = schedulerOptions{ schedulerAlgorithmSource: schedulerapi.SchedulerAlgorithmSource{ Provider: defaultAlgorithmSourceProviderName(), }, - disablePreemption: false, percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()), podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()), @@ -227,7 +215,6 @@ func New(client clientset.Interface, podInformer: podInformer, schedulerCache: schedulerCache, StopEverything: stopEverything, - disablePreemption: options.disablePreemption, percentageOfNodesToScore: options.percentageOfNodesToScore, podInitialBackoffSeconds: options.podInitialBackoffSeconds, podMaxBackoffSeconds: options.podMaxBackoffSeconds, @@ -276,7 +263,6 @@ func New(client clientset.Interface, return nil, fmt.Errorf("unsupported algorithm source: %v", source) } // Additional tweaks to the config produced by the configurator. - sched.DisablePreemption = options.disablePreemption sched.StopEverything = stopEverything sched.client = client sched.scheduledPodsHasSynced = podInformer.Informer().HasSynced @@ -481,9 +467,8 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) { // into the resources that were preempted, but this is harmless. nominatedNode := "" if fitError, ok := err.(*core.FitError); ok { - if sched.DisablePreemption || !prof.HasPostFilterPlugins() { - klog.V(3).Infof("Pod priority feature is not enabled or preemption is disabled by scheduler configuration." + - " No preemption is performed.") + if !prof.HasPostFilterPlugins() { + klog.V(3).Infof("No PostFilter plugins are registered, so no preemption will be performed.") } else { // Run PostFilter plugins to try to make the pod schedulable in a future scheduling cycle. result, status := prof.RunPostFilterPlugins(ctx, state, pod, fitError.FilteredNodesStatuses) diff --git a/staging/src/k8s.io/kube-scheduler/config/v1beta1/types.go b/staging/src/k8s.io/kube-scheduler/config/v1beta1/types.go index 44e5051a0dc..87965c73436 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1beta1/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1beta1/types.go @@ -61,9 +61,6 @@ type KubeSchedulerConfiguration struct { // TODO: We might wanna make this a substruct like Debugging componentbaseconfigv1alpha1.DebuggingConfiguration componentbaseconfigv1alpha1.DebuggingConfiguration `json:",inline"` - // DisablePreemption disables the pod preemption feature. - DisablePreemption *bool `json:"disablePreemption,omitempty"` - // PercentageOfNodesToScore is the percentage of all nodes that once found feasible // for running a pod, the scheduler stops its search for more feasible nodes in // the cluster. This helps improve scheduler's performance. Scheduler always tries to find diff --git a/test/integration/scheduler/preemption_test.go b/test/integration/scheduler/preemption_test.go index 0bbe214bec6..92a4f8db38d 100644 --- a/test/integration/scheduler/preemption_test.go +++ b/test/integration/scheduler/preemption_test.go @@ -148,7 +148,7 @@ func TestPreemption(t *testing.T) { }, } testCtx := testutils.InitTestSchedulerWithOptions(t, - testutils.InitTestMaster(t, "preemptiom", nil), + testutils.InitTestMaster(t, "preemption", nil), false, nil, time.Second, scheduler.WithProfiles(prof), scheduler.WithFrameworkOutOfTreeRegistry(registry)) diff --git a/test/integration/scheduler/util.go b/test/integration/scheduler/util.go index 6c596cda46a..b0fcec47fc2 100644 --- a/test/integration/scheduler/util.go +++ b/test/integration/scheduler/util.go @@ -39,6 +39,8 @@ import ( podutil "k8s.io/kubernetes/pkg/api/v1/pod" "k8s.io/kubernetes/pkg/controller/disruption" "k8s.io/kubernetes/pkg/scheduler" + schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption" st "k8s.io/kubernetes/pkg/scheduler/testing" testutils "k8s.io/kubernetes/test/integration/util" imageutils "k8s.io/kubernetes/test/utils/image" @@ -88,9 +90,19 @@ func initTest(t *testing.T, nsPrefix string, opts ...scheduler.Option) *testutil // initTestDisablePreemption initializes a test environment and creates master and scheduler with default // configuration but with pod preemption disabled. func initTestDisablePreemption(t *testing.T, nsPrefix string) *testutils.TestContext { + prof := schedulerconfig.KubeSchedulerProfile{ + SchedulerName: v1.DefaultSchedulerName, + Plugins: &schedulerconfig.Plugins{ + PostFilter: &schedulerconfig.PluginSet{ + Disabled: []schedulerconfig.Plugin{ + {Name: defaultpreemption.Name}, + }, + }, + }, + } testCtx := testutils.InitTestSchedulerWithOptions( t, testutils.InitTestMaster(t, nsPrefix, nil), true, nil, - time.Second, scheduler.WithPreemptionDisabled(true)) + time.Second, scheduler.WithProfiles(prof)) testutils.SyncInformerFactory(testCtx) go testCtx.Scheduler.Run(testCtx.Ctx) return testCtx From d65a97848e83e21bde6a76feefd385afaea9c1d7 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Tue, 7 Jul 2020 17:41:10 -0700 Subject: [PATCH 2/2] codegen --- .../apis/config/v1beta1/zz_generated.conversion.go | 6 ------ .../kube-scheduler/config/v1beta1/zz_generated.deepcopy.go | 5 ----- test/integration/scheduler/BUILD | 2 ++ 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go index 56d0bdaef42..8845e699296 100644 --- a/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1beta1/zz_generated.conversion.go @@ -305,9 +305,6 @@ func autoConvert_v1beta1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfi if err := v1alpha1.Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { return err } - if err := metav1.Convert_Pointer_bool_To_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil { - return err - } if err := metav1.Convert_Pointer_int32_To_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil { return err } @@ -349,9 +346,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1beta1_KubeSchedulerConfi if err := v1alpha1.Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { return err } - if err := metav1.Convert_bool_To_Pointer_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil { - return err - } if err := metav1.Convert_int32_To_Pointer_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil { return err } diff --git a/staging/src/k8s.io/kube-scheduler/config/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/kube-scheduler/config/v1beta1/zz_generated.deepcopy.go index 0e9d94c081a..f2e89c43e1f 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1beta1/zz_generated.deepcopy.go @@ -100,11 +100,6 @@ func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfigurati **out = **in } in.DebuggingConfiguration.DeepCopyInto(&out.DebuggingConfiguration) - if in.DisablePreemption != nil { - in, out := &in.DisablePreemption, &out.DisablePreemption - *out = new(bool) - **out = **in - } if in.PercentageOfNodesToScore != nil { in, out := &in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore *out = new(int32) diff --git a/test/integration/scheduler/BUILD b/test/integration/scheduler/BUILD index 36430d66bc3..c6b88b2738e 100644 --- a/test/integration/scheduler/BUILD +++ b/test/integration/scheduler/BUILD @@ -85,6 +85,8 @@ go_library( "//pkg/api/v1/pod:go_default_library", "//pkg/controller/disruption:go_default_library", "//pkg/scheduler:go_default_library", + "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/plugins/defaultpreemption:go_default_library", "//pkg/scheduler/testing:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/policy/v1beta1:go_default_library",