diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index bf35ca4f184..b3f544f74fe 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -796,6 +796,13 @@ const ( // // Allow fine-tuning of cpumanager policies CPUManagerPolicyOptions featuregate.Feature = "CPUManagerPolicyOptions" + + // owner: @jiahuif + // alpha: v1.21 + // beta: v1.22 + // + // Enables Leader Migration for kube-controller-manager and cloud-controller-manager + ControllerManagerLeaderMigration featuregate.Feature = "ControllerManagerLeaderMigration" ) func init() { @@ -914,6 +921,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS KubeletInUserNamespace: {Default: false, PreRelease: featuregate.Alpha}, MemoryQoS: {Default: false, PreRelease: featuregate.Alpha}, CPUManagerPolicyOptions: {Default: false, PreRelease: featuregate.Alpha}, + ControllerManagerLeaderMigration: {Default: true, PreRelease: featuregate.Beta}, // inherited features from generic apiserver, relisted here to get a conflict if it is changed // unintentionally on either side: diff --git a/staging/src/k8s.io/controller-manager/config/v1beta1/doc.go b/staging/src/k8s.io/controller-manager/config/v1beta1/doc.go new file mode 100644 index 00000000000..94cd3f12831 --- /dev/null +++ b/staging/src/k8s.io/controller-manager/config/v1beta1/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2021 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. +*/ + +// +k8s:deepcopy-gen=package +// +k8s:conversion-gen=k8s.io/controller-manager/config +// +k8s:openapi-gen=true +// +groupName=controllermanager.config.k8s.io + +package v1beta1 // import "k8s.io/controller-manager/config/v1beta1" diff --git a/staging/src/k8s.io/controller-manager/config/v1beta1/register.go b/staging/src/k8s.io/controller-manager/config/v1beta1/register.go new file mode 100644 index 00000000000..c812dcd3be9 --- /dev/null +++ b/staging/src/k8s.io/controller-manager/config/v1beta1/register.go @@ -0,0 +1,48 @@ +/* +Copyright 2021 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 v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the "group" that is needed to uniquely identify the API +const GroupName = "controllermanager.config.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + +var ( + // SchemeBuilder is the scheme builder with scheme init functions to run for this API package + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // localSchemeBuilder extends the SchemeBuilder instance with the external types. In this package, + // defaulting and conversion init funcs are registered as well. + localSchemeBuilder = &SchemeBuilder + // AddToScheme is a global function that registers this API group & version to a scheme + AddToScheme = localSchemeBuilder.AddToScheme +) + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &LeaderMigrationConfiguration{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/controller-manager/config/v1beta1/types.go b/staging/src/k8s.io/controller-manager/config/v1beta1/types.go new file mode 100644 index 00000000000..91467c006bc --- /dev/null +++ b/staging/src/k8s.io/controller-manager/config/v1beta1/types.go @@ -0,0 +1,51 @@ +/* +Copyright 2021 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 v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// LeaderMigrationConfiguration provides versioned configuration for all migrating leader locks. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type LeaderMigrationConfiguration struct { + metav1.TypeMeta `json:",inline"` + + // LeaderName is the name of the leader election resource that protects the migration + // E.g. 1-20-KCM-to-1-21-CCM + LeaderName string `json:"leaderName"` + + // ResourceLock indicates the resource object type that will be used to lock + // Should be "leases" or "endpoints" + ResourceLock string `json:"resourceLock"` + + // ControllerLeaders contains a list of migrating leader lock configurations + // +listType=atomic + ControllerLeaders []ControllerLeaderConfiguration `json:"controllerLeaders"` +} + +// ControllerLeaderConfiguration provides the configuration for a migrating leader lock. +type ControllerLeaderConfiguration struct { + // Name is the name of the controller being migrated + // E.g. service-controller, route-controller, cloud-node-controller, etc + Name string `json:"name"` + + // Component is the name of the component in which the controller should be running. + // E.g. kube-controller-manager, cloud-controller-manager, etc + // Or '*' meaning the controller can be run under any component that participates in the migration + Component string `json:"component"` +} diff --git a/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.conversion.go b/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.conversion.go new file mode 100644 index 00000000000..53196691180 --- /dev/null +++ b/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.conversion.go @@ -0,0 +1,105 @@ +// +build !ignore_autogenerated + +/* +Copyright 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. +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v1beta1 + +import ( + unsafe "unsafe" + + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + config "k8s.io/controller-manager/config" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*ControllerLeaderConfiguration)(nil), (*config.ControllerLeaderConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_ControllerLeaderConfiguration_To_config_ControllerLeaderConfiguration(a.(*ControllerLeaderConfiguration), b.(*config.ControllerLeaderConfiguration), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.ControllerLeaderConfiguration)(nil), (*ControllerLeaderConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_ControllerLeaderConfiguration_To_v1beta1_ControllerLeaderConfiguration(a.(*config.ControllerLeaderConfiguration), b.(*ControllerLeaderConfiguration), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*LeaderMigrationConfiguration)(nil), (*config.LeaderMigrationConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_LeaderMigrationConfiguration_To_config_LeaderMigrationConfiguration(a.(*LeaderMigrationConfiguration), b.(*config.LeaderMigrationConfiguration), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.LeaderMigrationConfiguration)(nil), (*LeaderMigrationConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_LeaderMigrationConfiguration_To_v1beta1_LeaderMigrationConfiguration(a.(*config.LeaderMigrationConfiguration), b.(*LeaderMigrationConfiguration), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1beta1_ControllerLeaderConfiguration_To_config_ControllerLeaderConfiguration(in *ControllerLeaderConfiguration, out *config.ControllerLeaderConfiguration, s conversion.Scope) error { + out.Name = in.Name + out.Component = in.Component + return nil +} + +// Convert_v1beta1_ControllerLeaderConfiguration_To_config_ControllerLeaderConfiguration is an autogenerated conversion function. +func Convert_v1beta1_ControllerLeaderConfiguration_To_config_ControllerLeaderConfiguration(in *ControllerLeaderConfiguration, out *config.ControllerLeaderConfiguration, s conversion.Scope) error { + return autoConvert_v1beta1_ControllerLeaderConfiguration_To_config_ControllerLeaderConfiguration(in, out, s) +} + +func autoConvert_config_ControllerLeaderConfiguration_To_v1beta1_ControllerLeaderConfiguration(in *config.ControllerLeaderConfiguration, out *ControllerLeaderConfiguration, s conversion.Scope) error { + out.Name = in.Name + out.Component = in.Component + return nil +} + +// Convert_config_ControllerLeaderConfiguration_To_v1beta1_ControllerLeaderConfiguration is an autogenerated conversion function. +func Convert_config_ControllerLeaderConfiguration_To_v1beta1_ControllerLeaderConfiguration(in *config.ControllerLeaderConfiguration, out *ControllerLeaderConfiguration, s conversion.Scope) error { + return autoConvert_config_ControllerLeaderConfiguration_To_v1beta1_ControllerLeaderConfiguration(in, out, s) +} + +func autoConvert_v1beta1_LeaderMigrationConfiguration_To_config_LeaderMigrationConfiguration(in *LeaderMigrationConfiguration, out *config.LeaderMigrationConfiguration, s conversion.Scope) error { + out.LeaderName = in.LeaderName + out.ResourceLock = in.ResourceLock + out.ControllerLeaders = *(*[]config.ControllerLeaderConfiguration)(unsafe.Pointer(&in.ControllerLeaders)) + return nil +} + +// Convert_v1beta1_LeaderMigrationConfiguration_To_config_LeaderMigrationConfiguration is an autogenerated conversion function. +func Convert_v1beta1_LeaderMigrationConfiguration_To_config_LeaderMigrationConfiguration(in *LeaderMigrationConfiguration, out *config.LeaderMigrationConfiguration, s conversion.Scope) error { + return autoConvert_v1beta1_LeaderMigrationConfiguration_To_config_LeaderMigrationConfiguration(in, out, s) +} + +func autoConvert_config_LeaderMigrationConfiguration_To_v1beta1_LeaderMigrationConfiguration(in *config.LeaderMigrationConfiguration, out *LeaderMigrationConfiguration, s conversion.Scope) error { + out.LeaderName = in.LeaderName + out.ResourceLock = in.ResourceLock + out.ControllerLeaders = *(*[]ControllerLeaderConfiguration)(unsafe.Pointer(&in.ControllerLeaders)) + return nil +} + +// Convert_config_LeaderMigrationConfiguration_To_v1beta1_LeaderMigrationConfiguration is an autogenerated conversion function. +func Convert_config_LeaderMigrationConfiguration_To_v1beta1_LeaderMigrationConfiguration(in *config.LeaderMigrationConfiguration, out *LeaderMigrationConfiguration, s conversion.Scope) error { + return autoConvert_config_LeaderMigrationConfiguration_To_v1beta1_LeaderMigrationConfiguration(in, out, s) +} diff --git a/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..ad70b4862a7 --- /dev/null +++ b/staging/src/k8s.io/controller-manager/config/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,71 @@ +// +build !ignore_autogenerated + +/* +Copyright 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. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1beta1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ControllerLeaderConfiguration) DeepCopyInto(out *ControllerLeaderConfiguration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControllerLeaderConfiguration. +func (in *ControllerLeaderConfiguration) DeepCopy() *ControllerLeaderConfiguration { + if in == nil { + return nil + } + out := new(ControllerLeaderConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LeaderMigrationConfiguration) DeepCopyInto(out *LeaderMigrationConfiguration) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.ControllerLeaders != nil { + in, out := &in.ControllerLeaders, &out.ControllerLeaders + *out = make([]ControllerLeaderConfiguration, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaderMigrationConfiguration. +func (in *LeaderMigrationConfiguration) DeepCopy() *LeaderMigrationConfiguration { + if in == nil { + return nil + } + out := new(LeaderMigrationConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *LeaderMigrationConfiguration) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/staging/src/k8s.io/controller-manager/pkg/features/kube_features.go b/staging/src/k8s.io/controller-manager/pkg/features/kube_features.go index a22352d91fc..8a3910361c0 100644 --- a/staging/src/k8s.io/controller-manager/pkg/features/kube_features.go +++ b/staging/src/k8s.io/controller-manager/pkg/features/kube_features.go @@ -36,8 +36,10 @@ const ( // owner: @jiahuif // alpha: v1.21 + // beta: v1.22 // // Enables Leader Migration for kube-controller-manager and cloud-controller-manager + // copied and sync'ed from k8s.io/kubernetes/pkg/features/kube_features.go ControllerManagerLeaderMigration featuregate.Feature = "ControllerManagerLeaderMigration" ) @@ -49,5 +51,5 @@ func SetupCurrentKubernetesSpecificFeatureGates(featuregates featuregate.Mutable // To add a new feature, define a key for it at k8s.io/api/pkg/features and add it here. var cloudPublicFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ IPv6DualStack: {Default: true, PreRelease: featuregate.Beta}, - ControllerManagerLeaderMigration: {Default: false, PreRelease: featuregate.Alpha}, + ControllerManagerLeaderMigration: {Default: true, PreRelease: featuregate.Beta}, } diff --git a/staging/src/k8s.io/controller-manager/pkg/leadermigration/config/config.go b/staging/src/k8s.io/controller-manager/pkg/leadermigration/config/config.go index 3e697dbf455..9cecdbafff2 100644 --- a/staging/src/k8s.io/controller-manager/pkg/leadermigration/config/config.go +++ b/staging/src/k8s.io/controller-manager/pkg/leadermigration/config/config.go @@ -26,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" internal "k8s.io/controller-manager/config" "k8s.io/controller-manager/config/v1alpha1" + "k8s.io/controller-manager/config/v1beta1" ) // ResourceLockLeases is the resourceLock value for 'leases' API @@ -43,6 +44,10 @@ func init() { // v1alpha1 util.Must(v1alpha1.AddToScheme(cfgScheme)) util.Must(cfgScheme.SetVersionPriority(v1alpha1.SchemeGroupVersion)) + + // v1beta1 + util.Must(v1beta1.AddToScheme(cfgScheme)) + util.Must(cfgScheme.SetVersionPriority(v1beta1.SchemeGroupVersion)) } // ReadLeaderMigrationConfiguration reads LeaderMigrationConfiguration from a YAML file at the given path. diff --git a/staging/src/k8s.io/controller-manager/pkg/leadermigration/options/options_test.go b/staging/src/k8s.io/controller-manager/pkg/leadermigration/options/options_test.go index 59af7ee1ae3..5bcba5e480e 100644 --- a/staging/src/k8s.io/controller-manager/pkg/leadermigration/options/options_test.go +++ b/staging/src/k8s.io/controller-manager/pkg/leadermigration/options/options_test.go @@ -72,6 +72,25 @@ kind: LeaderMigrationConfiguration leaderName: test-leader-migration resourceLock: leases controllerLeaders: [] +`, + expectErr: false, + expectConfig: &config.LeaderMigrationConfiguration{ + LeaderName: "test-leader-migration", + ResourceLock: "leases", + ControllerLeaders: []config.ControllerLeaderConfiguration{}, + }, + }, + { + name: "enabled, with custom configuration file (version v1beta1)", + flags: []string{"--enable-leader-migration"}, + enableFeatureGate: true, + expectEnabled: true, + configContent: ` +apiVersion: controllermanager.config.k8s.io/v1beta1 +kind: LeaderMigrationConfiguration +leaderName: test-leader-migration +resourceLock: leases +controllerLeaders: [] `, expectErr: false, expectConfig: &config.LeaderMigrationConfiguration{ diff --git a/vendor/modules.txt b/vendor/modules.txt index 2b313ce95a4..dcea9add904 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1961,6 +1961,7 @@ k8s.io/component-helpers/storage/volume k8s.io/controller-manager/app k8s.io/controller-manager/config k8s.io/controller-manager/config/v1alpha1 +k8s.io/controller-manager/config/v1beta1 k8s.io/controller-manager/options k8s.io/controller-manager/pkg/clientbuilder k8s.io/controller-manager/pkg/features