diff --git a/pkg/scheduler/apis/config/v1alpha2/BUILD b/pkg/scheduler/apis/config/v1alpha2/BUILD index faa59026430..310bb455145 100644 --- a/pkg/scheduler/apis/config/v1alpha2/BUILD +++ b/pkg/scheduler/apis/config/v1alpha2/BUILD @@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = [ - "conversion.go", "defaults.go", "doc.go", "register.go", @@ -27,16 +26,10 @@ go_library( go_test( name = "go_default_test", - srcs = [ - "conversion_test.go", - "defaults_test.go", - ], + srcs = ["defaults_test.go"], embed = [":go_default_library"], deps = [ - "//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/component-base/config:go_default_library", "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", diff --git a/pkg/scheduler/apis/config/v1alpha2/conversion.go b/pkg/scheduler/apis/config/v1alpha2/conversion.go deleted file mode 100644 index 5d31f7a1627..00000000000 --- a/pkg/scheduler/apis/config/v1alpha2/conversion.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -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 ( - "fmt" - - "k8s.io/apimachinery/pkg/conversion" - "k8s.io/kube-scheduler/config/v1alpha2" - "k8s.io/kubernetes/pkg/scheduler/apis/config" -) - -// Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. -func Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha2.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { - if err := autoConvert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil { - return err - } - if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) == 0 { - out.ResourceNamespace = in.ResourceNamespace - } else if len(in.ResourceNamespace) == 0 && len(in.LockObjectNamespace) > 0 { - out.ResourceNamespace = in.LockObjectNamespace - } else if len(in.ResourceNamespace) > 0 && len(in.LockObjectNamespace) > 0 { - if in.ResourceNamespace == in.LockObjectNamespace { - out.ResourceNamespace = in.ResourceNamespace - } else { - return fmt.Errorf("ResourceNamespace and LockObjectNamespace are both set and do not match, ResourceNamespace: %s, LockObjectNamespace: %s", in.ResourceNamespace, in.LockObjectNamespace) - } - } - - if len(in.ResourceName) > 0 && len(in.LockObjectName) == 0 { - out.ResourceName = in.ResourceName - } else if len(in.ResourceName) == 0 && len(in.LockObjectName) > 0 { - out.ResourceName = in.LockObjectName - } else if len(in.ResourceName) > 0 && len(in.LockObjectName) > 0 { - if in.ResourceName == in.LockObjectName { - out.ResourceName = in.ResourceName - } else { - return fmt.Errorf("ResourceName and LockObjectName are both set and do not match, ResourceName: %s, LockObjectName: %s", in.ResourceName, in.LockObjectName) - } - } - return nil -} - -// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. -func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha2.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { - if err := autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in, out, s); err != nil { - return err - } - out.ResourceNamespace = in.ResourceNamespace - out.LockObjectNamespace = in.ResourceNamespace - out.ResourceName = in.ResourceName - out.LockObjectName = in.ResourceName - return nil -} diff --git a/pkg/scheduler/apis/config/v1alpha2/conversion_test.go b/pkg/scheduler/apis/config/v1alpha2/conversion_test.go deleted file mode 100644 index 4767b5777c9..00000000000 --- a/pkg/scheduler/apis/config/v1alpha2/conversion_test.go +++ /dev/null @@ -1,193 +0,0 @@ -/* -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" - - "k8s.io/apimachinery/pkg/conversion" - componentbaseconfig "k8s.io/component-base/config" - componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" - "k8s.io/kube-scheduler/config/v1alpha2" - "k8s.io/kubernetes/pkg/scheduler/apis/config" -) - -func TestV1alpha1ToConfigKubeSchedulerLeaderElectionConfiguration(t *testing.T) { - configuration := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{ - LockObjectName: "name", - LockObjectNamespace: "namespace", - LeaderElectionConfiguration: componentbaseconfigv1alpha1.LeaderElectionConfiguration{ - ResourceName: "name", - ResourceNamespace: "namespace", - }, - } - emptyLockObjectNameConfig := configuration.DeepCopy() - emptyLockObjectNameConfig.LockObjectName = "" - - emptyLockObjectNamespaceConfig := configuration.DeepCopy() - emptyLockObjectNamespaceConfig.LockObjectNamespace = "" - - emptyResourceNameConfig := configuration.DeepCopy() - emptyResourceNameConfig.ResourceName = "" - - emptyResourceNamespaceConfig := configuration.DeepCopy() - emptyResourceNamespaceConfig.ResourceNamespace = "" - - differentNameConfig := configuration.DeepCopy() - differentNameConfig.LockObjectName = "name1" - - differentNamespaceConfig := configuration.DeepCopy() - differentNamespaceConfig.LockObjectNamespace = "namespace1" - - emptyconfig := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{} - - scenarios := map[string]struct { - expectedResourceNamespace string - expectedResourceName string - expectedToFailed bool - config *v1alpha2.KubeSchedulerLeaderElectionConfiguration - }{ - "both-set-same-name-and-namespace": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedToFailed: false, - config: configuration, - }, - "not-set-lock-object-name": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedToFailed: false, - config: emptyLockObjectNameConfig, - }, - "not-set-lock-object-namespace": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedToFailed: false, - config: emptyLockObjectNamespaceConfig, - }, - "not-set-resource-name": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedToFailed: false, - config: emptyResourceNameConfig, - }, - "not-set-resource-namespace": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedToFailed: false, - config: emptyResourceNamespaceConfig, - }, - "set-different-name": { - expectedResourceNamespace: "", - expectedResourceName: "", - expectedToFailed: true, - config: differentNameConfig, - }, - "set-different-namespace": { - expectedResourceNamespace: "", - expectedResourceName: "", - expectedToFailed: true, - config: differentNamespaceConfig, - }, - "set-empty-name-and-namespace": { - expectedResourceNamespace: "", - expectedResourceName: "", - expectedToFailed: false, - config: emptyconfig, - }, - } - for name, scenario := range scenarios { - out := &config.KubeSchedulerLeaderElectionConfiguration{} - s := conversion.Scope(nil) - err := Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(scenario.config, out, s) - if err == nil && scenario.expectedToFailed { - t.Errorf("Unexpected success for scenario: %s", name) - } - if err == nil && !scenario.expectedToFailed { - if out.ResourceName != scenario.expectedResourceName { - t.Errorf("Unexpected success for scenario: %s, out.ResourceName: %s, expectedResourceName: %s", name, out.ResourceName, scenario.expectedResourceName) - } - if out.ResourceNamespace != scenario.expectedResourceNamespace { - t.Errorf("Unexpected success for scenario: %s, out.ResourceNamespace: %s, expectedResourceNamespace: %s", name, out.ResourceNamespace, scenario.expectedResourceNamespace) - } - } - if err != nil && !scenario.expectedToFailed { - t.Errorf("Unexpected failure for scenario: %s - %+v", name, err) - } - } -} - -func TestConfigToV1alpha1KubeSchedulerLeaderElectionConfiguration(t *testing.T) { - configuration := &config.KubeSchedulerLeaderElectionConfiguration{ - LeaderElectionConfiguration: componentbaseconfig.LeaderElectionConfiguration{ - ResourceName: "name", - ResourceNamespace: "namespace", - }, - } - emptyconfig := &config.KubeSchedulerLeaderElectionConfiguration{} - - scenarios := map[string]struct { - expectedResourceNamespace string - expectedResourceName string - expectedLockObjectNamespace string - expectedLockObjectName string - expectedToFailed bool - config *config.KubeSchedulerLeaderElectionConfiguration - }{ - "both-set-name-and-namespace": { - expectedResourceNamespace: "namespace", - expectedResourceName: "name", - expectedLockObjectNamespace: "namespace", - expectedLockObjectName: "name", - expectedToFailed: false, - config: configuration, - }, - "set-empty-name-and-namespace": { - expectedResourceNamespace: "", - expectedResourceName: "", - expectedLockObjectNamespace: "", - expectedLockObjectName: "", - expectedToFailed: false, - config: emptyconfig, - }, - } - for name, scenario := range scenarios { - out := &v1alpha2.KubeSchedulerLeaderElectionConfiguration{} - s := conversion.Scope(nil) - err := Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(scenario.config, out, s) - if err == nil && scenario.expectedToFailed { - t.Errorf("Unexpected success for scenario: %s", name) - } - if err == nil && !scenario.expectedToFailed { - if out.ResourceName != scenario.expectedResourceName { - t.Errorf("Unexpected success for scenario: %s, out.ResourceName: %s, expectedResourceName: %s", name, out.ResourceName, scenario.expectedResourceName) - } - if out.LockObjectName != scenario.expectedLockObjectName { - t.Errorf("Unexpected success for scenario: %s, out.LockObjectName: %s, expectedLockObjectName: %s", name, out.LockObjectName, scenario.expectedLockObjectName) - } - if out.ResourceNamespace != scenario.expectedResourceNamespace { - t.Errorf("Unexpected success for scenario: %s, out.ResourceNamespace: %s, expectedResourceNamespace: %s", name, out.ResourceNamespace, scenario.expectedResourceNamespace) - } - if out.LockObjectNamespace != scenario.expectedLockObjectNamespace { - t.Errorf("Unexpected success for scenario: %s, out.LockObjectNamespace: %s, expectedLockObjectNamespace: %s", name, out.LockObjectNamespace, scenario.expectedLockObjectNamespace) - } - } - if err != nil && !scenario.expectedToFailed { - t.Errorf("Unexpected failure for scenario: %s - %+v", name, err) - } - } -} diff --git a/pkg/scheduler/apis/config/v1alpha2/defaults.go b/pkg/scheduler/apis/config/v1alpha2/defaults.go index 218cbee7064..a5c371d0bd9 100644 --- a/pkg/scheduler/apis/config/v1alpha2/defaults.go +++ b/pkg/scheduler/apis/config/v1alpha2/defaults.go @@ -121,11 +121,11 @@ func SetDefaults_KubeSchedulerConfiguration(obj *v1alpha2.KubeSchedulerConfigura if len(obj.LeaderElection.ResourceLock) == 0 { obj.LeaderElection.ResourceLock = "endpointsleases" } - if len(obj.LeaderElection.LockObjectNamespace) == 0 && len(obj.LeaderElection.ResourceNamespace) == 0 { - obj.LeaderElection.LockObjectNamespace = v1alpha2.SchedulerDefaultLockObjectNamespace + if len(obj.LeaderElection.ResourceNamespace) == 0 { + obj.LeaderElection.ResourceNamespace = v1alpha2.SchedulerDefaultLockObjectNamespace } - if len(obj.LeaderElection.LockObjectName) == 0 && len(obj.LeaderElection.ResourceName) == 0 { - obj.LeaderElection.LockObjectName = v1alpha2.SchedulerDefaultLockObjectName + if len(obj.LeaderElection.ResourceName) == 0 { + obj.LeaderElection.ResourceName = v1alpha2.SchedulerDefaultLockObjectName } if len(obj.ClientConnection.ContentType) == 0 { diff --git a/pkg/scheduler/apis/config/v1alpha2/defaults_test.go b/pkg/scheduler/apis/config/v1alpha2/defaults_test.go index f60d9e2842b..6bbdccc7df5 100644 --- a/pkg/scheduler/apis/config/v1alpha2/defaults_test.go +++ b/pkg/scheduler/apis/config/v1alpha2/defaults_test.go @@ -54,11 +54,9 @@ func TestSchedulerDefaults(t *testing.T) { RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, ResourceLock: "endpointsleases", - ResourceNamespace: "", - ResourceName: "", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", }, - LockObjectName: "kube-scheduler", - LockObjectNamespace: "kube-system", }, ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ QPS: 50, @@ -96,11 +94,9 @@ func TestSchedulerDefaults(t *testing.T) { RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, ResourceLock: "endpointsleases", - ResourceNamespace: "", - ResourceName: "", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", }, - LockObjectName: "kube-scheduler", - LockObjectNamespace: "kube-system", }, ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ QPS: 50, @@ -138,11 +134,9 @@ func TestSchedulerDefaults(t *testing.T) { RenewDeadline: metav1.Duration{Duration: 10 * time.Second}, RetryPeriod: metav1.Duration{Duration: 2 * time.Second}, ResourceLock: "endpointsleases", - ResourceNamespace: "", - ResourceName: "", + ResourceNamespace: "kube-system", + ResourceName: "kube-scheduler", }, - LockObjectName: "kube-scheduler", - LockObjectNamespace: "kube-system", }, ClientConnection: componentbaseconfig.ClientConnectionConfiguration{ QPS: 50, diff --git a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go index 097461bc2c4..e327791177a 100644 --- a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go @@ -48,6 +48,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1alpha2.KubeSchedulerLeaderElectionConfiguration)(nil), (*config.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(a.(*v1alpha2.KubeSchedulerLeaderElectionConfiguration), b.(*config.KubeSchedulerLeaderElectionConfiguration), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.KubeSchedulerLeaderElectionConfiguration)(nil), (*v1alpha2.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(a.(*config.KubeSchedulerLeaderElectionConfiguration), b.(*v1alpha2.KubeSchedulerLeaderElectionConfiguration), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v1alpha2.Plugin)(nil), (*config.Plugin)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_Plugin_To_config_Plugin(a.(*v1alpha2.Plugin), b.(*config.Plugin), scope) }); err != nil { @@ -128,16 +138,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddConversionFunc((*config.KubeSchedulerLeaderElectionConfiguration)(nil), (*v1alpha2.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(a.(*config.KubeSchedulerLeaderElectionConfiguration), b.(*v1alpha2.KubeSchedulerLeaderElectionConfiguration), scope) - }); err != nil { - return err - } - if err := s.AddConversionFunc((*v1alpha2.KubeSchedulerLeaderElectionConfiguration)(nil), (*config.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(a.(*v1alpha2.KubeSchedulerLeaderElectionConfiguration), b.(*config.KubeSchedulerLeaderElectionConfiguration), scope) - }); err != nil { - return err - } return nil } @@ -261,11 +261,14 @@ func autoConvert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_Kub if err := v1alpha1.Convert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfiguration(&in.LeaderElectionConfiguration, &out.LeaderElectionConfiguration, s); err != nil { return err } - // WARNING: in.LockObjectNamespace requires manual conversion: does not exist in peer-type - // WARNING: in.LockObjectName requires manual conversion: does not exist in peer-type return nil } +// Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. +func Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in *v1alpha2.KubeSchedulerLeaderElectionConfiguration, out *config.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { + return autoConvert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(in, out, s) +} + func autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha2.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { if err := v1alpha1.Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(&in.LeaderElectionConfiguration, &out.LeaderElectionConfiguration, s); err != nil { return err @@ -273,6 +276,11 @@ func autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_Kub return nil } +// Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration is an autogenerated conversion function. +func Convert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in *config.KubeSchedulerLeaderElectionConfiguration, out *v1alpha2.KubeSchedulerLeaderElectionConfiguration, s conversion.Scope) error { + return autoConvert_config_KubeSchedulerLeaderElectionConfiguration_To_v1alpha2_KubeSchedulerLeaderElectionConfiguration(in, out, s) +} + func autoConvert_v1alpha2_Plugin_To_config_Plugin(in *v1alpha2.Plugin, out *config.Plugin, s conversion.Scope) error { out.Name = in.Name if err := v1.Convert_Pointer_int32_To_int32(&in.Weight, &out.Weight, s); err != nil { diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go index 92991e087c5..b05aa908f45 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go @@ -146,12 +146,6 @@ type SchedulerPolicyConfigMapSource struct { // to include scheduler specific configuration. type KubeSchedulerLeaderElectionConfiguration struct { componentbaseconfigv1alpha1.LeaderElectionConfiguration `json:",inline"` - // LockObjectNamespace defines the namespace of the lock object - // DEPRECATED: will be removed in favor of resourceNamespace - LockObjectNamespace string `json:"lockObjectNamespace"` - // LockObjectName defines the lock object name - // DEPRECATED: will be removed in favor of resourceName - LockObjectName string `json:"lockObjectName"` } // Plugins include multiple extension points. When specified, the list of plugins for