defaults_test.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. Copyright 2020 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 v1alpha2
  14. import (
  15. "reflect"
  16. "testing"
  17. "time"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. componentbaseconfig "k8s.io/component-base/config/v1alpha1"
  20. "k8s.io/kube-scheduler/config/v1alpha2"
  21. "k8s.io/utils/pointer"
  22. )
  23. func TestSchedulerDefaults(t *testing.T) {
  24. enable := true
  25. tests := []struct {
  26. name string
  27. config *v1alpha2.KubeSchedulerConfiguration
  28. expected *v1alpha2.KubeSchedulerConfiguration
  29. }{
  30. {
  31. name: "empty config",
  32. config: &v1alpha2.KubeSchedulerConfiguration{},
  33. expected: &v1alpha2.KubeSchedulerConfiguration{
  34. SchedulerName: pointer.StringPtr("default-scheduler"),
  35. AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
  36. HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
  37. HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
  38. MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
  39. DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
  40. EnableProfiling: &enable,
  41. EnableContentionProfiling: &enable,
  42. },
  43. LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
  44. LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
  45. LeaderElect: pointer.BoolPtr(true),
  46. LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
  47. RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
  48. RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
  49. ResourceLock: "endpointsleases",
  50. ResourceNamespace: "kube-system",
  51. ResourceName: "kube-scheduler",
  52. },
  53. },
  54. ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
  55. QPS: 50,
  56. Burst: 100,
  57. ContentType: "application/vnd.kubernetes.protobuf",
  58. },
  59. DisablePreemption: pointer.BoolPtr(false),
  60. PercentageOfNodesToScore: pointer.Int32Ptr(0),
  61. BindTimeoutSeconds: pointer.Int64Ptr(600),
  62. PodInitialBackoffSeconds: pointer.Int64Ptr(1),
  63. PodMaxBackoffSeconds: pointer.Int64Ptr(10),
  64. Plugins: nil,
  65. },
  66. },
  67. {
  68. name: "metrics and healthz address with no port",
  69. config: &v1alpha2.KubeSchedulerConfiguration{
  70. MetricsBindAddress: pointer.StringPtr("1.2.3.4"),
  71. HealthzBindAddress: pointer.StringPtr("1.2.3.4"),
  72. },
  73. expected: &v1alpha2.KubeSchedulerConfiguration{
  74. SchedulerName: pointer.StringPtr("default-scheduler"),
  75. AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
  76. HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
  77. HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"),
  78. MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"),
  79. DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
  80. EnableProfiling: &enable,
  81. EnableContentionProfiling: &enable,
  82. },
  83. LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
  84. LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
  85. LeaderElect: pointer.BoolPtr(true),
  86. LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
  87. RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
  88. RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
  89. ResourceLock: "endpointsleases",
  90. ResourceNamespace: "kube-system",
  91. ResourceName: "kube-scheduler",
  92. },
  93. },
  94. ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
  95. QPS: 50,
  96. Burst: 100,
  97. ContentType: "application/vnd.kubernetes.protobuf",
  98. },
  99. DisablePreemption: pointer.BoolPtr(false),
  100. PercentageOfNodesToScore: pointer.Int32Ptr(0),
  101. BindTimeoutSeconds: pointer.Int64Ptr(600),
  102. PodInitialBackoffSeconds: pointer.Int64Ptr(1),
  103. PodMaxBackoffSeconds: pointer.Int64Ptr(10),
  104. Plugins: nil,
  105. },
  106. },
  107. {
  108. name: "metrics and healthz port with no address",
  109. config: &v1alpha2.KubeSchedulerConfiguration{
  110. MetricsBindAddress: pointer.StringPtr(":12345"),
  111. HealthzBindAddress: pointer.StringPtr(":12345"),
  112. },
  113. expected: &v1alpha2.KubeSchedulerConfiguration{
  114. SchedulerName: pointer.StringPtr("default-scheduler"),
  115. AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
  116. HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1),
  117. HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"),
  118. MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"),
  119. DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
  120. EnableProfiling: &enable,
  121. EnableContentionProfiling: &enable,
  122. },
  123. LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
  124. LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
  125. LeaderElect: pointer.BoolPtr(true),
  126. LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
  127. RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
  128. RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
  129. ResourceLock: "endpointsleases",
  130. ResourceNamespace: "kube-system",
  131. ResourceName: "kube-scheduler",
  132. },
  133. },
  134. ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
  135. QPS: 50,
  136. Burst: 100,
  137. ContentType: "application/vnd.kubernetes.protobuf",
  138. },
  139. DisablePreemption: pointer.BoolPtr(false),
  140. PercentageOfNodesToScore: pointer.Int32Ptr(0),
  141. BindTimeoutSeconds: pointer.Int64Ptr(600),
  142. PodInitialBackoffSeconds: pointer.Int64Ptr(1),
  143. PodMaxBackoffSeconds: pointer.Int64Ptr(10),
  144. Plugins: nil,
  145. },
  146. },
  147. }
  148. for _, tc := range tests {
  149. t.Run(tc.name, func(t *testing.T) {
  150. SetDefaults_KubeSchedulerConfiguration(tc.config)
  151. if !reflect.DeepEqual(tc.expected, tc.config) {
  152. t.Errorf("Expected:\n%#v\n\nGot:\n%#v", tc.expected, tc.config)
  153. }
  154. })
  155. }
  156. }