diff --git a/cmd/kube-scheduler/app/options/options_test.go b/cmd/kube-scheduler/app/options/options_test.go index 325eec3e215..ec7a2614b76 100644 --- a/cmd/kube-scheduler/app/options/options_test.go +++ b/cmd/kube-scheduler/app/options/options_test.go @@ -277,9 +277,10 @@ pluginConfig: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, - PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, - PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, Plugins: nil, }, }, @@ -359,14 +360,20 @@ pluginConfig: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, - PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, - PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, }, }, { name: "overridden master", options: &Options{ + ComponentConfig: func() kubeschedulerconfig.KubeSchedulerConfiguration { + cfg, _ := newDefaultComponentConfig() + cfg.ClientConnection.Kubeconfig = flagKubeconfig + return *cfg + }(), Master: insecureserver.URL, SecureServing: (&apiserveroptions.SecureServingOptions{ ServerCert: apiserveroptions.GeneratableKeyCert{ @@ -391,6 +398,34 @@ pluginConfig: AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/* }, }, + expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{ + SchedulerName: "default-scheduler", + AlgorithmSource: kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &defaultSource}, + HardPodAffinitySymmetricWeight: 1, + HealthzBindAddress: "", // defaults empty when not running from config file + MetricsBindAddress: "", // defaults empty when not running from config file + LeaderElection: kubeschedulerconfig.KubeSchedulerLeaderElectionConfiguration{ + LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{ + LeaderElect: 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{ + Kubeconfig: flagKubeconfig, + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, + }, expectedUsername: "none, http", }, { @@ -422,9 +457,10 @@ pluginConfig: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, - PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, - PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, Plugins: &kubeschedulerconfig.Plugins{ Reserve: &kubeschedulerconfig.PluginSet{ Enabled: []kubeschedulerconfig.Plugin{ @@ -499,9 +535,10 @@ pluginConfig: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, - PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, - PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, Plugins: nil, }, }, @@ -537,9 +574,10 @@ pluginConfig: Burst: 100, ContentType: "application/vnd.kubernetes.protobuf", }, - BindTimeoutSeconds: &defaultBindTimeoutSeconds, - PodInitialBackoffSeconds: &defaultPodInitialBackoffSeconds, - PodMaxBackoffSeconds: &defaultPodMaxBackoffSeconds, + PercentageOfNodesToScore: 50, + BindTimeoutSeconds: defaultBindTimeoutSeconds, + PodInitialBackoffSeconds: defaultPodInitialBackoffSeconds, + PodMaxBackoffSeconds: defaultPodMaxBackoffSeconds, Plugins: nil, }, }, diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 84604746604..2134db59fb6 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -193,12 +193,12 @@ func Run(ctx context.Context, cc schedulerserverconfig.CompletedConfig, outOfTre scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight), scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption), scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore), - scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds), + scheduler.WithBindTimeoutSeconds(cc.ComponentConfig.BindTimeoutSeconds), scheduler.WithFrameworkOutOfTreeRegistry(outOfTreeRegistry), scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins), scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig), - scheduler.WithPodMaxBackoffSeconds(*cc.ComponentConfig.PodMaxBackoffSeconds), - scheduler.WithPodInitialBackoffSeconds(*cc.ComponentConfig.PodInitialBackoffSeconds), + scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds), + scheduler.WithPodInitialBackoffSeconds(cc.ComponentConfig.PodInitialBackoffSeconds), ) if err != nil { return err diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index 87e7c3603e3..dfeb93e6c95 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -88,17 +88,17 @@ type KubeSchedulerConfiguration struct { // Duration to wait for a binding operation to complete before timing out // Value must be non-negative integer. The value zero indicates no waiting. // If this value is nil, the default value will be used. - BindTimeoutSeconds *int64 + BindTimeoutSeconds int64 // PodInitialBackoffSeconds is the initial backoff for unschedulable pods. // If specified, it must be greater than 0. If this value is null, the default value (1s) // will be used. - PodInitialBackoffSeconds *int64 + PodInitialBackoffSeconds int64 // PodMaxBackoffSeconds is the max backoff for unschedulable pods. // If specified, it must be greater than podInitialBackoffSeconds. If this value is null, // the default value (10s) will be used. - PodMaxBackoffSeconds *int64 + PodMaxBackoffSeconds int64 // Plugins specify the set of plugins that should be enabled or disabled. Enabled plugins are the // ones that should be enabled in addition to the default plugins. Disabled plugins are any of the diff --git a/pkg/scheduler/apis/config/v1alpha1/BUILD b/pkg/scheduler/apis/config/v1alpha1/BUILD index f32f086017d..a020af102be 100644 --- a/pkg/scheduler/apis/config/v1alpha1/BUILD +++ b/pkg/scheduler/apis/config/v1alpha1/BUILD @@ -17,6 +17,7 @@ go_library( "//pkg/apis/core:go_default_library", "//pkg/master/ports:go_default_library", "//pkg/scheduler/apis/config:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", @@ -34,13 +35,12 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/scheduler/apis/config:go_default_library", - "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/component-base/config:go_default_library", "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1alpha1:go_default_library", + "//vendor/k8s.io/utils/pointer:go_default_library", ], ) diff --git a/pkg/scheduler/apis/config/v1alpha1/defaults.go b/pkg/scheduler/apis/config/v1alpha1/defaults.go index f7e61ce9cbb..73a24e96522 100644 --- a/pkg/scheduler/apis/config/v1alpha1/defaults.go +++ b/pkg/scheduler/apis/config/v1alpha1/defaults.go @@ -27,6 +27,7 @@ import ( // this package shouldn't really depend on other k8s.io/kubernetes code api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/master/ports" + "k8s.io/kubernetes/pkg/scheduler/apis/config" ) func addDefaultingFuncs(scheme *runtime.Scheme) error { @@ -35,12 +36,14 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error { // SetDefaults_KubeSchedulerConfiguration sets additional defaults func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration) { - if len(obj.SchedulerName) == 0 { - obj.SchedulerName = api.DefaultSchedulerName + if obj.SchedulerName == nil { + val := api.DefaultSchedulerName + obj.SchedulerName = &val } - if obj.HardPodAffinitySymmetricWeight == 0 { - obj.HardPodAffinitySymmetricWeight = api.DefaultHardPodAffinitySymmetricWeight + if obj.HardPodAffinitySymmetricWeight == nil { + val := api.DefaultHardPodAffinitySymmetricWeight + obj.HardPodAffinitySymmetricWeight = &val } if obj.AlgorithmSource.Policy == nil && @@ -55,22 +58,64 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.Kub } } - if host, port, err := net.SplitHostPort(obj.HealthzBindAddress); err == nil { - if len(host) == 0 { - host = "0.0.0.0" - } - obj.HealthzBindAddress = net.JoinHostPort(host, port) + // For Healthz and Metrics bind addresses, we want to check: + // 1. If the value is nil, default to 0.0.0.0 and default scheduler port + // 2. If there is a value set, attempt to split it. If it's just a port (ie, ":1234"), default to 0.0.0.0 with that port + // 3. If splitting the value fails, check if the value is even a valid IP. If so, use that with the default port. + // Otherwise use the default bind address + defaultBindAddress := net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort)) + if obj.HealthzBindAddress == nil { + obj.HealthzBindAddress = &defaultBindAddress } else { - obj.HealthzBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort)) + if host, port, err := net.SplitHostPort(*obj.HealthzBindAddress); err == nil { + if len(host) == 0 { + host = "0.0.0.0" + } + hostPort := net.JoinHostPort(host, port) + obj.HealthzBindAddress = &hostPort + } else { + // Something went wrong splitting the host/port, could just be a missing port so check if the + // existing value is a valid IP address. If so, use that with the default scheduler port + if host := net.ParseIP(*obj.HealthzBindAddress); host != nil { + hostPort := net.JoinHostPort(*obj.HealthzBindAddress, strconv.Itoa(ports.InsecureSchedulerPort)) + obj.HealthzBindAddress = &hostPort + } else { + // TODO: in v1beta1 we should let this error instead of stomping with a default value + obj.HealthzBindAddress = &defaultBindAddress + } + } } - if host, port, err := net.SplitHostPort(obj.MetricsBindAddress); err == nil { - if len(host) == 0 { - host = "0.0.0.0" - } - obj.MetricsBindAddress = net.JoinHostPort(host, port) + if obj.MetricsBindAddress == nil { + obj.MetricsBindAddress = &defaultBindAddress } else { - obj.MetricsBindAddress = net.JoinHostPort("0.0.0.0", strconv.Itoa(ports.InsecureSchedulerPort)) + if host, port, err := net.SplitHostPort(*obj.MetricsBindAddress); err == nil { + if len(host) == 0 { + host = "0.0.0.0" + } + hostPort := net.JoinHostPort(host, port) + obj.MetricsBindAddress = &hostPort + } else { + // Something went wrong splitting the host/port, could just be a missing port so check if the + // existing value is a valid IP address. If so, use that with the default scheduler port + if host := net.ParseIP(*obj.MetricsBindAddress); host != nil { + hostPort := net.JoinHostPort(*obj.MetricsBindAddress, strconv.Itoa(ports.InsecureSchedulerPort)) + obj.MetricsBindAddress = &hostPort + } else { + // TODO: in v1beta1 we should let this error instead of stomping with a default value + obj.MetricsBindAddress = &defaultBindAddress + } + } + } + + if obj.DisablePreemption == nil { + disablePreemption := false + obj.DisablePreemption = &disablePreemption + } + + if obj.PercentageOfNodesToScore == nil { + percentageOfNodesToScore := int32(config.DefaultPercentageOfNodesToScore) + obj.PercentageOfNodesToScore = &percentageOfNodesToScore } if len(obj.LeaderElection.ResourceLock) == 0 { @@ -98,17 +143,17 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubeschedulerconfigv1alpha1.Kub componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&obj.LeaderElection.LeaderElectionConfiguration) if obj.BindTimeoutSeconds == nil { - defaultBindTimeoutSeconds := int64(600) - obj.BindTimeoutSeconds = &defaultBindTimeoutSeconds + val := int64(600) + obj.BindTimeoutSeconds = &val } if obj.PodInitialBackoffSeconds == nil { - defaultPodInitialBackoffSeconds := int64(1) - obj.PodInitialBackoffSeconds = &defaultPodInitialBackoffSeconds + val := int64(1) + obj.PodInitialBackoffSeconds = &val } if obj.PodMaxBackoffSeconds == nil { - defaultPodMaxBackoffSeconds := int64(10) - obj.PodMaxBackoffSeconds = &defaultPodMaxBackoffSeconds + val := int64(10) + obj.PodMaxBackoffSeconds = &val } } diff --git a/pkg/scheduler/apis/config/v1alpha1/defaults_test.go b/pkg/scheduler/apis/config/v1alpha1/defaults_test.go index 9e55f464f3e..b39eeb18f9c 100644 --- a/pkg/scheduler/apis/config/v1alpha1/defaults_test.go +++ b/pkg/scheduler/apis/config/v1alpha1/defaults_test.go @@ -17,48 +17,140 @@ limitations under the License. package v1alpha1 import ( - "encoding/json" "reflect" "testing" + "time" - "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" + componentbaseconfig "k8s.io/component-base/config/v1alpha1" kubeschedulerconfigv1alpha1 "k8s.io/kube-scheduler/config/v1alpha1" + "k8s.io/utils/pointer" ) func TestSchedulerDefaults(t *testing.T) { - ks1 := &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{} - SetDefaults_KubeSchedulerConfiguration(ks1) - cm, err := convertObjToConfigMap("KubeSchedulerConfiguration", ks1) - if err != nil { - t.Errorf("unexpected ConvertObjToConfigMap error %v", err) - } - - ks2 := &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{} - if err = json.Unmarshal([]byte(cm.Data["KubeSchedulerConfiguration"]), ks2); err != nil { - t.Errorf("unexpected error unserializing scheduler config %v", err) - } - - if !reflect.DeepEqual(ks2, ks1) { - t.Errorf("Expected:\n%#v\n\nGot:\n%#v", ks1, ks2) - } -} - -// ConvertObjToConfigMap converts an object to a ConfigMap. -// This is specifically meant for ComponentConfigs. -func convertObjToConfigMap(name string, obj runtime.Object) (*v1.ConfigMap, error) { - eJSONBytes, err := json.Marshal(obj) - if err != nil { - return nil, err - } - cm := &v1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, + tests := []struct { + name string + config *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration + expected *kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration + }{ + { + name: "empty config", + config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{}, + expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), + HealthzBindAddress: pointer.StringPtr("0.0.0.0:10251"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:10251"), + LeaderElection: kubeschedulerconfigv1alpha1.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: "", + ResourceName: "", + }, + LockObjectName: "kube-scheduler", + LockObjectNamespace: "kube-system", + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + DisablePreemption: pointer.BoolPtr(false), + PercentageOfNodesToScore: pointer.Int32Ptr(50), + BindTimeoutSeconds: pointer.Int64Ptr(600), + PodInitialBackoffSeconds: pointer.Int64Ptr(1), + PodMaxBackoffSeconds: pointer.Int64Ptr(10), + Plugins: nil, + }, }, - Data: map[string]string{ - name: string(eJSONBytes[:]), + { + name: "metrics and healthz address with no port", + config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + MetricsBindAddress: pointer.StringPtr("1.2.3.4"), + HealthzBindAddress: pointer.StringPtr("1.2.3.4"), + }, + expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), + HealthzBindAddress: pointer.StringPtr("1.2.3.4:10251"), + MetricsBindAddress: pointer.StringPtr("1.2.3.4:10251"), + LeaderElection: kubeschedulerconfigv1alpha1.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: "", + ResourceName: "", + }, + LockObjectName: "kube-scheduler", + LockObjectNamespace: "kube-system", + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + DisablePreemption: pointer.BoolPtr(false), + PercentageOfNodesToScore: pointer.Int32Ptr(50), + BindTimeoutSeconds: pointer.Int64Ptr(600), + PodInitialBackoffSeconds: pointer.Int64Ptr(1), + PodMaxBackoffSeconds: pointer.Int64Ptr(10), + Plugins: nil, + }, + }, + { + name: "metrics and healthz port with no address", + config: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + MetricsBindAddress: pointer.StringPtr(":12345"), + HealthzBindAddress: pointer.StringPtr(":12345"), + }, + expected: &kubeschedulerconfigv1alpha1.KubeSchedulerConfiguration{ + SchedulerName: pointer.StringPtr("default-scheduler"), + AlgorithmSource: kubeschedulerconfigv1alpha1.SchedulerAlgorithmSource{Provider: pointer.StringPtr("DefaultProvider")}, + HardPodAffinitySymmetricWeight: pointer.Int32Ptr(1), + HealthzBindAddress: pointer.StringPtr("0.0.0.0:12345"), + MetricsBindAddress: pointer.StringPtr("0.0.0.0:12345"), + LeaderElection: kubeschedulerconfigv1alpha1.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: "", + ResourceName: "", + }, + LockObjectName: "kube-scheduler", + LockObjectNamespace: "kube-system", + }, + ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ + QPS: 50, + Burst: 100, + ContentType: "application/vnd.kubernetes.protobuf", + }, + DisablePreemption: pointer.BoolPtr(false), + PercentageOfNodesToScore: pointer.Int32Ptr(50), + BindTimeoutSeconds: pointer.Int64Ptr(600), + PodInitialBackoffSeconds: pointer.Int64Ptr(1), + PodMaxBackoffSeconds: pointer.Int64Ptr(10), + Plugins: nil, + }, }, } - return cm, nil + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + SetDefaults_KubeSchedulerConfiguration(tc.config) + if !reflect.DeepEqual(tc.expected, tc.config) { + t.Errorf("Expected:\n%#v\n\nGot:\n%#v", tc.expected, tc.config) + } + }) + } } diff --git a/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go index e37bbdf6139..0f1dc00bf5c 100644 --- a/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha1/zz_generated.conversion.go @@ -23,6 +23,7 @@ package v1alpha1 import ( unsafe "unsafe" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" @@ -141,28 +142,54 @@ func RegisterConversions(s *runtime.Scheme) error { } func autoConvert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha1.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error { - out.SchedulerName = in.SchedulerName + if err := v1.Convert_Pointer_string_To_string(&in.SchedulerName, &out.SchedulerName, s); err != nil { + return err + } if err := Convert_v1alpha1_SchedulerAlgorithmSource_To_config_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - out.HardPodAffinitySymmetricWeight = in.HardPodAffinitySymmetricWeight + if err := v1.Convert_Pointer_int32_To_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { + return err + } if err := Convert_v1alpha1_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } if err := componentbaseconfigv1alpha1.Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil { return err } - out.HealthzBindAddress = in.HealthzBindAddress - out.MetricsBindAddress = in.MetricsBindAddress + if err := v1.Convert_Pointer_string_To_string(&in.HealthzBindAddress, &out.HealthzBindAddress, s); err != nil { + return err + } + if err := v1.Convert_Pointer_string_To_string(&in.MetricsBindAddress, &out.MetricsBindAddress, s); err != nil { + return err + } if err := componentbaseconfigv1alpha1.Convert_v1alpha1_DebuggingConfiguration_To_config_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { return err } - out.DisablePreemption = in.DisablePreemption - out.PercentageOfNodesToScore = in.PercentageOfNodesToScore - out.BindTimeoutSeconds = (*int64)(unsafe.Pointer(in.BindTimeoutSeconds)) - out.PodInitialBackoffSeconds = (*int64)(unsafe.Pointer(in.PodInitialBackoffSeconds)) - out.PodMaxBackoffSeconds = (*int64)(unsafe.Pointer(in.PodMaxBackoffSeconds)) - out.Plugins = (*config.Plugins)(unsafe.Pointer(in.Plugins)) + if err := v1.Convert_Pointer_bool_To_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil { + return err + } + if err := v1.Convert_Pointer_int32_To_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil { + return err + } + if err := v1.Convert_Pointer_int64_To_int64(&in.BindTimeoutSeconds, &out.BindTimeoutSeconds, s); err != nil { + return err + } + if err := v1.Convert_Pointer_int64_To_int64(&in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds, s); err != nil { + return err + } + if err := v1.Convert_Pointer_int64_To_int64(&in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds, s); err != nil { + return err + } + if in.Plugins != nil { + in, out := &in.Plugins, &out.Plugins + *out = new(config.Plugins) + if err := Convert_v1alpha1_Plugins_To_config_Plugins(*in, *out, s); err != nil { + return err + } + } else { + out.Plugins = nil + } out.PluginConfig = *(*[]config.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) return nil } @@ -173,28 +200,54 @@ func Convert_v1alpha1_KubeSchedulerConfiguration_To_config_KubeSchedulerConfigur } func autoConvert_config_KubeSchedulerConfiguration_To_v1alpha1_KubeSchedulerConfiguration(in *config.KubeSchedulerConfiguration, out *v1alpha1.KubeSchedulerConfiguration, s conversion.Scope) error { - out.SchedulerName = in.SchedulerName + if err := v1.Convert_string_To_Pointer_string(&in.SchedulerName, &out.SchedulerName, s); err != nil { + return err + } if err := Convert_config_SchedulerAlgorithmSource_To_v1alpha1_SchedulerAlgorithmSource(&in.AlgorithmSource, &out.AlgorithmSource, s); err != nil { return err } - out.HardPodAffinitySymmetricWeight = in.HardPodAffinitySymmetricWeight + if err := v1.Convert_int32_To_Pointer_int32(&in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight, s); err != nil { + return err + } if err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err } if err := componentbaseconfigv1alpha1.Convert_config_ClientConnectionConfiguration_To_v1alpha1_ClientConnectionConfiguration(&in.ClientConnection, &out.ClientConnection, s); err != nil { return err } - out.HealthzBindAddress = in.HealthzBindAddress - out.MetricsBindAddress = in.MetricsBindAddress + if err := v1.Convert_string_To_Pointer_string(&in.HealthzBindAddress, &out.HealthzBindAddress, s); err != nil { + return err + } + if err := v1.Convert_string_To_Pointer_string(&in.MetricsBindAddress, &out.MetricsBindAddress, s); err != nil { + return err + } if err := componentbaseconfigv1alpha1.Convert_config_DebuggingConfiguration_To_v1alpha1_DebuggingConfiguration(&in.DebuggingConfiguration, &out.DebuggingConfiguration, s); err != nil { return err } - out.DisablePreemption = in.DisablePreemption - out.PercentageOfNodesToScore = in.PercentageOfNodesToScore - out.BindTimeoutSeconds = (*int64)(unsafe.Pointer(in.BindTimeoutSeconds)) - out.PodInitialBackoffSeconds = (*int64)(unsafe.Pointer(in.PodInitialBackoffSeconds)) - out.PodMaxBackoffSeconds = (*int64)(unsafe.Pointer(in.PodMaxBackoffSeconds)) - out.Plugins = (*v1alpha1.Plugins)(unsafe.Pointer(in.Plugins)) + if err := v1.Convert_bool_To_Pointer_bool(&in.DisablePreemption, &out.DisablePreemption, s); err != nil { + return err + } + if err := v1.Convert_int32_To_Pointer_int32(&in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore, s); err != nil { + return err + } + if err := v1.Convert_int64_To_Pointer_int64(&in.BindTimeoutSeconds, &out.BindTimeoutSeconds, s); err != nil { + return err + } + if err := v1.Convert_int64_To_Pointer_int64(&in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds, s); err != nil { + return err + } + if err := v1.Convert_int64_To_Pointer_int64(&in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds, s); err != nil { + return err + } + if in.Plugins != nil { + in, out := &in.Plugins, &out.Plugins + *out = new(v1alpha1.Plugins) + if err := Convert_config_Plugins_To_v1alpha1_Plugins(*in, *out, s); err != nil { + return err + } + } else { + out.Plugins = nil + } out.PluginConfig = *(*[]v1alpha1.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) return nil } @@ -222,7 +275,9 @@ func autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha1_Kub func autoConvert_v1alpha1_Plugin_To_config_Plugin(in *v1alpha1.Plugin, out *config.Plugin, s conversion.Scope) error { out.Name = in.Name - out.Weight = in.Weight + if err := v1.Convert_Pointer_int32_To_int32(&in.Weight, &out.Weight, s); err != nil { + return err + } return nil } @@ -233,7 +288,9 @@ func Convert_v1alpha1_Plugin_To_config_Plugin(in *v1alpha1.Plugin, out *config.P func autoConvert_config_Plugin_To_v1alpha1_Plugin(in *config.Plugin, out *v1alpha1.Plugin, s conversion.Scope) error { out.Name = in.Name - out.Weight = in.Weight + if err := v1.Convert_int32_To_Pointer_int32(&in.Weight, &out.Weight, s); err != nil { + return err + } return nil } @@ -265,8 +322,28 @@ func Convert_config_PluginConfig_To_v1alpha1_PluginConfig(in *config.PluginConfi } func autoConvert_v1alpha1_PluginSet_To_config_PluginSet(in *v1alpha1.PluginSet, out *config.PluginSet, s conversion.Scope) error { - out.Enabled = *(*[]config.Plugin)(unsafe.Pointer(&in.Enabled)) - out.Disabled = *(*[]config.Plugin)(unsafe.Pointer(&in.Disabled)) + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = make([]config.Plugin, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_Plugin_To_config_Plugin(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Enabled = nil + } + if in.Disabled != nil { + in, out := &in.Disabled, &out.Disabled + *out = make([]config.Plugin, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_Plugin_To_config_Plugin(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Disabled = nil + } return nil } @@ -276,8 +353,28 @@ func Convert_v1alpha1_PluginSet_To_config_PluginSet(in *v1alpha1.PluginSet, out } func autoConvert_config_PluginSet_To_v1alpha1_PluginSet(in *config.PluginSet, out *v1alpha1.PluginSet, s conversion.Scope) error { - out.Enabled = *(*[]v1alpha1.Plugin)(unsafe.Pointer(&in.Enabled)) - out.Disabled = *(*[]v1alpha1.Plugin)(unsafe.Pointer(&in.Disabled)) + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = make([]v1alpha1.Plugin, len(*in)) + for i := range *in { + if err := Convert_config_Plugin_To_v1alpha1_Plugin(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Enabled = nil + } + if in.Disabled != nil { + in, out := &in.Disabled, &out.Disabled + *out = make([]v1alpha1.Plugin, len(*in)) + for i := range *in { + if err := Convert_config_Plugin_To_v1alpha1_Plugin(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Disabled = nil + } return nil } @@ -287,17 +384,105 @@ func Convert_config_PluginSet_To_v1alpha1_PluginSet(in *config.PluginSet, out *v } func autoConvert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *config.Plugins, s conversion.Scope) error { - out.QueueSort = (*config.PluginSet)(unsafe.Pointer(in.QueueSort)) - out.PreFilter = (*config.PluginSet)(unsafe.Pointer(in.PreFilter)) - out.Filter = (*config.PluginSet)(unsafe.Pointer(in.Filter)) - out.PostFilter = (*config.PluginSet)(unsafe.Pointer(in.PostFilter)) - out.Score = (*config.PluginSet)(unsafe.Pointer(in.Score)) - out.Reserve = (*config.PluginSet)(unsafe.Pointer(in.Reserve)) - out.Permit = (*config.PluginSet)(unsafe.Pointer(in.Permit)) - out.PreBind = (*config.PluginSet)(unsafe.Pointer(in.PreBind)) - out.Bind = (*config.PluginSet)(unsafe.Pointer(in.Bind)) - out.PostBind = (*config.PluginSet)(unsafe.Pointer(in.PostBind)) - out.Unreserve = (*config.PluginSet)(unsafe.Pointer(in.Unreserve)) + if in.QueueSort != nil { + in, out := &in.QueueSort, &out.QueueSort + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.QueueSort = nil + } + if in.PreFilter != nil { + in, out := &in.PreFilter, &out.PreFilter + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PreFilter = nil + } + if in.Filter != nil { + in, out := &in.Filter, &out.Filter + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Filter = nil + } + if in.PostFilter != nil { + in, out := &in.PostFilter, &out.PostFilter + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PostFilter = nil + } + if in.Score != nil { + in, out := &in.Score, &out.Score + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Score = nil + } + if in.Reserve != nil { + in, out := &in.Reserve, &out.Reserve + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Reserve = nil + } + if in.Permit != nil { + in, out := &in.Permit, &out.Permit + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Permit = nil + } + if in.PreBind != nil { + in, out := &in.PreBind, &out.PreBind + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PreBind = nil + } + if in.Bind != nil { + in, out := &in.Bind, &out.Bind + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Bind = nil + } + if in.PostBind != nil { + in, out := &in.PostBind, &out.PostBind + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PostBind = nil + } + if in.Unreserve != nil { + in, out := &in.Unreserve, &out.Unreserve + *out = new(config.PluginSet) + if err := Convert_v1alpha1_PluginSet_To_config_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Unreserve = nil + } return nil } @@ -307,17 +492,105 @@ func Convert_v1alpha1_Plugins_To_config_Plugins(in *v1alpha1.Plugins, out *confi } func autoConvert_config_Plugins_To_v1alpha1_Plugins(in *config.Plugins, out *v1alpha1.Plugins, s conversion.Scope) error { - out.QueueSort = (*v1alpha1.PluginSet)(unsafe.Pointer(in.QueueSort)) - out.PreFilter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PreFilter)) - out.Filter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Filter)) - out.PostFilter = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PostFilter)) - out.Score = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Score)) - out.Reserve = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Reserve)) - out.Permit = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Permit)) - out.PreBind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PreBind)) - out.Bind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Bind)) - out.PostBind = (*v1alpha1.PluginSet)(unsafe.Pointer(in.PostBind)) - out.Unreserve = (*v1alpha1.PluginSet)(unsafe.Pointer(in.Unreserve)) + if in.QueueSort != nil { + in, out := &in.QueueSort, &out.QueueSort + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.QueueSort = nil + } + if in.PreFilter != nil { + in, out := &in.PreFilter, &out.PreFilter + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PreFilter = nil + } + if in.Filter != nil { + in, out := &in.Filter, &out.Filter + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Filter = nil + } + if in.PostFilter != nil { + in, out := &in.PostFilter, &out.PostFilter + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PostFilter = nil + } + if in.Score != nil { + in, out := &in.Score, &out.Score + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Score = nil + } + if in.Reserve != nil { + in, out := &in.Reserve, &out.Reserve + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Reserve = nil + } + if in.Permit != nil { + in, out := &in.Permit, &out.Permit + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Permit = nil + } + if in.PreBind != nil { + in, out := &in.PreBind, &out.PreBind + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PreBind = nil + } + if in.Bind != nil { + in, out := &in.Bind, &out.Bind + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Bind = nil + } + if in.PostBind != nil { + in, out := &in.PostBind, &out.PostBind + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.PostBind = nil + } + if in.Unreserve != nil { + in, out := &in.Unreserve, &out.Unreserve + *out = new(v1alpha1.PluginSet) + if err := Convert_config_PluginSet_To_v1alpha1_PluginSet(*in, *out, s); err != nil { + return err + } + } else { + out.Unreserve = nil + } return nil } diff --git a/pkg/scheduler/apis/config/validation/validation.go b/pkg/scheduler/apis/config/validation/validation.go index b832340f80b..4f705a3b309 100644 --- a/pkg/scheduler/apis/config/validation/validation.go +++ b/pkg/scheduler/apis/config/validation/validation.go @@ -47,22 +47,15 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) f if cc.HardPodAffinitySymmetricWeight < 0 || cc.HardPodAffinitySymmetricWeight > 100 { allErrs = append(allErrs, field.Invalid(field.NewPath("hardPodAffinitySymmetricWeight"), cc.HardPodAffinitySymmetricWeight, "not in valid range 0-100")) } - if cc.BindTimeoutSeconds == nil { - allErrs = append(allErrs, field.Required(field.NewPath("bindTimeoutSeconds"), "")) - } if cc.PercentageOfNodesToScore < 0 || cc.PercentageOfNodesToScore > 100 { allErrs = append(allErrs, field.Invalid(field.NewPath("percentageOfNodesToScore"), cc.PercentageOfNodesToScore, "not in valid range 0-100")) } - if cc.PodInitialBackoffSeconds == nil { - allErrs = append(allErrs, field.Required(field.NewPath("podInitialBackoffSeconds"), "")) - } else if *cc.PodInitialBackoffSeconds <= 0 { + if cc.PodInitialBackoffSeconds <= 0 { allErrs = append(allErrs, field.Invalid(field.NewPath("podInitialBackoffSeconds"), cc.PodInitialBackoffSeconds, "must be greater than 0")) } - if cc.PodMaxBackoffSeconds == nil { - allErrs = append(allErrs, field.Required(field.NewPath("podMaxBackoffSeconds"), "")) - } else if cc.PodInitialBackoffSeconds != nil && *cc.PodMaxBackoffSeconds < *cc.PodInitialBackoffSeconds { + if cc.PodMaxBackoffSeconds < cc.PodInitialBackoffSeconds { allErrs = append(allErrs, field.Invalid(field.NewPath("podMaxBackoffSeconds"), cc.PodMaxBackoffSeconds, "must be greater than or equal to PodInitialBackoffSeconds")) } diff --git a/pkg/scheduler/apis/config/validation/validation_test.go b/pkg/scheduler/apis/config/validation/validation_test.go index 1f6bec50fb6..1ebedacf29e 100644 --- a/pkg/scheduler/apis/config/validation/validation_test.go +++ b/pkg/scheduler/apis/config/validation/validation_test.go @@ -61,9 +61,9 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { ResourceName: "name", }, }, - PodInitialBackoffSeconds: &podInitialBackoffSeconds, - PodMaxBackoffSeconds: &podMaxBackoffSeconds, - BindTimeoutSeconds: &testTimeout, + PodInitialBackoffSeconds: podInitialBackoffSeconds, + PodMaxBackoffSeconds: podMaxBackoffSeconds, + BindTimeoutSeconds: testTimeout, PercentageOfNodesToScore: 35, } @@ -95,9 +95,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true - bindTimeoutUnset := validConfig.DeepCopy() - bindTimeoutUnset.BindTimeoutSeconds = nil - percentageOfNodesToScore101 := validConfig.DeepCopy() percentageOfNodesToScore101.PercentageOfNodesToScore = int32(101) @@ -141,10 +138,6 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) { expectedToFail: true, config: HardPodAffinitySymmetricWeightLt0, }, - "bind-timeout-unset": { - expectedToFail: true, - config: bindTimeoutUnset, - }, "bad-percentage-of-nodes-to-score": { expectedToFail: true, config: percentageOfNodesToScore101, diff --git a/pkg/scheduler/apis/config/zz_generated.deepcopy.go b/pkg/scheduler/apis/config/zz_generated.deepcopy.go index 48ccd164b7c..20b0f03e6e3 100644 --- a/pkg/scheduler/apis/config/zz_generated.deepcopy.go +++ b/pkg/scheduler/apis/config/zz_generated.deepcopy.go @@ -105,21 +105,6 @@ func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfigurati out.LeaderElection = in.LeaderElection out.ClientConnection = in.ClientConnection out.DebuggingConfiguration = in.DebuggingConfiguration - if in.BindTimeoutSeconds != nil { - in, out := &in.BindTimeoutSeconds, &out.BindTimeoutSeconds - *out = new(int64) - **out = **in - } - if in.PodInitialBackoffSeconds != nil { - in, out := &in.PodInitialBackoffSeconds, &out.PodInitialBackoffSeconds - *out = new(int64) - **out = **in - } - if in.PodMaxBackoffSeconds != nil { - in, out := &in.PodMaxBackoffSeconds, &out.PodMaxBackoffSeconds - *out = new(int64) - **out = **in - } if in.Plugins != nil { in, out := &in.Plugins, &out.Plugins *out = new(Plugins) diff --git a/pkg/scheduler/framework/v1alpha1/framework_test.go b/pkg/scheduler/framework/v1alpha1/framework_test.go index 7ff56a931f7..e6d340403e7 100644 --- a/pkg/scheduler/framework/v1alpha1/framework_test.go +++ b/pkg/scheduler/framework/v1alpha1/framework_test.go @@ -26,6 +26,7 @@ import ( "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 9525dd0a701..bc35158979a 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -46,7 +46,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/algorithm" "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates" "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities" - kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/core" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" @@ -192,7 +191,7 @@ func TestSchedulerCreation(t *testing.T) { informerFactory, NewPodInformer(client, 0), eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"), - kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource}, + schedulerapi.SchedulerAlgorithmSource{Provider: &testSource}, stopCh, WithPodInitialBackoffSeconds(1), WithPodMaxBackoffSeconds(10), @@ -693,7 +692,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C } func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, scache internalcache.Cache, informerFactory informers.SharedInformerFactory, predicateMap map[string]predicates.FitPredicate, stop chan struct{}, bindingTime time.Duration) (*Scheduler, chan *v1.Binding) { - fwk, _ := framework.NewFramework(emptyPluginRegistry, nil, []kubeschedulerconfig.PluginConfig{}) + fwk, _ := framework.NewFramework(emptyPluginRegistry, nil, []schedulerapi.PluginConfig{}) algo := core.NewGenericScheduler( scache, internalqueue.NewSchedulingQueue(nil, nil), diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go index 014c9cbf765..2d8fdc82280 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/types.go @@ -41,13 +41,13 @@ type KubeSchedulerConfiguration struct { // SchedulerName is name of the scheduler, used to select which pods // will be processed by this scheduler, based on pod's "spec.SchedulerName". - SchedulerName string `json:"schedulerName"` + SchedulerName *string `json:"schedulerName,omitempty"` // AlgorithmSource specifies the scheduler algorithm source. AlgorithmSource SchedulerAlgorithmSource `json:"algorithmSource"` // RequiredDuringScheduling affinity is not symmetric, but there is an implicit PreferredDuringScheduling affinity rule // corresponding to every RequiredDuringScheduling affinity rule. // HardPodAffinitySymmetricWeight represents the weight of implicit PreferredDuringScheduling affinity rule, in the range 0-100. - HardPodAffinitySymmetricWeight int32 `json:"hardPodAffinitySymmetricWeight"` + HardPodAffinitySymmetricWeight *int32 `json:"hardPodAffinitySymmetricWeight,omitempty"` // LeaderElection defines the configuration of leader election client. LeaderElection KubeSchedulerLeaderElectionConfiguration `json:"leaderElection"` @@ -57,17 +57,17 @@ type KubeSchedulerConfiguration struct { ClientConnection componentbaseconfigv1alpha1.ClientConnectionConfiguration `json:"clientConnection"` // HealthzBindAddress is the IP address and port for the health check server to serve on, // defaulting to 0.0.0.0:10251 - HealthzBindAddress string `json:"healthzBindAddress"` + HealthzBindAddress *string `json:"healthzBindAddress,omitempty"` // MetricsBindAddress is the IP address and port for the metrics server to // serve on, defaulting to 0.0.0.0:10251. - MetricsBindAddress string `json:"metricsBindAddress"` + MetricsBindAddress *string `json:"metricsBindAddress,omitempty"` // DebuggingConfiguration holds configuration for Debugging related features // TODO: We might wanna make this a substruct like Debugging componentbaseconfigv1alpha1.DebuggingConfiguration componentbaseconfigv1alpha1.DebuggingConfiguration `json:",inline"` // DisablePreemption disables the pod preemption feature. - DisablePreemption bool `json:"disablePreemption"` + DisablePreemption *bool `json:"disablePreemption,omitempty"` // PercentageOfNodeToScore is the percentage of all nodes that once found feasible // for running a pod, the scheduler stops its search for more feasible nodes in @@ -77,7 +77,7 @@ type KubeSchedulerConfiguration struct { // then scheduler stops finding further feasible nodes once it finds 150 feasible ones. // When the value is 0, default percentage (5%--50% based on the size of the cluster) of the // nodes will be scored. - PercentageOfNodesToScore int32 `json:"percentageOfNodesToScore"` + PercentageOfNodesToScore *int32 `json:"percentageOfNodesToScore,omitempty"` // Duration to wait for a binding operation to complete before timing out // Value must be non-negative integer. The value zero indicates no waiting. @@ -209,7 +209,7 @@ type Plugin struct { // Name defines the name of plugin Name string `json:"name"` // Weight defines the weight of plugin, only used for Score plugins. - Weight int32 `json:"weight,omitempty"` + Weight *int32 `json:"weight,omitempty"` } // PluginConfig specifies arguments that should be passed to a plugin at the time of initialization. diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/zz_generated.deepcopy.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/zz_generated.deepcopy.go index f04761e7e41..f81f35e5802 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha1/zz_generated.deepcopy.go @@ -28,10 +28,40 @@ import ( func (in *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) { *out = *in out.TypeMeta = in.TypeMeta + if in.SchedulerName != nil { + in, out := &in.SchedulerName, &out.SchedulerName + *out = new(string) + **out = **in + } in.AlgorithmSource.DeepCopyInto(&out.AlgorithmSource) + if in.HardPodAffinitySymmetricWeight != nil { + in, out := &in.HardPodAffinitySymmetricWeight, &out.HardPodAffinitySymmetricWeight + *out = new(int32) + **out = **in + } in.LeaderElection.DeepCopyInto(&out.LeaderElection) out.ClientConnection = in.ClientConnection + if in.HealthzBindAddress != nil { + in, out := &in.HealthzBindAddress, &out.HealthzBindAddress + *out = new(string) + **out = **in + } + if in.MetricsBindAddress != nil { + in, out := &in.MetricsBindAddress, &out.MetricsBindAddress + *out = new(string) + **out = **in + } in.DebuggingConfiguration.DeepCopyInto(&out.DebuggingConfiguration) + if in.DisablePreemption != nil { + in, out := &in.DisablePreemption, &out.DisablePreemption + *out = new(bool) + **out = **in + } + if in.PercentageOfNodesToScore != nil { + in, out := &in.PercentageOfNodesToScore, &out.PercentageOfNodesToScore + *out = new(int32) + **out = **in + } if in.BindTimeoutSeconds != nil { in, out := &in.BindTimeoutSeconds, &out.BindTimeoutSeconds *out = new(int64) @@ -100,6 +130,11 @@ func (in *KubeSchedulerLeaderElectionConfiguration) DeepCopy() *KubeSchedulerLea // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Plugin) DeepCopyInto(out *Plugin) { *out = *in + if in.Weight != nil { + in, out := &in.Weight, &out.Weight + *out = new(int32) + **out = **in + } return } @@ -136,12 +171,16 @@ func (in *PluginSet) DeepCopyInto(out *PluginSet) { if in.Enabled != nil { in, out := &in.Enabled, &out.Enabled *out = make([]Plugin, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.Disabled != nil { in, out := &in.Disabled, &out.Disabled *out = make([]Plugin, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return }