diff --git a/cmd/kube-scheduler/app/options/BUILD b/cmd/kube-scheduler/app/options/BUILD index 081e789a512..2c17c3eb288 100644 --- a/cmd/kube-scheduler/app/options/BUILD +++ b/cmd/kube-scheduler/app/options/BUILD @@ -21,6 +21,8 @@ go_library( "//pkg/scheduler/apis/config/v1alpha1:go_default_library", "//pkg/scheduler/apis/config/v1alpha2:go_default_library", "//pkg/scheduler/apis/config/validation:go_default_library", + "//pkg/scheduler/framework/plugins:go_default_library", + "//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/cmd/kube-scheduler/app/options/deprecated.go b/cmd/kube-scheduler/app/options/deprecated.go index 4d7df5c8123..086819ab2cd 100644 --- a/cmd/kube-scheduler/app/options/deprecated.go +++ b/cmd/kube-scheduler/app/options/deprecated.go @@ -20,10 +20,11 @@ import ( "fmt" "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/framework/plugins" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" ) // DeprecatedOptions contains deprecated options and their flags. @@ -31,11 +32,12 @@ import ( type DeprecatedOptions struct { // The fields below here are placeholders for flags that can't be directly // mapped into componentconfig.KubeSchedulerConfiguration. - PolicyConfigFile string - PolicyConfigMapName string - PolicyConfigMapNamespace string - UseLegacyPolicyConfig bool - AlgorithmProvider string + PolicyConfigFile string + PolicyConfigMapName string + PolicyConfigMapNamespace string + UseLegacyPolicyConfig bool + AlgorithmProvider string + HardPodAffinitySymmetricWeight int32 } // AddFlags adds flags for the deprecated options. @@ -61,7 +63,7 @@ func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig fs.StringVar(&cfg.LeaderElection.ResourceNamespace, "lock-object-namespace", cfg.LeaderElection.ResourceNamespace, "DEPRECATED: define the namespace of the lock object. Will be removed in favor of leader-elect-resource-namespace.") fs.StringVar(&cfg.LeaderElection.ResourceName, "lock-object-name", cfg.LeaderElection.ResourceName, "DEPRECATED: define the name of the lock object. Will be removed in favor of leader-elect-resource-name") - fs.Int32Var(&cfg.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", cfg.HardPodAffinitySymmetricWeight, + fs.Int32Var(&o.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", interpodaffinity.DefaultHardPodAffinityWeight, "DEPRECATED: RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule corresponding "+ "to every RequiredDuringScheduling affinity rule. --hard-pod-affinity-symmetric-weight represents the weight of implicit PreferredDuringScheduling affinity rule. Must be in the range 0-100."+ "This option was moved to the policy configuration file") @@ -76,6 +78,11 @@ func (o *DeprecatedOptions) Validate() []error { if o.UseLegacyPolicyConfig && len(o.PolicyConfigFile) == 0 { errs = append(errs, field.Required(field.NewPath("policyConfigFile"), "required when --use-legacy-policy-config is true")) } + + if err := interpodaffinity.ValidateHardPodAffinityWeight(field.NewPath("hardPodAffinitySymmetricWeight"), o.HardPodAffinitySymmetricWeight); err != nil { + errs = append(errs, err) + } + return errs } @@ -113,5 +120,12 @@ func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfig } } + if o.HardPodAffinitySymmetricWeight != interpodaffinity.DefaultHardPodAffinityWeight { + args := interpodaffinity.Args{ + HardPodAffinityWeight: &o.HardPodAffinitySymmetricWeight, + } + cfg.PluginConfig = append(cfg.PluginConfig, plugins.NewPluginConfig(interpodaffinity.Name, args)) + } + return nil } diff --git a/cmd/kube-scheduler/app/options/deprecated_test.go b/cmd/kube-scheduler/app/options/deprecated_test.go index 15f781edfe6..17830535a5c 100644 --- a/cmd/kube-scheduler/app/options/deprecated_test.go +++ b/cmd/kube-scheduler/app/options/deprecated_test.go @@ -26,7 +26,6 @@ func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) { config *DeprecatedOptions }{ "good": { - expectedToFail: false, config: &DeprecatedOptions{ PolicyConfigFile: "/some/file", UseLegacyPolicyConfig: true, @@ -41,6 +40,17 @@ func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) { AlgorithmProvider: "", }, }, + "good affinity weight": { + config: &DeprecatedOptions{ + HardPodAffinitySymmetricWeight: 50, + }, + }, + "bad affinity weight": { + expectedToFail: true, + config: &DeprecatedOptions{ + HardPodAffinitySymmetricWeight: -1, + }, + }, } for name, scenario := range scenarios { diff --git a/cmd/kube-scheduler/app/options/options_test.go b/cmd/kube-scheduler/app/options/options_test.go index 6d91fe8a0bd..de134c38c82 100644 --- a/cmd/kube-scheduler/app/options/options_test.go +++ b/cmd/kube-scheduler/app/options/options_test.go @@ -134,6 +134,18 @@ leaderElection: t.Fatal(err) } + v1alpha1Config := filepath.Join(tmpDir, "kubeconfig_v1alpha1.yaml") + if err := ioutil.WriteFile(v1alpha1Config, []byte(fmt.Sprintf(` +apiVersion: kubescheduler.config.k8s.io/v1alpha1 +kind: KubeSchedulerConfiguration +clientConnection: + kubeconfig: "%s" +leaderElection: + leaderElect: true +hardPodAffinitySymmetricWeight: 3`, configKubeconfig)), os.FileMode(0600)); err != nil { + t.Fatal(err) + } + unknownFieldConfigLenient := filepath.Join(tmpDir, "scheduler_invalid_unknown_field_lenient.yaml") if err := ioutil.WriteFile(unknownFieldConfigLenient, []byte(fmt.Sprintf(` apiVersion: kubescheduler.config.k8s.io/v1alpha1 @@ -307,11 +319,10 @@ plugins: }, expectedUsername: "config", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "0.0.0.0:10251", - MetricsBindAddress: "0.0.0.0:10251", + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, @@ -399,11 +410,10 @@ plugins: }, expectedUsername: "flag", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "", // defaults empty when not running from config file - MetricsBindAddress: "", // defaults empty when not running from config file + SchedulerName: "default-scheduler", + 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{ EnableProfiling: true, EnableContentionProfiling: true, @@ -464,11 +474,10 @@ plugins: }, }, expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "", // defaults empty when not running from config file - MetricsBindAddress: "", // defaults empty when not running from config file + SchedulerName: "default-scheduler", + 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{ EnableProfiling: true, EnableContentionProfiling: true, @@ -504,11 +513,10 @@ plugins: }, expectedUsername: "config", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "0.0.0.0:10251", - MetricsBindAddress: "0.0.0.0:10251", + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, @@ -578,11 +586,10 @@ plugins: }, expectedUsername: "config", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "0.0.0.0:10251", - MetricsBindAddress: "0.0.0.0:10251", + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, @@ -632,21 +639,114 @@ plugins: options: &Options{}, expectedError: "no configuration has been provided", }, + { + name: "Deprecated HardPodAffinitySymmetricWeight", + options: &Options{ + ComponentConfig: func() kubeschedulerconfig.KubeSchedulerConfiguration { + cfg, _ := newDefaultComponentConfig() + cfg.ClientConnection.Kubeconfig = flagKubeconfig + return *cfg + }(), + Deprecated: &DeprecatedOptions{ + HardPodAffinitySymmetricWeight: 5, + }, + }, + expectedUsername: "flag", + expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: true, + EnableContentionProfiling: true, + }, + LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{ + LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{ + LeaderElect: true, + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, + ResourceLock: "endpointsleases", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", + }, + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + Kubeconfig: flagKubeconfig, + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + PercentageOfNodesToScore: defaultPercentageOfNodesToScore, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, + PluginConfig: []kubeschedulerconfig.PluginConfig{ + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":5}`), + }, + }, + }, + }, + }, + { + name: "v1alpha1 config with HardPodAffinitySymmetricWeight", + options: &Options{ + ConfigFile: v1alpha1Config, + }, + expectedUsername: "config", + expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", + DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: true, + EnableContentionProfiling: true, + }, + LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{ + LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{ + LeaderElect: true, + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, + ResourceLock: "endpointsleases", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", + }, + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + Kubeconfig: configKubeconfig, + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + PercentageOfNodesToScore: defaultPercentageOfNodesToScore, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, + PluginConfig: []kubeschedulerconfig.PluginConfig{ + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":3}`), + }, + }, + }, + }, + }, { name: "unknown field lenient (v1alpha1)", options: &Options{ ConfigFile: unknownFieldConfigLenient, }, - // TODO (obitech): Remove this comment and add a new test for v1alpha2, when it's available, as this should fail then. - // expectedError: "found unknown field: foo", - // checkErrFn: runtime.IsStrictDecodingError, expectedUsername: "config", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "0.0.0.0:10251", - MetricsBindAddress: "0.0.0.0:10251", + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, @@ -688,16 +788,12 @@ plugins: options: &Options{ ConfigFile: duplicateFieldConfigLenient, }, - // TODO (obitech): Remove this comment and add a new test for v1alpha2, when it's available, as this should fail then. - // expectedError: `key "leaderElect" already set`, - // checkErrFn: runtime.IsStrictDecodingError, expectedUsername: "config", expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ - SchedulerName: "default-scheduler", - AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, - HardPodAffinitySymmetricWeight: 1, - HealthzBindAddress: "0.0.0.0:10251", - MetricsBindAddress: "0.0.0.0:10251", + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HealthzBindAddress: "0.0.0.0:10251", + MetricsBindAddress: "0.0.0.0:10251", DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: true, EnableContentionProfiling: true, diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index bb5b30e7e4e..5c5f0bf6ddb 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -188,7 +188,6 @@ func Run(ctx context.Context, cc schedulerserverconfig.CompletedConfig, outOfTre ctx.Done(), scheduler.WithName(cc.ComponentConfig.SchedulerName), scheduler.WithAlgorithmSource(cc.ComponentConfig.AlgorithmSource), - scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight), scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption), scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore), scheduler.WithBindTimeoutSeconds(cc.ComponentConfig.BindTimeoutSeconds), diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index 4b6ceab8c2d..de6d7a47908 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -51,10 +51,6 @@ type KubeSchedulerConfiguration struct { SchedulerName string // AlgorithmSource specifies the scheduler algorithm source. AlgorithmSource SchedulerAlgorithmSource - // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule - // corresponding to every RequiredDuringScheduling affinity rule. - // HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range [0-100]. - HardPodAffinitySymmetricWeight int32 // LeaderElection defines the configuration of leader election client. LeaderElection KubeSchedulerLeaderElectionConfiguration diff --git a/pkg/scheduler/apis/config/v1alpha1/BUILD b/pkg/scheduler/apis/config/v1alpha1/BUILD index 6f89f470087..cc1874253c7 100644 --- a/pkg/scheduler/apis/config/v1alpha1/BUILD +++ b/pkg/scheduler/apis/config/v1alpha1/BUILD @@ -17,6 +17,8 @@ go_library( "//pkg/apis/core:go_default_library", "//pkg/master/ports:go_default_library", "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/plugins:go_default_library", + "//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", @@ -38,7 +40,6 @@ go_test( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/component-base/config:go_default_library", "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1alpha1:go_default_library", diff --git a/pkg/scheduler/apis/config/v1alpha1/conversion.go b/pkg/scheduler/apis/config/v1alpha1/conversion.go index a7770f1642b..60f6e4e3047 100644 --- a/pkg/scheduler/apis/config/v1alpha1/conversion.go +++ b/pkg/scheduler/apis/config/v1alpha1/conversion.go @@ -22,9 +22,24 @@ import ( "k8s.io/apimachinery/pkg/conversion" "k8s.io/kube-scheduler/config/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" ) -// Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. +// Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration converts to the internal. +func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error { + if err := autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s); err != nil { + return err + } + if in.HardPodAffinitySymmetricWeight != nil { + args := interpodaffinity.Args{HardPodAffinityWeight: in.HardPodAffinitySymmetricWeight} + plCfg := plugins.NewPluginConfig(interpodaffinity.Name, args) + out.PluginConfig = append(out.PluginConfig, plCfg) + } + return nil +} + +// Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election. func Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha1.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { if err := autoConvert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil { return err @@ -55,7 +70,7 @@ func Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSch return nil } -// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. +// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration handles deprecated parameters for leader election. func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha1.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { if err := autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil { return err diff --git a/pkg/scheduler/apis/config/v1alpha1/conversion_test.go b/pkg/scheduler/apis/config/v1alpha1/conversion_test.go index 5ad4bb1c245..331c6770dc6 100644 --- a/pkg/scheduler/apis/config/v1alpha1/conversion_test.go +++ b/pkg/scheduler/apis/config/v1alpha1/conversion_test.go @@ -21,15 +21,86 @@ import ( "github.com/google/go-cmp/cmp" - conversion "k8s.io/apimachinery/pkg/conversion" + "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" componentbaseconfig "k8s.io/component-base/config" componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" - v1alpha1 "k8s.io/kube-scheduler/config/v1alpha1" - config "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kube-scheduler/config/v1alpha1" + "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/utils/pointer" ) +func TestConvertHardPodAffinitySymmetricWeight(t *testing.T) { + cases := []struct { + name string + cfg v1alpha1.KubeSchedulerConfiguration + want config.KubeSchedulerConfiguration + }{ + { + name: "no weight", + }, + { + name: "custom weight", + cfg: v1alpha1.KubeSchedulerConfiguration{ + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(3), + }, + want: config.KubeSchedulerConfiguration{ + PluginConfig: []config.PluginConfig{ + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":3}`), + }, + }, + }, + }, + }, + { + name: "custom weight and existing PluginConfig", + cfg: v1alpha1.KubeSchedulerConfiguration{ + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(3), + PluginConfig: []v1alpha1.PluginConfig{ + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":5}`), + }, + }, + }, + }, + want: config.KubeSchedulerConfiguration{ + PluginConfig: []config.PluginConfig{ + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":5}`), + }, + }, + { + Name: "InterPodAffinity", + Args: runtime.Unknown{ + Raw: []byte(`{"hardPodAffinityWeight":3}`), + }, + }, + }, + }, + }, + } + scheme := getScheme(t) + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var out config.KubeSchedulerConfiguration + err := scheme.Convert(&tc.cfg, &out, nil) + if err != nil { + t.Fatal(err) + } + if diff := cmp.Diff(tc.want, out); diff != "" { + t.Errorf("unexpected conversion (-want, +got):\n%s", diff) + } + }) + } +} + func TestV1alpha1ToConfigKubeSchedulerLeaderElectionConfiguration(t *testing.T) { configuration := &v1alpha1.KubeSchedulerLeaderElectionConfiguration{ LockObjectName: "name", @@ -384,8 +455,7 @@ func TestConvertBetweenV1Alpha1PluginsAndConfigPlugins(t *testing.T) { } convertedConfigPlugins := config.Plugins{} convertedV1Alpha1Plugins := v1alpha1.Plugins{} - scheme := runtime.NewScheme() - utilruntime.Must(AddToScheme(scheme)) + scheme := getScheme(t) if err := scheme.Convert(&v1alpha1Plugins, &convertedConfigPlugins, nil); err != nil { t.Fatal(err) } @@ -399,3 +469,11 @@ func TestConvertBetweenV1Alpha1PluginsAndConfigPlugins(t *testing.T) { t.Errorf("unexpected plugins diff (-want, +got): %s", diff) } } + +func getScheme(t *testing.T) *runtime.Scheme { + scheme := runtime.NewScheme() + if err := AddToScheme(scheme); err != nil { + t.Fatal(err) + } + return scheme +} diff --git a/pkg/scheduler/apis/config/v1alpha1/defaults.go b/pkg/scheduler/apis/config/v1alpha1/defaults.go index 83e294f2b7c..b298e8d9ac8 100644 --- a/pkg/scheduler/apis/config/v1alpha1/defaults.go +++ b/pkg/scheduler/apis/config/v1alpha1/defaults.go @@ -41,11 +41,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.Kub obj.SchedulerName = &val } - if obj.HardPodAffinitySymmetricWeight == nil { - val := api.DefaultHardPodAffinitySymmetricWeight - obj.HardPodAffinitySymmetricWeight = &val - } - if obj.AlgorithmSource.Policy == nil && (obj.AlgorithmSource.Provider == nil || len(*obj.AlgorithmSource.Provider) == 0) { val := kubeschedulerconfigv1alpha1.SchedulerDefaultProviderName diff --git a/pkg/scheduler/apis/config/v1alpha1/defaults_test.go b/pkg/scheduler/apis/config/v1alpha1/defaults_test.go index 724bd3def33..bf8c00e3eff 100644 --- a/pkg/scheduler/apis/config/v1alpha1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1alpha1/defaults_test.go @@ -17,10 +17,10 @@ limitations under the License. package v1alpha1 import ( - "reflect" "testing" "time" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" componentbaseconfig "k8s.io/component-base/config/v1alpha1" kubeschedulerconfigv1alpha1 "k8s.io/kube-scheduler/config/v1alpha1" @@ -37,10 +37,50 @@ func TestSchedulerDefaults(t *testing.T) { { name: "empty config", config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{}, + expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"), + DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: &enable, + EnableContentionProfiling: &enable, + }, + LeaderElection: kubeschedulerconfigv1alpha1.KubeSchedulerLeaderElectionConfiguration{ + LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{ + LeaderElect: pointer.BoolPtr(true), + LeaseDuration: metav1.Duration{Duration: 15 * time.Second}, + RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, + RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, + ResourceLock: "endpointsleases", + ResourceNamespace: "", + ResourceName: "", + }, + LockObjectName: "kube-scheduler", + LockObjectNamespace: "kube-system", + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + DisablePreemption: pointer.BoolPtr(false), + PercentageOfNodesToScore: pointer.Int32Ptr(0), + BindTimeoutSeconds: pointer.Int64Ptr(600), + PodInitialBackoffSeconds: pointer.Int64Ptr(1), + PodMaxBackoffSeconds: pointer.Int64Ptr(10), + Plugins: nil, + }, + }, + { + name: "custom hard pod affinity", + config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(42), + }, expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ SchedulerName: pointer.StringPtr("default-scheduler"), AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(42), HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"), MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ @@ -80,11 +120,10 @@ func TestSchedulerDefaults(t *testing.T) { HealthzBindAddress: pointer.StringPtr("1.2.3.4"), }, expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ - SchedulerName: pointer.StringPtr("default-scheduler"), - AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), - HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"), - MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"), + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"), + MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: &enable, EnableContentionProfiling: &enable, @@ -122,11 +161,10 @@ func TestSchedulerDefaults(t *testing.T) { HealthzBindAddress: pointer.StringPtr(":12345"), }, expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ - SchedulerName: pointer.StringPtr("default-scheduler"), - AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), - HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"), - MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"), + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: &enable, EnableContentionProfiling: &enable, @@ -161,8 +199,8 @@ func TestSchedulerDefaults(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { SetDefaults_KubeSchedulerConfiguration(tc.config) - if !reflect.DeepEqual(tc.expected, tc.config) { - t.Errorf("Expected:\n%#v\n\nGot:\n%#v", tc.expected, tc.config) + if diff := cmp.Diff(tc.expected, tc.config); diff != "" { + t.Errorf("wrong defaults set (-want, +got):\n%s", diff) } }) } diff --git a/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go index 30098fda218..4caef540c94 100644 --- a/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go @@ -38,11 +38,6 @@ func init() { // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { - if err := s.AddGeneratedConversionFunc((*v1alpha1.KubeSchedulerConfiguration)(nil), (*config.KubeSchedulerConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(a.(*v1alpha1.KubeSchedulerConfiguration), b.(*config.KubeSchedulerConfiguration), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*config.KubeSchedulerConfiguration)(nil), (*v1alpha1.KubeSchedulerConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(a.(*config.KubeSchedulerConfiguration), b.(*v1alpha1.KubeSchedulerConfiguration), scope) }); err != nil { @@ -128,6 +123,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1alpha1.KubeSchedulerConfiguration)(nil), (*config.KubeSchedulerConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(a.(*v1alpha1.KubeSchedulerConfiguration), b.(*config.KubeSchedulerConfiguration), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1alpha1.KubeSchedulerLeaderElectionConfiguration)(nil), (*config.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(a.(*v1alpha1.KubeSchedulerLeaderElectionConfiguration), b.(*config.KubeSchedulerLeaderElectionConfiguration), scope) }); err != nil { @@ -148,9 +148,7 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConf if err := Convert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - if err := v1.Convert_Pointer_int32_To_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { - return err - } + // WARNING: in.HardPodAffinitySymmetricWeight requires manual conversion: does not exist in peer-type if err := Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } @@ -194,11 +192,6 @@ func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConf return nil } -// Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration is an autogenerated conversion function. -func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error { - return autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in, out, s) -} - func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in *config.KubeSchedulerConfiguration, out *v1alpha1.KubeSchedulerConfiguration, s conversion.Scope) error { if err := v1.Convert_string_To_Pointer_string(&in.SchedulerName, &out.SchedulerName, s); err != nil { return err @@ -206,9 +199,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConf if err := Convert_config_SchedulerAlgorithmSource_To_v1alpha1_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - if err := v1.Convert_int32_To_Pointer_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { - return err - } if err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } diff --git a/pkg/scheduler/apis/config/v1alpha2/defaults.go b/pkg/scheduler/apis/config/v1alpha2/defaults.go index a5c371d0bd9..1b1479cfaf4 100644 --- a/pkg/scheduler/apis/config/v1alpha2/defaults.go +++ b/pkg/scheduler/apis/config/v1alpha2/defaults.go @@ -41,11 +41,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *v1alpha2.KubeSchedulerConfigura obj.SchedulerName = &val } - if obj.HardPodAffinitySymmetricWeight == nil { - val := api.DefaultHardPodAffinitySymmetricWeight - obj.HardPodAffinitySymmetricWeight = &val - } - if obj.AlgorithmSource.Policy == nil && (obj.AlgorithmSource.Provider == nil || len(*obj.AlgorithmSource.Provider) == 0) { val := v1alpha2.SchedulerDefaultProviderName diff --git a/pkg/scheduler/apis/config/v1alpha2/defaults_test.go b/pkg/scheduler/apis/config/v1alpha2/defaults_test.go index 6bbdccc7df5..ea4bd68cd28 100644 --- a/pkg/scheduler/apis/config/v1alpha2/defaults_test.go +++ b/pkg/scheduler/apis/config/v1alpha2/defaults_test.go @@ -38,11 +38,10 @@ func TestSchedulerDefaults(t *testing.T) { name: "empty config", config: &v1alpha2.KubeSchedulerConfiguration{}, expected: &v1alpha2.KubeSchedulerConfiguration{ - SchedulerName: pointer.StringPtr("default-scheduler"), - AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), - HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"), - MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"), + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: &enable, EnableContentionProfiling: &enable, @@ -78,11 +77,10 @@ func TestSchedulerDefaults(t *testing.T) { HealthzBindAddress: pointer.StringPtr("1.2.3.4"), }, expected: &v1alpha2.KubeSchedulerConfiguration{ - SchedulerName: pointer.StringPtr("default-scheduler"), - AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), - HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"), - MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"), + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"), + MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: &enable, EnableContentionProfiling: &enable, @@ -118,11 +116,10 @@ func TestSchedulerDefaults(t *testing.T) { HealthzBindAddress: pointer.StringPtr(":12345"), }, expected: &v1alpha2.KubeSchedulerConfiguration{ - SchedulerName: pointer.StringPtr("default-scheduler"), - AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, - HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), - HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"), - MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"), + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"), DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{ EnableProfiling: &enable, EnableContentionProfiling: &enable, diff --git a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go index c1124e53ee8..8706d563eed 100644 --- a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go @@ -148,9 +148,6 @@ func autoConvert_v1alpha2_KubeSchedulerConfiguration_To_config_KubeSchedulerConf if err := Convert_v1alpha2_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - if err := v1.Convert_Pointer_int32_To_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { - return err - } if err := Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } @@ -206,9 +203,6 @@ func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha2_KubeSchedulerConf if err := Convert_config_SchedulerAlgorithmSource_To_v1alpha2_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - if err := v1.Convert_int32_To_Pointer_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { - return err - } if err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } diff --git a/pkg/scheduler/apis/config/validation/validation.go b/pkg/scheduler/apis/config/validation/validation.go index 3e82149e0d3..0f90013600f 100644 --- a/pkg/scheduler/apis/config/validation/validation.go +++ b/pkg/scheduler/apis/config/validation/validation.go @@ -44,9 +44,6 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) f for _, msg := range validation.IsValidSocketAddr(cc.MetricsBindAddress) { allErrs = append(allErrs, field.Invalid(field.NewPath("metricsBindAddress"), cc.MetricsBindAddress, msg)) } - if cc.HardPodAffinitySymmetricWeight < 0 || cc.HardPodAffinitySymmetricWeight > 100 { - allErrs = append(allErrs, field.Invalid(field.NewPath("hardPodAffinitySymmetricWeight"), cc.HardPodAffinitySymmetricWeight, "not in valid range [0-100]")) - } if cc.PercentageOfNodesToScore < 0 || cc.PercentageOfNodesToScore > 100 { allErrs = append(allErrs, field.Invalid(field.NewPath("percentageOfNodesToScore"), cc.PercentageOfNodesToScore, "not in valid range [0-100]")) diff --git a/pkg/scheduler/apis/config/validation/validation_test.go b/pkg/scheduler/apis/config/validation/validation_test.go index 88403a0f072..006aeb3f14a 100644 --- a/pkg/scheduler/apis/config/validation/validation_test.go +++ b/pkg/scheduler/apis/config/validation/validation_test.go @@ -32,10 +32,9 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { podInitialBackoffSeconds := int64(1) podMaxBackoffSeconds := int64(1) validConfig := &config.KubeSchedulerConfiguration{ - SchedulerName: "me", - HealthzBindAddress: "0.0.0.0:10254", - MetricsBindAddress: "0.0.0.0:10254", - HardPodAffinitySymmetricWeight: 80, + SchedulerName: "me", + HealthzBindAddress: "0.0.0.0:10254", + MetricsBindAddress: "0.0.0.0:10254", ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ AcceptContentTypes: "application/json", ContentType: "application/json", @@ -67,12 +66,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { PercentageOfNodesToScore: 35, } - HardPodAffinitySymmetricWeightGt100 := validConfig.DeepCopy() - HardPodAffinitySymmetricWeightGt100.HardPodAffinitySymmetricWeight = 120 - - HardPodAffinitySymmetricWeightLt0 := validConfig.DeepCopy() - HardPodAffinitySymmetricWeightLt0.HardPodAffinitySymmetricWeight = -1 - resourceNameNotSet := validConfig.DeepCopy() resourceNameNotSet.LeaderElection.ResourceName = "" @@ -130,14 +123,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { expectedToFail: true, config: metricsBindAddrHostInvalid, }, - "bad-hard-pod-affinity-symmetric-weight-lt-0": { - expectedToFail: true, - config: HardPodAffinitySymmetricWeightGt100, - }, - "bad-hard-pod-affinity-symmetric-weight-gt-100": { - expectedToFail: true, - config: HardPodAffinitySymmetricWeightLt0, - }, "bad-percentage-of-nodes-to-score": { expectedToFail: true, config: percentageOfNodesToScore101, diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 8f53e152a59..c7fdb7c2fc1 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -79,11 +78,6 @@ type Configurator struct { schedulerCache internalcache.Cache - // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule - // corresponding to every RequiredDuringScheduling affinity rule. - // HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range [0-100]. - hardPodAffinitySymmetricWeight int32 - // Handles volume binding decisions volumeBinder *volumebinder.VolumeBinder @@ -181,10 +175,6 @@ func (c *Configurator) createFromProvider(providerName string) (*Scheduler, erro defaultPlugins.Apply(c.plugins) c.plugins = defaultPlugins - pluginConfig := []schedulerapi.PluginConfig{c.interPodAffinityPluginConfig()} - pluginConfig = append(pluginConfig, c.pluginConfig...) - c.pluginConfig = pluginConfig - return c.create([]core.SchedulerExtender{}) } @@ -253,10 +243,13 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, // place ignorable extenders to the tail of extenders extenders = append(extenders, ignorableExtenders...) } - // Providing HardPodAffinitySymmetricWeight in the policy config is the new and preferred way of providing the value. - // Give it higher precedence than scheduler CLI configuration when it is provided. + // HardPodAffinitySymmetricWeight in the policy config takes precedence over + // CLI configuration. if policy.HardPodAffinitySymmetricWeight != 0 { - c.hardPodAffinitySymmetricWeight = policy.HardPodAffinitySymmetricWeight + v := policy.HardPodAffinitySymmetricWeight + args.InterPodAffinityArgs = &interpodaffinity.Args{ + HardPodAffinityWeight: &v, + } } // When AlwaysCheckAllPredicates is set to true, scheduler checks all the configured @@ -267,10 +260,6 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, klog.V(2).Infof("Creating scheduler with fit predicates '%v' and priority functions '%v'", predicateKeys, priorityKeys) - args.InterPodAffinityArgs = &interpodaffinity.Args{ - HardPodAffinityWeight: &c.hardPodAffinitySymmetricWeight, - } - pluginsForPredicates, pluginConfigForPredicates, err := getPredicateConfigs(predicateKeys, lr, args) if err != nil { return nil, err @@ -307,15 +296,6 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, return c.create(extenders) } -func (c *Configurator) interPodAffinityPluginConfig() schedulerapi.PluginConfig { - return schedulerapi.PluginConfig{ - Name: interpodaffinity.Name, - Args: runtime.Unknown{ - Raw: []byte(fmt.Sprintf(`{"hardPodAffinityWeight":%d}`, c.hardPodAffinitySymmetricWeight)), - }, - } -} - // getPriorityConfigs returns priorities configuration: ones that will run as priorities and ones that will run // as framework plugins. Specifically, a priority will run as a framework plugin if a plugin config producer was // registered for that priority. diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index 7910fb665e7..568882d5b20 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -44,7 +44,6 @@ 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/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" @@ -65,7 +64,7 @@ func TestCreate(t *testing.T) { client := fake.NewSimpleClientset() stopCh := make(chan struct{}) defer close(stopCh) - factory := newConfigFactory(client, v1.DefaultHardPodAffinitySymmetricWeight, stopCh) + factory := newConfigFactory(client, stopCh) factory.createFromProvider(schedulerapi.SchedulerDefaultProviderName) } @@ -78,7 +77,7 @@ func TestCreateFromConfig(t *testing.T) { client := fake.NewSimpleClientset() stopCh := make(chan struct{}) defer close(stopCh) - factory := newConfigFactory(client, v1.DefaultHardPodAffinitySymmetricWeight, stopCh) + factory := newConfigFactory(client, stopCh) configData = []byte(`{ "kind" : "Policy", @@ -107,10 +106,6 @@ func TestCreateFromConfig(t *testing.T) { if err != nil { t.Fatalf("createFromConfig failed: %v", err) } - hpa := factory.hardPodAffinitySymmetricWeight - if hpa != v1.DefaultHardPodAffinitySymmetricWeight { - t.Errorf("Wrong hardPodAffinitySymmetricWeight, ecpected: %d, got: %d", v1.DefaultHardPodAffinitySymmetricWeight, hpa) - } queueSortPls := sched.Framework.ListPlugins()["QueueSortPlugin"] wantQueuePls := []schedulerapi.Plugin{{Name: queuesort.Name}} if diff := cmp.Diff(wantQueuePls, queueSortPls); diff != "" { @@ -128,6 +123,7 @@ func TestCreateFromConfig(t *testing.T) { // Verify that service affinity custom predicate/priority is converted to framework plugin. wantArgs = `{"Name":"ServiceAffinity","Args":{"labels":["zone","foo"],"antiAffinityLabelsPreference":["rack","zone"]}}` verifyPluginConvertion(t, serviceaffinity.Name, []string{"FilterPlugin", "ScorePlugin"}, sched, factory, 6, wantArgs) + // TODO(#87703): Verify all plugin configs. } func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, sched *Scheduler, configurator *Configurator, wantWeight int32, wantArgs string) { @@ -178,7 +174,7 @@ func TestCreateFromConfigWithHardPodAffinitySymmetricWeight(t *testing.T) { client := fake.NewSimpleClientset() stopCh := make(chan struct{}) defer close(stopCh) - factory := newConfigFactory(client, v1.DefaultHardPodAffinitySymmetricWeight, stopCh) + factory := newConfigFactory(client, stopCh) configData = []byte(`{ "kind" : "Policy", @@ -225,7 +221,7 @@ func TestCreateFromEmptyConfig(t *testing.T) { client := fake.NewSimpleClientset() stopCh := make(chan struct{}) defer close(stopCh) - factory := newConfigFactory(client, v1.DefaultHardPodAffinitySymmetricWeight, stopCh) + factory := newConfigFactory(client, stopCh) configData = []byte(`{}`) if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), configData, &policy); err != nil { @@ -233,18 +229,8 @@ func TestCreateFromEmptyConfig(t *testing.T) { } factory.createFromConfig(policy) - wantConfig := []schedulerapi.PluginConfig{ - { - Name: noderesources.FitName, - Args: runtime.Unknown{Raw: []byte(`null`)}, - }, - { - Name: interpodaffinity.Name, - Args: runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":1}`)}, - }, - } - if diff := cmp.Diff(wantConfig, factory.pluginConfig); diff != "" { - t.Errorf("wrong plugin config (-want, +got): %s", diff) + if len(factory.pluginConfig) != 0 { + t.Errorf("got plugin config %s, want none", factory.pluginConfig) } } @@ -255,7 +241,7 @@ func TestCreateFromConfigWithUnspecifiedPredicatesOrPriorities(t *testing.T) { client := fake.NewSimpleClientset() stopCh := make(chan struct{}) defer close(stopCh) - factory := newConfigFactory(client, v1.DefaultHardPodAffinitySymmetricWeight, stopCh) + factory := newConfigFactory(client, stopCh) configData := []byte(`{ "kind" : "Policy", @@ -406,32 +392,30 @@ func testClientGetPodRequest(client *fake.Clientset, t *testing.T, podNs string, } func newConfigFactoryWithFrameworkRegistry( - client clientset.Interface, hardPodAffinitySymmetricWeight int32, stopCh <-chan struct{}, + client clientset.Interface, stopCh <-chan struct{}, registry framework.Registry) *Configurator { informerFactory := informers.NewSharedInformerFactory(client, 0) snapshot := internalcache.NewEmptySnapshot() return &Configurator{ - client: client, - informerFactory: informerFactory, - podInformer: informerFactory.Core().V1().Pods(), - hardPodAffinitySymmetricWeight: hardPodAffinitySymmetricWeight, - disablePreemption: disablePodPreemption, - percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, - bindTimeoutSeconds: bindTimeoutSeconds, - podInitialBackoffSeconds: podInitialBackoffDurationSeconds, - podMaxBackoffSeconds: podMaxBackoffDurationSeconds, - StopEverything: stopCh, - enableNonPreempting: utilfeature.DefaultFeatureGate.Enabled(kubefeatures.NonPreemptingPriority), - registry: registry, - plugins: nil, - pluginConfig: []schedulerapi.PluginConfig{}, - nodeInfoSnapshot: snapshot, + client: client, + informerFactory: informerFactory, + podInformer: informerFactory.Core().V1().Pods(), + disablePreemption: disablePodPreemption, + percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, + bindTimeoutSeconds: bindTimeoutSeconds, + podInitialBackoffSeconds: podInitialBackoffDurationSeconds, + podMaxBackoffSeconds: podMaxBackoffDurationSeconds, + StopEverything: stopCh, + enableNonPreempting: utilfeature.DefaultFeatureGate.Enabled(kubefeatures.NonPreemptingPriority), + registry: registry, + plugins: nil, + pluginConfig: []schedulerapi.PluginConfig{}, + nodeInfoSnapshot: snapshot, } } -func newConfigFactory( - client clientset.Interface, hardPodAffinitySymmetricWeight int32, stopCh <-chan struct{}) *Configurator { - return newConfigFactoryWithFrameworkRegistry(client, hardPodAffinitySymmetricWeight, stopCh, +func newConfigFactory(client clientset.Interface, stopCh <-chan struct{}) *Configurator { + return newConfigFactoryWithFrameworkRegistry(client, stopCh, frameworkplugins.NewInTreeRegistry()) } diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD index 539d2d9bea0..246596796e9 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD +++ b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD @@ -19,6 +19,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", "//staging/src/k8s.io/client-go/util/workqueue:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go index d31729e2f23..1c9f5c34087 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go @@ -21,6 +21,7 @@ import ( "sync" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers" ) @@ -29,13 +30,18 @@ const ( // Name is the name of the plugin used in the plugin registry and configurations. Name = "InterPodAffinity" - defaultHardPodAffinityWeight int32 = 1 - minHardPodAffinityWeight int32 = 0 - maxHardPodAffinityWeight int32 = 100 + // DefaultHardPodAffinityWeight is the default HardPodAffinityWeight. + DefaultHardPodAffinityWeight int32 = 1 + // MinHardPodAffinityWeight is the minimum HardPodAffinityWeight. + MinHardPodAffinityWeight int32 = 0 + // MaxHardPodAffinityWeight is the maximum HardPodAffinityWeight. + MaxHardPodAffinityWeight int32 = 100 ) // Args holds the args that are used to configure the plugin. type Args struct { + // HardPodAffinityWeight is the scoring weight for existing pods with a + // matching hard affinity to the incoming pod. HardPodAffinityWeight *int32 `json:"hardPodAffinityWeight,omitempty"` } @@ -70,7 +76,7 @@ func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin } pl := &InterPodAffinity{ sharedLister: h.SnapshotSharedLister(), - hardPodAffinityWeight: defaultHardPodAffinityWeight, + hardPodAffinityWeight: DefaultHardPodAffinityWeight, } if args.HardPodAffinityWeight != nil { pl.hardPodAffinityWeight = *args.HardPodAffinityWeight @@ -82,10 +88,14 @@ func validateArgs(args *Args) error { if args.HardPodAffinityWeight == nil { return nil } + return ValidateHardPodAffinityWeight(field.NewPath("hardPodAffinityWeight"), *args.HardPodAffinityWeight) +} - weight := *args.HardPodAffinityWeight - if weight < minHardPodAffinityWeight || weight > maxHardPodAffinityWeight { - return fmt.Errorf("invalid args.hardPodAffinityWeight: %d, must be in the range %d-%d", weight, minHardPodAffinityWeight, maxHardPodAffinityWeight) +// ValidateHardPodAffinityWeight validates that weight is within allowed range. +func ValidateHardPodAffinityWeight(path *field.Path, w int32) error { + if w < MinHardPodAffinityWeight || w > MaxHardPodAffinityWeight { + msg := fmt.Sprintf("not in valid range [%d-%d]", MinHardPodAffinityWeight, MaxHardPodAffinityWeight) + return field.Invalid(path, w, msg) } return nil } diff --git a/pkg/scheduler/framework/plugins/legacy_registry.go b/pkg/scheduler/framework/plugins/legacy_registry.go index 84f94bf1efd..25f0750a195 100644 --- a/pkg/scheduler/framework/plugins/legacy_registry.go +++ b/pkg/scheduler/framework/plugins/legacy_registry.go @@ -18,7 +18,6 @@ package plugins import ( "encoding/json" - "fmt" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -226,7 +225,9 @@ func NewLegacyRegistry() *LegacyRegistry { // GeneralPredicate is a combination of predicates. plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil) plugins.PreFilter = appendToPluginSet(plugins.PreFilter, noderesources.FitName, nil) - pluginConfig = append(pluginConfig, makePluginConfig(noderesources.FitName, args.NodeResourcesFitArgs)) + if args.NodeResourcesFitArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.FitName, args.NodeResourcesFitArgs)) + } plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil) plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil) plugins.PreFilter = appendToPluginSet(plugins.PreFilter, nodeports.Name, nil) @@ -242,7 +243,9 @@ func NewLegacyRegistry() *LegacyRegistry { func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil) plugins.PreFilter = appendToPluginSet(plugins.PreFilter, noderesources.FitName, nil) - pluginConfig = append(pluginConfig, makePluginConfig(noderesources.FitName, args.NodeResourcesFitArgs)) + if args.NodeResourcesFitArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.FitName, args.NodeResourcesFitArgs)) + } return }) registry.registerPredicateConfigProducer(HostNamePred, @@ -315,13 +318,17 @@ func NewLegacyRegistry() *LegacyRegistry { registry.registerPredicateConfigProducer(CheckNodeLabelPresencePred, func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { plugins.Filter = appendToPluginSet(plugins.Filter, nodelabel.Name, nil) - pluginConfig = append(pluginConfig, makePluginConfig(nodelabel.Name, args.NodeLabelArgs)) + if args.NodeLabelArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(nodelabel.Name, args.NodeLabelArgs)) + } return }) registry.registerPredicateConfigProducer(CheckServiceAffinityPred, func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { plugins.Filter = appendToPluginSet(plugins.Filter, serviceaffinity.Name, nil) - pluginConfig = append(pluginConfig, makePluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs)) + if args.ServiceAffinityArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs)) + } plugins.PreFilter = appendToPluginSet(plugins.PreFilter, serviceaffinity.Name, nil) return }) @@ -353,7 +360,9 @@ func NewLegacyRegistry() *LegacyRegistry { func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { plugins.PreScore = appendToPluginSet(plugins.PreScore, interpodaffinity.Name, nil) plugins.Score = appendToPluginSet(plugins.Score, interpodaffinity.Name, &args.Weight) - pluginConfig = append(pluginConfig, makePluginConfig(interpodaffinity.Name, args.InterPodAffinityArgs)) + if args.InterPodAffinityArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(interpodaffinity.Name, args.InterPodAffinityArgs)) + } return }) registry.registerPriorityConfigProducer(NodePreferAvoidPodsPriority, @@ -379,7 +388,9 @@ func NewLegacyRegistry() *LegacyRegistry { registry.registerPriorityConfigProducer(noderesources.RequestedToCapacityRatioName, func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { plugins.Score = appendToPluginSet(plugins.Score, noderesources.RequestedToCapacityRatioName, &args.Weight) - pluginConfig = append(pluginConfig, makePluginConfig(noderesources.RequestedToCapacityRatioName, args.RequestedToCapacityRatioArgs)) + if args.RequestedToCapacityRatioArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.RequestedToCapacityRatioName, args.RequestedToCapacityRatioArgs)) + } return }) @@ -390,7 +401,9 @@ func NewLegacyRegistry() *LegacyRegistry { // priorities specified in Policy have the same weight). weight := args.Weight * int32(len(args.NodeLabelArgs.PresentLabelsPreference)+len(args.NodeLabelArgs.AbsentLabelsPreference)) plugins.Score = appendToPluginSet(plugins.Score, nodelabel.Name, &weight) - pluginConfig = append(pluginConfig, makePluginConfig(nodelabel.Name, args.NodeLabelArgs)) + if args.NodeLabelArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(nodelabel.Name, args.NodeLabelArgs)) + } return }) registry.registerPriorityConfigProducer(serviceaffinity.Name, @@ -400,7 +413,9 @@ func NewLegacyRegistry() *LegacyRegistry { // priorities specified in Policy have the same weight). weight := args.Weight * int32(len(args.ServiceAffinityArgs.AntiAffinityLabelsPreference)) plugins.Score = appendToPluginSet(plugins.Score, serviceaffinity.Name, &weight) - pluginConfig = append(pluginConfig, makePluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs)) + if args.ServiceAffinityArgs != nil { + pluginConfig = append(pluginConfig, NewPluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs)) + } return }) @@ -471,17 +486,17 @@ func appendToPluginSet(set *config.PluginSet, name string, weight *int32) *confi return set } -func makePluginConfig(pluginName string, args interface{}) config.PluginConfig { +// NewPluginConfig builds a PluginConfig with the struct of args marshaled. +// It panics if it fails to marshal. +func NewPluginConfig(pluginName string, args interface{}) config.PluginConfig { encoding, err := json.Marshal(args) if err != nil { - klog.Fatal(fmt.Errorf("failed to marshal %+v: %v", args, err)) - return config.PluginConfig{} + klog.Fatalf("failed to marshal %+v: %v", args, err) } - config := config.PluginConfig{ + return config.PluginConfig{ Name: pluginName, Args: runtime.Unknown{Raw: encoding}, } - return config } // ProcessPredicatePolicy given a PredicatePolicy, return the plugin name implementing the predicate and update diff --git a/pkg/scheduler/framework/v1alpha1/BUILD b/pkg/scheduler/framework/v1alpha1/BUILD index 630b522ac32..a3cdc1cda7c 100644 --- a/pkg/scheduler/framework/v1alpha1/BUILD +++ b/pkg/scheduler/framework/v1alpha1/BUILD @@ -58,7 +58,6 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/scheduler/apis/config:go_default_library", - "//pkg/scheduler/apis/config/scheme:go_default_library", "//pkg/scheduler/metrics:go_default_library", "//pkg/scheduler/nodeinfo:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/v1alpha1/registry_test.go b/pkg/scheduler/framework/v1alpha1/registry_test.go index bf73ed87369..4bda03221d8 100644 --- a/pkg/scheduler/framework/v1alpha1/registry_test.go +++ b/pkg/scheduler/framework/v1alpha1/registry_test.go @@ -21,59 +21,35 @@ import ( "testing" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/kubernetes/pkg/scheduler/apis/config" - "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" ) func TestDecodeInto(t *testing.T) { type PluginFooConfig struct { - FooTest string `json:"foo_test,omitempty"` + FooTest string `json:"fooTest,omitempty"` } tests := []struct { - name string - schedulerConfig string - expected PluginFooConfig + name string + args *runtime.Unknown + expected PluginFooConfig }{ { name: "test decode for JSON config", - schedulerConfig: `{ - "kind": "KubeSchedulerConfiguration", - "apiVersion": "kubescheduler.config.k8s.io/v1alpha1", - "plugins": { - "permit": { - "enabled": [ - { - "name": "foo" - } - ] - } - }, - "pluginConfig": [ - { - "name": "foo", - "args": { - "foo_test": "test decode" - } - } - ] - }`, + args: &runtime.Unknown{ + ContentType: runtime.ContentTypeJSON, + Raw: []byte(`{ + "fooTest": "test decode" + }`), + }, expected: PluginFooConfig{ FooTest: "test decode", }, }, { name: "test decode for YAML config", - schedulerConfig: ` -apiVersion: kubescheduler.config.k8s.io/v1alpha1 -kind: KubeSchedulerConfiguration -plugins: - permit: - enabled: - - name: foo -pluginConfig: - - name: foo - args: - foo_test: "test decode"`, + args: &runtime.Unknown{ + ContentType: runtime.ContentTypeYAML, + Raw: []byte(`fooTest: "test decode"`), + }, expected: PluginFooConfig{ FooTest: "test decode", }, @@ -82,14 +58,9 @@ pluginConfig: for _, test := range tests { t.Run(test.name, func(t *testing.T) { - schedulerConf, err := loadConfig([]byte(test.schedulerConfig)) - if err != nil { - t.Errorf("loadConfig(): failed to load scheduler config: %v", err) - } var pluginFooConf PluginFooConfig - if err := DecodeInto(&schedulerConf.PluginConfig[0].Args, &pluginFooConf); err != nil { - t.Errorf("DecodeInto(): failed to decode args %+v: %v", - schedulerConf.PluginConfig[0].Args, err) + if err := DecodeInto(test.args, &pluginFooConf); err != nil { + t.Errorf("DecodeInto(): failed to decode args %+v: %v", test.args, err) } if !reflect.DeepEqual(test.expected, pluginFooConf) { t.Errorf("DecodeInto(): failed to decode plugin config, expected: %+v, got: %+v", @@ -99,15 +70,6 @@ pluginConfig: } } -func loadConfig(data []byte) (*config.KubeSchedulerConfiguration, error) { - configObj := &config.KubeSchedulerConfiguration{} - if err := runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), data, configObj); err != nil { - return nil, err - } - - return configObj, nil -} - // isRegistryEqual compares two registries for equality. This function is used in place of // reflect.DeepEqual() and cmp() as they don't compare function values. func isRegistryEqual(registryX, registryY Registry) bool { diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 0d18894f4a1..535355426cd 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -126,14 +126,13 @@ func (sched *Scheduler) Cache() internalcache.Cache { } type schedulerOptions struct { - schedulerName string - schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource - hardPodAffinitySymmetricWeight int32 - disablePreemption bool - percentageOfNodesToScore int32 - bindTimeoutSeconds int64 - podInitialBackoffSeconds int64 - podMaxBackoffSeconds int64 + schedulerName string + schedulerAlgorithmSource schedulerapi.SchedulerAlgorithmSource + disablePreemption bool + percentageOfNodesToScore int32 + bindTimeoutSeconds int64 + podInitialBackoffSeconds int64 + podMaxBackoffSeconds int64 // Contains out-of-tree plugins to be merged with the in-tree registry. frameworkOutOfTreeRegistry framework.Registry // Plugins and PluginConfig set from ComponentConfig. @@ -158,13 +157,6 @@ func WithAlgorithmSource(source schedulerapi.SchedulerAlgorithmSource) Option { } } -// WithHardPodAffinitySymmetricWeight sets hardPodAffinitySymmetricWeight for Scheduler, the default value is 1 -func WithHardPodAffinitySymmetricWeight(hardPodAffinitySymmetricWeight int32) Option { - return func(o *schedulerOptions) { - o.hardPodAffinitySymmetricWeight = hardPodAffinitySymmetricWeight - } -} - // WithPreemptionDisabled sets disablePreemption for Scheduler, the default value is false func WithPreemptionDisabled(disablePreemption bool) Option { return func(o *schedulerOptions) { @@ -227,12 +219,11 @@ var defaultSchedulerOptions = schedulerOptions{ schedulerAlgorithmSource: schedulerapi.SchedulerAlgorithmSource{ Provider: defaultAlgorithmSourceProviderName(), }, - hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight, - disablePreemption: false, - percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, - bindTimeoutSeconds: BindTimeoutSeconds, - podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()), - podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()), + disablePreemption: false, + percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, + bindTimeoutSeconds: BindTimeoutSeconds, + podInitialBackoffSeconds: int64(internalqueue.DefaultPodInitialBackoffDuration.Seconds()), + podMaxBackoffSeconds: int64(internalqueue.DefaultPodMaxBackoffDuration.Seconds()), } // New returns a Scheduler @@ -272,23 +263,22 @@ func New(client clientset.Interface, snapshot := internalcache.NewEmptySnapshot() configurator := &Configurator{ - client: client, - informerFactory: informerFactory, - podInformer: podInformer, - volumeBinder: volumeBinder, - schedulerCache: schedulerCache, - StopEverything: stopEverything, - hardPodAffinitySymmetricWeight: options.hardPodAffinitySymmetricWeight, - disablePreemption: options.disablePreemption, - percentageOfNodesToScore: options.percentageOfNodesToScore, - bindTimeoutSeconds: options.bindTimeoutSeconds, - podInitialBackoffSeconds: options.podInitialBackoffSeconds, - podMaxBackoffSeconds: options.podMaxBackoffSeconds, - enableNonPreempting: utilfeature.DefaultFeatureGate.Enabled(kubefeatures.NonPreemptingPriority), - registry: registry, - plugins: options.frameworkPlugins, - pluginConfig: options.frameworkPluginConfig, - nodeInfoSnapshot: snapshot, + client: client, + informerFactory: informerFactory, + podInformer: podInformer, + volumeBinder: volumeBinder, + schedulerCache: schedulerCache, + StopEverything: stopEverything, + disablePreemption: options.disablePreemption, + percentageOfNodesToScore: options.percentageOfNodesToScore, + bindTimeoutSeconds: options.bindTimeoutSeconds, + podInitialBackoffSeconds: options.podInitialBackoffSeconds, + podMaxBackoffSeconds: options.podMaxBackoffSeconds, + enableNonPreempting: utilfeature.DefaultFeatureGate.Enabled(kubefeatures.NonPreemptingPriority), + registry: registry, + plugins: options.frameworkPlugins, + pluginConfig: options.frameworkPluginConfig, + nodeInfoSnapshot: snapshot, } metrics.Register() diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go index 6ceaa6d4d0a..c4e49170263 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go @@ -44,10 +44,6 @@ type KubeSchedulerConfiguration struct { SchedulerName *string `json:"schedulerName,omitempty"` // AlgorithmSource specifies the scheduler algorithm source. AlgorithmSource SchedulerAlgorithmSource `json:"algorithmSource"` - // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule - // corresponding to every RequiredDuringScheduling affinity rule. - // HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range 0-100. - HardPodAffinitySymmetricWeight *int32 `json:"hardPodAffinitySymmetricWeight,omitempty"` // LeaderElection defines the configuration of leader election client. LeaderElection KubeSchedulerLeaderElectionConfiguration `json:"leaderElection"` diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go index 8744079e192..4d2a5c27cac 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go @@ -34,11 +34,6 @@ func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfigurati **out = **in } in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource) - if in.HardPodAffinitySymmetricWeight != nil { - in, out := &in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight - *out = new(int32) - **out = **in - } in.LeaderElection.DeepCopyInto(&out.LeaderElection) out.ClientConnection = in.ClientConnection if in.HealthzBindAddress != nil { diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 0a47b2cf26d..fbe8d0578c7 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -273,7 +273,6 @@ priorities: [] }, }, }), - scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight), scheduler.WithBindTimeoutSeconds(defaultBindTimeout), ) if err != nil { @@ -321,7 +320,6 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) { }, }, }), - scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight), scheduler.WithBindTimeoutSeconds(defaultBindTimeout)) if err == nil {