remove legacy scheduler policy config, as well as associated flags policy-config-file, policy-configmap, policy-configmap-namespace and use-legacy-policy-config
Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
@@ -32,8 +32,6 @@ type Config struct {
|
||||
// ComponentConfig is the scheduler server's configuration object.
|
||||
ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration
|
||||
|
||||
LegacyPolicySource *kubeschedulerconfig.SchedulerPolicySource
|
||||
|
||||
// LoopbackClientConfig is a config for a privileged loopback connection
|
||||
LoopbackClientConfig *restclient.Config
|
||||
|
||||
|
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
|
||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
)
|
||||
|
||||
@@ -31,11 +30,7 @@ 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
|
||||
Port int
|
||||
Port int
|
||||
}
|
||||
|
||||
// TODO: remove these insecure flags in v1.24
|
||||
@@ -59,12 +54,6 @@ func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig
|
||||
|
||||
addDummyInsecureFlags(o, fs)
|
||||
|
||||
fs.StringVar(&o.PolicyConfigFile, "policy-config-file", o.PolicyConfigFile, "DEPRECATED: file with scheduler policy configuration. This file is used if policy ConfigMap is not provided or --use-legacy-policy-config=true. Note: The predicates/priorities defined in this file will take precedence over any profiles define in ComponentConfig.")
|
||||
usage := fmt.Sprintf("DEPRECATED: name of the ConfigMap object that contains scheduler's policy configuration. It must exist in the system namespace before scheduler initialization if --use-legacy-policy-config=false. The config must be provided as the value of an element in 'Data' map with the key='%v'. Note: The predicates/priorities defined in this file will take precedence over any profiles define in ComponentConfig.", kubeschedulerconfig.SchedulerPolicyConfigMapKey)
|
||||
fs.StringVar(&o.PolicyConfigMapName, "policy-configmap", o.PolicyConfigMapName, usage)
|
||||
fs.StringVar(&o.PolicyConfigMapNamespace, "policy-configmap-namespace", o.PolicyConfigMapNamespace, "DEPRECATED: the namespace where policy ConfigMap is located. The kube-system namespace will be used if this is not provided or is empty. Note: The predicates/priorities defined in this file will take precedence over any profiles define in ComponentConfig.")
|
||||
fs.BoolVar(&o.UseLegacyPolicyConfig, "use-legacy-policy-config", o.UseLegacyPolicyConfig, "DEPRECATED: when set to true, scheduler will ignore policy ConfigMap and uses policy config file. Note: The scheduler will fail if this is combined with Plugin configs")
|
||||
|
||||
fs.BoolVar(&cfg.EnableProfiling, "profiling", cfg.EnableProfiling, "DEPRECATED: enable profiling via web interface host:port/debug/pprof/. This parameter is ignored if a config file is specified in --config.")
|
||||
fs.BoolVar(&cfg.EnableContentionProfiling, "contention-profiling", cfg.EnableContentionProfiling, "DEPRECATED: enable lock contention profiling, if profiling is enabled. This parameter is ignored if a config file is specified in --config.")
|
||||
fs.StringVar(&cfg.ClientConnection.Kubeconfig, "kubeconfig", cfg.ClientConnection.Kubeconfig, "DEPRECATED: path to kubeconfig file with authorization and master location information. This parameter is ignored if a config file is specified in --config.")
|
||||
@@ -79,39 +68,9 @@ func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig
|
||||
func (o *DeprecatedOptions) Validate() []error {
|
||||
var errs []error
|
||||
|
||||
if o.UseLegacyPolicyConfig && len(o.PolicyConfigFile) == 0 {
|
||||
errs = append(errs, field.Required(field.NewPath("policyConfigFile"), "required when --use-legacy-policy-config is true"))
|
||||
}
|
||||
|
||||
// TODO: delete this check after insecure flags removed in v1.24
|
||||
if o.Port != 0 {
|
||||
errs = append(errs, field.Required(field.NewPath("port"), fmt.Sprintf("invalid port value %d: only zero is allowed", o.Port)))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// ApplyTo sets cfg.PolicySource from flags passed on the command line in the following precedence order:
|
||||
//
|
||||
// 1. --use-legacy-policy-config to use a policy file.
|
||||
// 2. --policy-configmap to use a policy config map value.
|
||||
func (o *DeprecatedOptions) ApplyTo(c *schedulerappconfig.Config) {
|
||||
if o == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""):
|
||||
c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{
|
||||
File: &kubeschedulerconfig.SchedulerPolicyFileSource{
|
||||
Path: o.PolicyConfigFile,
|
||||
},
|
||||
}
|
||||
case len(o.PolicyConfigMapName) > 0:
|
||||
c.LegacyPolicySource = &kubeschedulerconfig.SchedulerPolicySource{
|
||||
ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
|
||||
Name: o.PolicyConfigMapName,
|
||||
Namespace: o.PolicyConfigMapNamespace,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateDeprecatedKubeSchedulerConfiguration(t *testing.T) {
|
||||
scenarios := map[string]struct {
|
||||
expectedToFail bool
|
||||
config *DeprecatedOptions
|
||||
}{
|
||||
"good": {
|
||||
config: &DeprecatedOptions{
|
||||
PolicyConfigFile: "/some/file",
|
||||
UseLegacyPolicyConfig: true,
|
||||
},
|
||||
},
|
||||
"bad-policy-config-file-null": {
|
||||
expectedToFail: true,
|
||||
config: &DeprecatedOptions{
|
||||
PolicyConfigFile: "",
|
||||
UseLegacyPolicyConfig: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, scenario := range scenarios {
|
||||
errs := scenario.config.Validate()
|
||||
if len(errs) == 0 && scenario.expectedToFail {
|
||||
t.Errorf("Unexpected success for scenario: %s", name)
|
||||
}
|
||||
if len(errs) > 0 && !scenario.expectedToFail {
|
||||
t.Errorf("Unexpected failure for scenario: %s - %+v", name, errs)
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,7 +23,6 @@ import (
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
@@ -76,12 +75,9 @@ func NewOptions() (*Options, error) {
|
||||
SecureServing: apiserveroptions.NewSecureServingOptions().WithLoopback(),
|
||||
Authentication: apiserveroptions.NewDelegatingAuthenticationOptions(),
|
||||
Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(),
|
||||
Deprecated: &DeprecatedOptions{
|
||||
UseLegacyPolicyConfig: false,
|
||||
PolicyConfigMapNamespace: metav1.NamespaceSystem,
|
||||
},
|
||||
Metrics: metrics.NewOptions(),
|
||||
Logs: logs.NewOptions(),
|
||||
Deprecated: &DeprecatedOptions{},
|
||||
Metrics: metrics.NewOptions(),
|
||||
Logs: logs.NewOptions(),
|
||||
}
|
||||
|
||||
o.Authentication.TolerateInClusterLookupFailure = true
|
||||
@@ -161,10 +157,7 @@ func (o *Options) Complete(nfs *cliflag.NamedFlagSets) error {
|
||||
// Flags returns flags for a specific scheduler by section name
|
||||
func (o *Options) Flags() (nfs cliflag.NamedFlagSets) {
|
||||
fs := nfs.FlagSet("misc")
|
||||
fs.StringVar(&o.ConfigFile, "config", o.ConfigFile, `The path to the configuration file. The following flags can overwrite fields in this file:
|
||||
--policy-config-file
|
||||
--policy-configmap
|
||||
--policy-configmap-namespace`)
|
||||
fs.StringVar(&o.ConfigFile, "config", o.ConfigFile, "The path to the configuration file.")
|
||||
fs.StringVar(&o.WriteConfigTo, "write-config-to", o.WriteConfigTo, "If set, write the configuration values to this file and exit.")
|
||||
fs.StringVar(&o.Master, "master", o.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
|
||||
|
||||
@@ -185,8 +178,6 @@ func (o *Options) Flags() (nfs cliflag.NamedFlagSets) {
|
||||
func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
||||
if len(o.ConfigFile) == 0 {
|
||||
c.ComponentConfig = o.ComponentConfig
|
||||
|
||||
o.Deprecated.ApplyTo(c)
|
||||
} else {
|
||||
cfg, err := loadConfigFromFile(o.ConfigFile)
|
||||
if err != nil {
|
||||
@@ -197,15 +188,6 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
||||
}
|
||||
|
||||
c.ComponentConfig = *cfg
|
||||
|
||||
// apply any deprecated Policy flags, if applicable
|
||||
o.Deprecated.ApplyTo(c)
|
||||
}
|
||||
|
||||
// If the user is using the legacy policy config, clear the profiles, they will be set
|
||||
// on scheduler instantiation based on the configurations in the policy file.
|
||||
if c.LegacyPolicySource != nil {
|
||||
c.ComponentConfig.Profiles = nil
|
||||
}
|
||||
|
||||
if err := o.SecureServing.ApplyTo(&c.SecureServing, &c.LoopbackClientConfig); err != nil {
|
||||
|
@@ -1120,45 +1120,6 @@ profiles:
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Attempting to set Component Config Profiles and Policy config",
|
||||
options: &Options{
|
||||
ConfigFile: pluginConfigFile,
|
||||
Deprecated: &DeprecatedOptions{
|
||||
PolicyConfigMapName: "bar",
|
||||
},
|
||||
Logs: logs.NewOptions(),
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: v1beta3.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: configKubeconfig,
|
||||
QPS: 50,
|
||||
Burst: 100,
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
},
|
||||
PercentageOfNodesToScore: defaultPercentageOfNodesToScore,
|
||||
PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds,
|
||||
PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no config",
|
||||
options: &Options{
|
||||
|
@@ -316,7 +316,6 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
|
||||
scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion),
|
||||
scheduler.WithKubeConfig(cc.KubeConfig),
|
||||
scheduler.WithProfiles(cc.ComponentConfig.Profiles...),
|
||||
scheduler.WithLegacyPolicySource(cc.LegacyPolicySource),
|
||||
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
||||
scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry),
|
||||
scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds),
|
||||
|
@@ -139,19 +139,6 @@ profiles:
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// policy config file
|
||||
policyConfigFile := filepath.Join(tmpDir, "policy-config.yaml")
|
||||
if err := ioutil.WriteFile(policyConfigFile, []byte(`{
|
||||
"kind": "Policy",
|
||||
"apiVersion": "v1",
|
||||
"predicates": [
|
||||
{"name": "MatchInterPodAffinity"}
|
||||
],"priorities": [
|
||||
{"name": "InterPodAffinityPriority", "weight": 2}
|
||||
]}`), os.FileMode(0600)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
flags []string
|
||||
@@ -206,30 +193,6 @@ profiles:
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "policy config file",
|
||||
flags: []string{
|
||||
"--kubeconfig", configKubeconfig,
|
||||
"--policy-config-file", policyConfigFile,
|
||||
},
|
||||
wantPlugins: map[string]*config.Plugins{
|
||||
"default-scheduler": {
|
||||
QueueSort: config.PluginSet{Enabled: []config.Plugin{{Name: "PrioritySort"}}},
|
||||
PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: "InterPodAffinity"}}},
|
||||
Filter: config.PluginSet{
|
||||
Enabled: []config.Plugin{
|
||||
{Name: "NodeUnschedulable"},
|
||||
{Name: "TaintToleration"},
|
||||
{Name: "InterPodAffinity"},
|
||||
},
|
||||
},
|
||||
PostFilter: config.PluginSet{Enabled: []config.Plugin{{Name: "DefaultPreemption"}}},
|
||||
PreScore: config.PluginSet{Enabled: []config.Plugin{{Name: "InterPodAffinity"}}},
|
||||
Score: config.PluginSet{Enabled: []config.Plugin{{Name: "InterPodAffinity", Weight: 2}}},
|
||||
Bind: config.PluginSet{Enabled: []config.Plugin{{Name: "DefaultBinder"}}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
makeListener := func(t *testing.T) net.Listener {
|
||||
|
Reference in New Issue
Block a user