123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /*
- Copyright 2020 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 v1alpha2
- import (
- "testing"
- "time"
- "github.com/google/go-cmp/cmp"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- componentbaseconfig "k8s.io/component-base/config/v1alpha1"
- "k8s.io/kube-scheduler/config/v1alpha2"
- "k8s.io/utils/pointer"
- )
- func TestSchedulerDefaults(t *testing.T) {
- enable := true
- tests := []struct {
- name string
- config *v1alpha2.KubeSchedulerConfiguration
- expected *v1alpha2.KubeSchedulerConfiguration
- }{
- {
- name: "empty config",
- config: &v1alpha2.KubeSchedulerConfiguration{},
- expected: &v1alpha2.KubeSchedulerConfiguration{
- AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
- HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
- EnableProfiling: &enable,
- EnableContentionProfiling: &enable,
- },
- LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
- LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
- LeaderElect: pointer.BoolPtr(true),
- LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
- RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
- RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
- ResourceLock: "endpointsleases",
- ResourceNamespace: "kube-system",
- ResourceName: "kube-scheduler",
- },
- },
- ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
- QPS: 50,
- Burst: 100,
- ContentType: "application/vnd.kubernetes.protobuf",
- },
- DisablePreemption: pointer.BoolPtr(false),
- PercentageOfNodesToScore: pointer.Int32Ptr(0),
- BindTimeoutSeconds: pointer.Int64Ptr(600),
- PodInitialBackoffSeconds: pointer.Int64Ptr(1),
- PodMaxBackoffSeconds: pointer.Int64Ptr(10),
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {SchedulerName: pointer.StringPtr("default-scheduler")},
- },
- },
- },
- {
- name: "no scheduler name",
- config: &v1alpha2.KubeSchedulerConfiguration{
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {
- PluginConfig: []v1alpha2.PluginConfig{
- {Name: "FooPlugin"},
- },
- },
- },
- },
- expected: &v1alpha2.KubeSchedulerConfiguration{
- AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
- HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
- EnableProfiling: &enable,
- EnableContentionProfiling: &enable,
- },
- LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
- LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
- LeaderElect: pointer.BoolPtr(true),
- LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
- RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
- RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
- ResourceLock: "endpointsleases",
- ResourceNamespace: "kube-system",
- ResourceName: "kube-scheduler",
- },
- },
- ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
- QPS: 50,
- Burst: 100,
- ContentType: "application/vnd.kubernetes.protobuf",
- },
- DisablePreemption: pointer.BoolPtr(false),
- PercentageOfNodesToScore: pointer.Int32Ptr(0),
- BindTimeoutSeconds: pointer.Int64Ptr(600),
- PodInitialBackoffSeconds: pointer.Int64Ptr(1),
- PodMaxBackoffSeconds: pointer.Int64Ptr(10),
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {
- SchedulerName: pointer.StringPtr("default-scheduler"),
- PluginConfig: []v1alpha2.PluginConfig{
- {Name: "FooPlugin"},
- },
- },
- },
- },
- },
- {
- name: "two profiles",
- config: &v1alpha2.KubeSchedulerConfiguration{
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {
- PluginConfig: []v1alpha2.PluginConfig{
- {Name: "FooPlugin"},
- },
- },
- {
- SchedulerName: pointer.StringPtr("custom-scheduler"),
- Plugins: &v1alpha2.Plugins{
- Bind: &v1alpha2.PluginSet{
- Enabled: []v1alpha2.Plugin{
- {Name: "BarPlugin"},
- },
- },
- },
- },
- },
- },
- expected: &v1alpha2.KubeSchedulerConfiguration{
- AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
- HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"),
- DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
- EnableProfiling: &enable,
- EnableContentionProfiling: &enable,
- },
- LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
- LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
- LeaderElect: pointer.BoolPtr(true),
- LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
- RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
- RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
- ResourceLock: "endpointsleases",
- ResourceNamespace: "kube-system",
- ResourceName: "kube-scheduler",
- },
- },
- ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
- QPS: 50,
- Burst: 100,
- ContentType: "application/vnd.kubernetes.protobuf",
- },
- DisablePreemption: pointer.BoolPtr(false),
- PercentageOfNodesToScore: pointer.Int32Ptr(0),
- BindTimeoutSeconds: pointer.Int64Ptr(600),
- PodInitialBackoffSeconds: pointer.Int64Ptr(1),
- PodMaxBackoffSeconds: pointer.Int64Ptr(10),
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {
- PluginConfig: []v1alpha2.PluginConfig{
- {Name: "FooPlugin"},
- },
- },
- {
- SchedulerName: pointer.StringPtr("custom-scheduler"),
- Plugins: &v1alpha2.Plugins{
- Bind: &v1alpha2.PluginSet{
- Enabled: []v1alpha2.Plugin{
- {Name: "BarPlugin"},
- },
- },
- },
- },
- },
- },
- },
- {
- name: "metrics and healthz address with no port",
- config: &v1alpha2.KubeSchedulerConfiguration{
- MetricsBindAddress: pointer.StringPtr("1.2.3.4"),
- HealthzBindAddress: pointer.StringPtr("1.2.3.4"),
- },
- expected: &v1alpha2.KubeSchedulerConfiguration{
- AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
- HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"),
- MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"),
- DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
- EnableProfiling: &enable,
- EnableContentionProfiling: &enable,
- },
- LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
- LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
- LeaderElect: pointer.BoolPtr(true),
- LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
- RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
- RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
- ResourceLock: "endpointsleases",
- ResourceNamespace: "kube-system",
- ResourceName: "kube-scheduler",
- },
- },
- ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
- QPS: 50,
- Burst: 100,
- ContentType: "application/vnd.kubernetes.protobuf",
- },
- DisablePreemption: pointer.BoolPtr(false),
- PercentageOfNodesToScore: pointer.Int32Ptr(0),
- BindTimeoutSeconds: pointer.Int64Ptr(600),
- PodInitialBackoffSeconds: pointer.Int64Ptr(1),
- PodMaxBackoffSeconds: pointer.Int64Ptr(10),
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {SchedulerName: pointer.StringPtr("default-scheduler")},
- },
- },
- },
- {
- name: "metrics and healthz port with no address",
- config: &v1alpha2.KubeSchedulerConfiguration{
- MetricsBindAddress: pointer.StringPtr(":12345"),
- HealthzBindAddress: pointer.StringPtr(":12345"),
- },
- expected: &v1alpha2.KubeSchedulerConfiguration{
- AlgorithmSource: v1alpha2.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")},
- HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"),
- MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"),
- DebuggingConfiguration: componentbaseconfig.DebuggingConfiguration{
- EnableProfiling: &enable,
- EnableContentionProfiling: &enable,
- },
- LeaderElection: v1alpha2.KubeSchedulerLeaderElectionConfiguration{
- LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{
- LeaderElect: pointer.BoolPtr(true),
- LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
- RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
- RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
- ResourceLock: "endpointsleases",
- ResourceNamespace: "kube-system",
- ResourceName: "kube-scheduler",
- },
- },
- ClientConnection: componentbaseconfig.ClientConnectionConfiguration{
- QPS: 50,
- Burst: 100,
- ContentType: "application/vnd.kubernetes.protobuf",
- },
- DisablePreemption: pointer.BoolPtr(false),
- PercentageOfNodesToScore: pointer.Int32Ptr(0),
- BindTimeoutSeconds: pointer.Int64Ptr(600),
- PodInitialBackoffSeconds: pointer.Int64Ptr(1),
- PodMaxBackoffSeconds: pointer.Int64Ptr(10),
- Profiles: []v1alpha2.KubeSchedulerProfile{
- {SchedulerName: pointer.StringPtr("default-scheduler")},
- },
- },
- },
- }
- for _, tc := range tests {
- t.Run(tc.name, func(t *testing.T) {
- SetDefaults_KubeSchedulerConfiguration(tc.config)
- if diff := cmp.Diff(tc.expected, tc.config); diff != "" {
- t.Errorf("Got unexpected defaults (-want, +got):\n%s", diff)
- }
- })
- }
- }
|