deprecated.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package options
  14. import (
  15. "fmt"
  16. "github.com/spf13/pflag"
  17. "k8s.io/apimachinery/pkg/util/validation/field"
  18. "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
  19. kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
  20. "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
  21. "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
  22. )
  23. // DeprecatedOptions contains deprecated options and their flags.
  24. // TODO remove these fields once the deprecated flags are removed.
  25. type DeprecatedOptions struct {
  26. // The fields below here are placeholders for flags that can't be directly
  27. // mapped into componentconfig.KubeSchedulerConfiguration.
  28. PolicyConfigFile string
  29. PolicyConfigMapName string
  30. PolicyConfigMapNamespace string
  31. UseLegacyPolicyConfig bool
  32. AlgorithmProvider string
  33. HardPodAffinitySymmetricWeight int32
  34. SchedulerName string
  35. }
  36. // AddFlags adds flags for the deprecated options.
  37. func (o *DeprecatedOptions) AddFlags(fs *pflag.FlagSet, cfg *kubeschedulerconfig.KubeSchedulerConfiguration) {
  38. if o == nil {
  39. return
  40. }
  41. fs.StringVar(&o.AlgorithmProvider, "algorithm-provider", o.AlgorithmProvider, "DEPRECATED: the scheduling algorithm provider to use, one of: "+algorithmprovider.ListAlgorithmProviders())
  42. 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")
  43. 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'", kubeschedulerconfig.SchedulerPolicyConfigMapKey)
  44. fs.StringVar(&o.PolicyConfigMapName, "policy-configmap", o.PolicyConfigMapName, usage)
  45. 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.")
  46. 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")
  47. fs.BoolVar(&cfg.EnableProfiling, "profiling", cfg.EnableProfiling, "DEPRECATED: enable profiling via web interface host:port/debug/pprof/")
  48. fs.BoolVar(&cfg.EnableContentionProfiling, "contention-profiling", cfg.EnableContentionProfiling, "DEPRECATED: enable lock contention profiling, if profiling is enabled")
  49. fs.StringVar(&cfg.ClientConnection.Kubeconfig, "kubeconfig", cfg.ClientConnection.Kubeconfig, "DEPRECATED: path to kubeconfig file with authorization and master location information.")
  50. fs.StringVar(&cfg.ClientConnection.ContentType, "kube-api-content-type", cfg.ClientConnection.ContentType, "DEPRECATED: content type of requests sent to apiserver.")
  51. fs.Float32Var(&cfg.ClientConnection.QPS, "kube-api-qps", cfg.ClientConnection.QPS, "DEPRECATED: QPS to use while talking with kubernetes apiserver")
  52. fs.Int32Var(&cfg.ClientConnection.Burst, "kube-api-burst", cfg.ClientConnection.Burst, "DEPRECATED: burst to use while talking with kubernetes apiserver")
  53. 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.")
  54. 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")
  55. fs.Int32Var(&o.HardPodAffinitySymmetricWeight, "hard-pod-affinity-symmetric-weight", o.HardPodAffinitySymmetricWeight,
  56. "DEPRECATED: RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule corresponding "+
  57. "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."+
  58. "This option was moved to the policy configuration file")
  59. 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\".")
  60. // MarkDeprecated hides the flag from the help. We don't want that:
  61. // fs.MarkDeprecated("hard-pod-affinity-symmetric-weight", "This option was moved to the policy configuration file")
  62. }
  63. // Validate validates the deprecated scheduler options.
  64. func (o *DeprecatedOptions) Validate() []error {
  65. var errs []error
  66. if o.UseLegacyPolicyConfig && len(o.PolicyConfigFile) == 0 {
  67. errs = append(errs, field.Required(field.NewPath("policyConfigFile"), "required when --use-legacy-policy-config is true"))
  68. }
  69. if err := interpodaffinity.ValidateHardPodAffinityWeight(field.NewPath("hardPodAffinitySymmetricWeight"), o.HardPodAffinitySymmetricWeight); err != nil {
  70. errs = append(errs, err)
  71. }
  72. return errs
  73. }
  74. // ApplyTo sets cfg.AlgorithmSource from flags passed on the command line in the following precedence order:
  75. //
  76. // 1. --use-legacy-policy-config to use a policy file.
  77. // 2. --policy-configmap to use a policy config map value.
  78. // 3. --algorithm-provider to use a named algorithm provider.
  79. func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfiguration) error {
  80. if o == nil {
  81. return nil
  82. }
  83. switch {
  84. case o.UseLegacyPolicyConfig || (len(o.PolicyConfigFile) > 0 && o.PolicyConfigMapName == ""):
  85. cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{
  86. Policy: &kubeschedulerconfig.SchedulerPolicySource{
  87. File: &kubeschedulerconfig.SchedulerPolicyFileSource{
  88. Path: o.PolicyConfigFile,
  89. },
  90. },
  91. }
  92. case len(o.PolicyConfigMapName) > 0:
  93. cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{
  94. Policy: &kubeschedulerconfig.SchedulerPolicySource{
  95. ConfigMap: &kubeschedulerconfig.SchedulerPolicyConfigMapSource{
  96. Name: o.PolicyConfigMapName,
  97. Namespace: o.PolicyConfigMapNamespace,
  98. },
  99. },
  100. }
  101. case len(o.AlgorithmProvider) > 0:
  102. cfg.AlgorithmSource = kubeschedulerconfig.SchedulerAlgorithmSource{
  103. Provider: &o.AlgorithmProvider,
  104. }
  105. }
  106. // The following deprecated options affect the only existing profile that is
  107. // added by default.
  108. profile := &cfg.Profiles[0]
  109. if len(o.SchedulerName) > 0 {
  110. profile.SchedulerName = o.SchedulerName
  111. }
  112. if o.HardPodAffinitySymmetricWeight != interpodaffinity.DefaultHardPodAffinityWeight {
  113. args := interpodaffinity.Args{
  114. HardPodAffinityWeight: &o.HardPodAffinitySymmetricWeight,
  115. }
  116. profile.PluginConfig = append(profile.PluginConfig, plugins.NewPluginConfig(interpodaffinity.Name, args))
  117. }
  118. return nil
  119. }