Remove deprecated fields from kubescheduler.config.k8s.io/v1alpha2

Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
Aldo Culquicondor 2020-02-06 15:21:33 -05:00
parent 6858c25ee4
commit 1071eb89f3
7 changed files with 31 additions and 303 deletions

View File

@ -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",

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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 {

View File

@ -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,

View File

@ -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 {

View File

@ -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