Merge pull request #102805 from ahg-g/ahg-deprecate

Remove deprecated scheduler CLI flags
This commit is contained in:
Kubernetes Prow Robot 2021-06-11 08:45:00 -07:00 committed by GitHub
commit 21ee533508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 189 deletions

View File

@ -23,8 +23,6 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/util/validation/field"
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config" schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/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"
) )
// DeprecatedOptions contains deprecated options and their flags. // DeprecatedOptions contains deprecated options and their flags.
@ -32,12 +30,10 @@ import (
type DeprecatedOptions struct { type DeprecatedOptions struct {
// The fields below here are placeholders for flags that can't be directly // The fields below here are placeholders for flags that can't be directly
// mapped into componentconfig.KubeSchedulerConfiguration. // mapped into componentconfig.KubeSchedulerConfiguration.
PolicyConfigFile string PolicyConfigFile string
PolicyConfigMapName string PolicyConfigMapName string
PolicyConfigMapNamespace string PolicyConfigMapNamespace string
UseLegacyPolicyConfig bool UseLegacyPolicyConfig bool
HardPodAffinitySymmetricWeight int32
SchedulerName string
} }
// AddFlags adds flags for the deprecated options. // AddFlags adds flags for the deprecated options.
@ -60,14 +56,6 @@ func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig
fs.Int32Var(&cfg.ClientConnection.Burst, "kube-api-burst", cfg.ClientConnection.Burst, "DEPRECATED: burst to use while talking with kubernetes apiserver. This parameter is ignored if a config file is specified in --config.") fs.Int32Var(&cfg.ClientConnection.Burst, "kube-api-burst", cfg.ClientConnection.Burst, "DEPRECATED: burst to use while talking with kubernetes apiserver. This parameter is ignored if a config file is specified in --config.")
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. This parameter is ignored if a config file is specified in --config.") 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. This parameter is ignored if a config file is specified in --config.")
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. This parameter is ignored if a config file is specified in --config.") 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. This parameter is ignored if a config file is specified in --config.")
fs.Int32Var(&o.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", o.HardPodAffinitySymmetricWeight,
"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 parameter is ignored if a config file is specified in --config.")
fs.StringVar(&o.SchedulerName, "scheduler-name", o.SchedulerName, "DEPRECATED: name of the scheduler, used to select which pods will be processed by this scheduler, based on pod's \"spec.schedulerName\". This parameter is ignored if a config file is specified in --config.")
// MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("hard-pod-affinity-symmetric-weight", "This option was moved to the policy configuration file")
} }
// Validate validates the deprecated scheduler options. // Validate validates the deprecated scheduler options.
@ -78,10 +66,6 @@ func (o *DeprecatedOptions) Validate() []error {
errs = append(errs, field.Required(field.NewPath("policyConfigFile"), "required when --use-legacy-policy-config is true")) errs = append(errs, field.Required(field.NewPath("policyConfigFile"), "required when --use-legacy-policy-config is true"))
} }
if err := validation.ValidateHardPodAffinityWeight(field.NewPath("hardPodAffinitySymmetricWeight"), o.HardPodAffinitySymmetricWeight); err != nil {
errs = append(errs, err)
}
return errs return errs
} }
@ -89,7 +73,7 @@ func (o *DeprecatedOptions) Validate() []error {
// //
// 1. --use-legacy-policy-config to use a policy file. // 1. --use-legacy-policy-config to use a policy file.
// 2. --policy-configmap to use a policy config map value. // 2. --policy-configmap to use a policy config map value.
func (o *DeprecatedOptions) ApplyPolicySourceTo(c *schedulerappconfig.Config) { func (o *DeprecatedOptions) ApplyTo(c *schedulerappconfig.Config) {
if o == nil { if o == nil {
return return
} }
@ -110,29 +94,3 @@ func (o *DeprecatedOptions) ApplyPolicySourceTo(c *schedulerappconfig.Config) {
} }
} }
} }
// ApplyTo sets a default profile plugin config if no config file is specified
// 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(c *schedulerappconfig.Config) {
if o == nil {
return
}
// The following deprecated options affect the only existing profile that is
// added by default.
profile := &c.ComponentConfig.Profiles[0]
if len(o.SchedulerName) > 0 {
profile.SchedulerName = o.SchedulerName
}
plCfg := kubeschedulerconfig.PluginConfig{
Name: interpodaffinity.Name,
Args: &kubeschedulerconfig.InterPodAffinityArgs{
HardPodAffinityWeight: o.HardPodAffinitySymmetricWeight,
},
}
profile.PluginConfig = append(profile.PluginConfig, plCfg)
o.ApplyPolicySourceTo(c)
}

View File

@ -38,17 +38,6 @@ func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) {
UseLegacyPolicyConfig: true, UseLegacyPolicyConfig: true,
}, },
}, },
"good affinity weight": {
config: &DeprecatedOptions{
HardPodAffinitySymmetricWeight: 50,
},
},
"bad affinity weight": {
expectedToFail: true,
config: &DeprecatedOptions{
HardPodAffinitySymmetricWeight: -1,
},
},
} }
for name, scenario := range scenarios { for name, scenario := range scenarios {

View File

@ -23,7 +23,6 @@ import (
"strconv" "strconv"
"time" "time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
apiserveroptions "k8s.io/apiserver/pkg/server/options" apiserveroptions "k8s.io/apiserver/pkg/server/options"
@ -99,10 +98,8 @@ func NewOptions() (*Options, error) {
Authentication: apiserveroptions.NewDelegatingAuthenticationOptions(), Authentication: apiserveroptions.NewDelegatingAuthenticationOptions(),
Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(), Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(),
Deprecated: &DeprecatedOptions{ Deprecated: &DeprecatedOptions{
UseLegacyPolicyConfig: false, UseLegacyPolicyConfig: false,
PolicyConfigMapNamespace: metav1.NamespaceSystem, PolicyConfigMapNamespace: metav1.NamespaceSystem,
SchedulerName: corev1.DefaultSchedulerName,
HardPodAffinitySymmetricWeight: 1,
}, },
Metrics: metrics.NewOptions(), Metrics: metrics.NewOptions(),
Logs: logs.NewOptions(), Logs: logs.NewOptions(),
@ -195,7 +192,7 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
c.ComponentConfig = *cfg c.ComponentConfig = *cfg
// apply any deprecated Policy flags, if applicable // apply any deprecated Policy flags, if applicable
o.Deprecated.ApplyPolicySourceTo(c) o.Deprecated.ApplyTo(c)
// if the user has set CC profiles and is trying to use a Policy config, error out // 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 // these configs are no longer merged and they should not be used simultaneously

View File

@ -40,7 +40,6 @@ import (
"k8s.io/kube-scheduler/config/v1beta2" "k8s.io/kube-scheduler/config/v1beta2"
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
) )
func newV1beta1DefaultComponentConfig() (*kubeschedulerconfig.KubeSchedulerConfiguration, error) { func newV1beta1DefaultComponentConfig() (*kubeschedulerconfig.KubeSchedulerConfiguration, error) {
@ -947,117 +946,6 @@ profiles:
}, },
expectedError: "no configuration has been provided", 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,
},
Logs: logs.NewOptions(),
},
expectedUsername: "flag",
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1beta2.SchemeGroupVersion.String(),
},
Parallelism: 16,
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
EnableProfiling: true,
EnableContentionProfiling: true,
},
LeaderElection: 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: "leases",
ResourceNamespace: "kube-system",
ResourceName: "kube-scheduler",
},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: flagKubeconfig,
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
PercentageOfNodesToScore: defaultPercentageOfNodesToScore,
PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Profiles: []kubeschedulerconfig.KubeSchedulerProfile{
{
SchedulerName: "default-scheduler",
PluginConfig: []kubeschedulerconfig.PluginConfig{
{
Name: "InterPodAffinity",
Args: &kubeschedulerconfig.InterPodAffinityArgs{HardPodAffinityWeight: 5},
},
},
},
},
},
},
{
name: "Deprecated SchedulerName flag",
options: &Options{
ComponentConfig: func() kubeschedulerconfig.KubeSchedulerConfiguration {
cfg, _ := newDefaultComponentConfig()
cfg.ClientConnection.Kubeconfig = flagKubeconfig
return *cfg
}(),
Deprecated: &DeprecatedOptions{
SchedulerName: "my-nice-scheduler",
HardPodAffinitySymmetricWeight: 1,
},
Logs: logs.NewOptions(),
},
expectedUsername: "flag",
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: v1beta2.SchemeGroupVersion.String(),
},
Parallelism: 16,
DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
EnableProfiling: true,
EnableContentionProfiling: true,
},
LeaderElection: 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: "leases",
ResourceNamespace: "kube-system",
ResourceName: "kube-scheduler",
},
ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
Kubeconfig: flagKubeconfig,
QPS: 50,
Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf",
},
PercentageOfNodesToScore: defaultPercentageOfNodesToScore,
PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
Profiles: []kubeschedulerconfig.KubeSchedulerProfile{
{
SchedulerName: "my-nice-scheduler",
PluginConfig: []kubeschedulerconfig.PluginConfig{
{
Name: interpodaffinity.Name,
Args: &kubeschedulerconfig.InterPodAffinityArgs{
HardPodAffinityWeight: 1,
},
},
},
},
},
},
},
{ {
name: "Attempting to set Component Config Profiles and Policy config", name: "Attempting to set Component Config Profiles and Policy config",
options: &Options{ options: &Options{

View File

@ -254,16 +254,6 @@ profiles:
}, },
}, },
}, },
{
name: "Deprecated SchedulerName flag",
flags: []string{
"--kubeconfig", configKubeconfig,
"--scheduler-name", "my-scheduler",
},
wantPlugins: map[string]map[string][]kubeschedulerconfig.Plugin{
"my-scheduler": defaultPlugins,
},
},
{ {
name: "default algorithm provider", name: "default algorithm provider",
flags: []string{ flags: []string{

View File

@ -68,11 +68,11 @@ func validateMinCandidateNodesAbsolute(minCandidateNodesAbsolute int32, p *field
// ValidateInterPodAffinityArgs validates that InterPodAffinityArgs are correct. // ValidateInterPodAffinityArgs validates that InterPodAffinityArgs are correct.
func ValidateInterPodAffinityArgs(path *field.Path, args *config.InterPodAffinityArgs) error { func ValidateInterPodAffinityArgs(path *field.Path, args *config.InterPodAffinityArgs) error {
return ValidateHardPodAffinityWeight(path.Child("hardPodAffinityWeight"), args.HardPodAffinityWeight) return validateHardPodAffinityWeight(path.Child("hardPodAffinityWeight"), args.HardPodAffinityWeight)
} }
// ValidateHardPodAffinityWeight validates that weight is within allowed range. // validateHardPodAffinityWeight validates that weight is within allowed range.
func ValidateHardPodAffinityWeight(path *field.Path, w int32) error { func validateHardPodAffinityWeight(path *field.Path, w int32) error {
const ( const (
minHardPodAffinityWeight = 0 minHardPodAffinityWeight = 0
maxHardPodAffinityWeight = 100 maxHardPodAffinityWeight = 100