defaults_test.go 7.0 KB

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