defaults.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 v1alpha1
  14. import (
  15. "net"
  16. "strconv"
  17. "k8s.io/api/core/v1"
  18. "k8s.io/apimachinery/pkg/runtime"
  19. componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
  20. kubescedulerconfigv1alpha1 "k8s.io/kube-scheduler/config/v1alpha1"
  21. // this package shouldn't really depend on other k8s.io/kubernetes code
  22. api "k8s.io/kubernetes/pkg/apis/core"
  23. "k8s.io/kubernetes/pkg/master/ports"
  24. )
  25. // When the --failure-domains scheduler flag is not specified,
  26. // DefaultFailureDomains defines the set of label keys used when TopologyKey is empty in PreferredDuringScheduling anti-affinity.
  27. var defaultFailureDomains string = v1.LabelHostname + "," + v1.LabelZoneFailureDomain + "," + v1.LabelZoneRegion
  28. func addDefaultingFuncs(scheme *runtime.Scheme) error {
  29. return RegisterDefaults(scheme)
  30. }
  31. // SetDefaults_KubeSchedulerConfiguration sets additional defaults
  32. func SetDefaults_KubeSchedulerConfiguration(obj *kubescedulerconfigv1alpha1.KubeSchedulerConfiguration) {
  33. if len(obj.SchedulerName) == 0 {
  34. obj.SchedulerName = api.DefaultSchedulerName
  35. }
  36. if obj.HardPodAffinitySymmetricWeight == 0 {
  37. obj.HardPodAffinitySymmetricWeight = api.DefaultHardPodAffinitySymmetricWeight
  38. }
  39. if obj.AlgorithmSource.Policy == nil &&
  40. (obj.AlgorithmSource.Provider == nil || len(*obj.AlgorithmSource.Provider) == 0) {
  41. val := kubescedulerconfigv1alpha1.SchedulerDefaultProviderName
  42. obj.AlgorithmSource.Provider = &val
  43. }
  44. if policy := obj.AlgorithmSource.Policy; policy != nil {
  45. if policy.ConfigMap != nil && len(policy.ConfigMap.Namespace) == 0 {
  46. obj.AlgorithmSource.Policy.ConfigMap.Namespace = api.NamespaceSystem
  47. }
  48. }
  49. if host, port, err := net.SplitHostPort(obj.HealthzBindAddress); err == nil {
  50. if len(host) == 0 {
  51. host = "0.0.0.0"
  52. }
  53. obj.HealthzBindAddress = net.JoinHostPort(host, port)
  54. } else {
  55. obj.HealthzBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort))
  56. }
  57. if host, port, err := net.SplitHostPort(obj.MetricsBindAddress); err == nil {
  58. if len(host) == 0 {
  59. host = "0.0.0.0"
  60. }
  61. obj.MetricsBindAddress = net.JoinHostPort(host, port)
  62. } else {
  63. obj.MetricsBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort))
  64. }
  65. if len(obj.LeaderElection.LockObjectNamespace) == 0 {
  66. obj.LeaderElection.LockObjectNamespace = kubescedulerconfigv1alpha1.SchedulerDefaultLockObjectNamespace
  67. }
  68. if len(obj.LeaderElection.LockObjectName) == 0 {
  69. obj.LeaderElection.LockObjectName = kubescedulerconfigv1alpha1.SchedulerDefaultLockObjectName
  70. }
  71. if len(obj.ClientConnection.ContentType) == 0 {
  72. obj.ClientConnection.ContentType = "application/vnd.kubernetes.protobuf"
  73. }
  74. // Scheduler has an opinion about QPS/Burst, setting specific defaults for itself, instead of generic settings.
  75. if obj.ClientConnection.QPS == 0.0 {
  76. obj.ClientConnection.QPS = 50.0
  77. }
  78. if obj.ClientConnection.Burst == 0 {
  79. obj.ClientConnection.Burst = 100
  80. }
  81. // Use the default LeaderElectionConfiguration options
  82. componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&obj.LeaderElection.LeaderElectionConfiguration)
  83. if obj.BindTimeoutSeconds == nil {
  84. defaultBindTimeoutSeconds := int64(600)
  85. obj.BindTimeoutSeconds = &defaultBindTimeoutSeconds
  86. }
  87. }