From 0ce7b688a65a65031c6ee8c616989e4b0be4ce9f Mon Sep 17 00:00:00 2001 From: Jefftree Date: Fri, 4 Oct 2024 14:43:11 +0000 Subject: [PATCH] v1alpha2 LeaseCandidate API --- .../app/controllermanager.go | 2 +- cmd/kube-scheduler/app/server.go | 2 +- hack/lib/init.sh | 2 +- pkg/apis/coordination/install/install.go | 6 +- pkg/apis/coordination/types.go | 18 +- .../v1alpha1/zz_generated.conversion.go | 151 --- .../v1alpha1/zz_generated.defaults.go | 33 - .../{v1alpha1 => v1alpha2}/doc.go | 6 +- .../{v1alpha1 => v1alpha2}/register.go | 8 +- .../coordination/validation/validation.go | 35 +- .../validation/validation_test.go | 56 +- pkg/controlplane/apiserver/aggregator.go | 2 +- pkg/controlplane/apiserver/server.go | 4 +- .../controller/leaderelection/election.go | 94 +- .../leaderelection/election_test.go | 419 ++++--- .../leaderelection_controller.go | 22 +- .../leaderelection_controller_test.go | 288 ++--- .../leasecandidategc_controller.go | 12 +- .../leasecandidategc_controller_test.go | 62 +- pkg/controlplane/instance.go | 4 +- .../default_storage_factory_builder.go | 2 +- pkg/printers/internalversion/printers.go | 4 +- .../coordination/rest/storage_coordination.go | 10 +- .../api/coordination/v1alpha1/generated.pb.go | 1036 ----------------- .../api/coordination/v1alpha1/generated.proto | 105 -- .../v1alpha1/types_swagger_doc_generated.go | 64 - .../v1alpha1/zz_generated.deepcopy.go | 116 -- .../zz_generated.prerelease-lifecycle.go | 58 - .../{v1alpha1 => v1alpha2}/doc.go | 2 +- .../{v1alpha1 => v1alpha2}/register.go | 6 +- .../{v1alpha1 => v1alpha2}/types.go | 29 +- staging/src/k8s.io/api/roundtrip_test.go | 4 +- .../tools/leaderelection/leasecandidate.go | 32 +- .../leaderelection/leasecandidate_test.go | 10 +- .../coordinated_leader_election_test.go | 24 +- test/integration/etcd/data.go | 8 +- 36 files changed, 559 insertions(+), 2177 deletions(-) delete mode 100644 pkg/apis/coordination/v1alpha1/zz_generated.conversion.go delete mode 100644 pkg/apis/coordination/v1alpha1/zz_generated.defaults.go rename pkg/apis/coordination/{v1alpha1 => v1alpha2}/doc.go (83%) rename pkg/apis/coordination/{v1alpha1 => v1alpha2}/register.go (90%) delete mode 100644 staging/src/k8s.io/api/coordination/v1alpha1/generated.pb.go delete mode 100644 staging/src/k8s.io/api/coordination/v1alpha1/generated.proto delete mode 100644 staging/src/k8s.io/api/coordination/v1alpha1/types_swagger_doc_generated.go delete mode 100644 staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.deepcopy.go delete mode 100644 staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.prerelease-lifecycle.go rename staging/src/k8s.io/api/coordination/{v1alpha1 => v1alpha2}/doc.go (92%) rename staging/src/k8s.io/api/coordination/{v1alpha1 => v1alpha2}/register.go (95%) rename staging/src/k8s.io/api/coordination/{v1alpha1 => v1alpha2}/types.go (75%) diff --git a/cmd/kube-controller-manager/app/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go index 0e5acfa03be..fc3f899d3a7 100644 --- a/cmd/kube-controller-manager/app/controllermanager.go +++ b/cmd/kube-controller-manager/app/controllermanager.go @@ -298,7 +298,7 @@ func Run(ctx context.Context, c *config.CompletedConfig) error { "kube-controller-manager", binaryVersion.FinalizeVersion(), emulationVersion.FinalizeVersion(), - []coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion}, + coordinationv1.OldestEmulationVersion, ) if err != nil { return err diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 30c8fca17c8..1785bbdcc91 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -227,7 +227,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched * "kube-scheduler", binaryVersion.FinalizeVersion(), emulationVersion.FinalizeVersion(), - []coordinationv1.CoordinatedLeaseStrategy{coordinationv1.OldestEmulationVersion}, + coordinationv1.OldestEmulationVersion, ) if err != nil { return err diff --git a/hack/lib/init.sh b/hack/lib/init.sh index d27c0a2798a..a818dc1c30d 100755 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -89,7 +89,7 @@ batch/v1beta1 \ certificates.k8s.io/v1 \ certificates.k8s.io/v1beta1 \ certificates.k8s.io/v1alpha1 \ -coordination.k8s.io/v1alpha1 \ +coordination.k8s.io/v1alpha2 \ coordination.k8s.io/v1beta1 \ coordination.k8s.io/v1 \ discovery.k8s.io/v1 \ diff --git a/pkg/apis/coordination/install/install.go b/pkg/apis/coordination/install/install.go index 09d5a8b6908..717db55b941 100644 --- a/pkg/apis/coordination/install/install.go +++ b/pkg/apis/coordination/install/install.go @@ -24,7 +24,7 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/apis/coordination" v1 "k8s.io/kubernetes/pkg/apis/coordination/v1" - "k8s.io/kubernetes/pkg/apis/coordination/v1alpha1" + "k8s.io/kubernetes/pkg/apis/coordination/v1alpha2" "k8s.io/kubernetes/pkg/apis/coordination/v1beta1" ) @@ -35,8 +35,8 @@ func init() { // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { utilruntime.Must(coordination.AddToScheme(scheme)) - utilruntime.Must(v1alpha1.AddToScheme(scheme)) + utilruntime.Must(v1alpha2.AddToScheme(scheme)) utilruntime.Must(v1beta1.AddToScheme(scheme)) utilruntime.Must(v1.AddToScheme(scheme)) - utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion)) + utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1beta1.SchemeGroupVersion, v1alpha2.SchemeGroupVersion)) } diff --git a/pkg/apis/coordination/types.go b/pkg/apis/coordination/types.go index b1fb9d98481..59362b76488 100644 --- a/pkg/apis/coordination/types.go +++ b/pkg/apis/coordination/types.go @@ -126,27 +126,23 @@ type LeaseCandidateSpec struct { // +optional RenewTime *metav1.MicroTime // BinaryVersion is the binary version. It must be in a semver format without leading `v`. - // This field is required when strategy is "OldestEmulationVersion" - // +optional + // This field is required. + // +required BinaryVersion string // EmulationVersion is the emulation version. It must be in a semver format without leading `v`. // EmulationVersion must be less than or equal to BinaryVersion. // This field is required when strategy is "OldestEmulationVersion" // +optional EmulationVersion string - // PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election. - // The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated - // leader election to make a decision about the final election strategy. This follows as - // - If all clients have strategy X as the first element in this list, strategy X will be used. - // - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y - // will be used. - // - If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader - // election will not operate the Lease until resolved. + // Strategy is the strategy that coordinated leader election will use for picking the leader. + // If multiple candidates for the same Lease return different strategies, the strategy provided + // by the candidate with the latest BinaryVersion will be used. If there is still conflict, + // this is a user error and coordinated leader election will not operate the Lease until resolved. // (Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled. // +featureGate=CoordinatedLeaderElection // +listType=atomic // +required - PreferredStrategies []CoordinatedLeaseStrategy + Strategy CoordinatedLeaseStrategy } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/coordination/v1alpha1/zz_generated.conversion.go b/pkg/apis/coordination/v1alpha1/zz_generated.conversion.go deleted file mode 100644 index 5724ec4bec7..00000000000 --- a/pkg/apis/coordination/v1alpha1/zz_generated.conversion.go +++ /dev/null @@ -1,151 +0,0 @@ -//go:build !ignore_autogenerated -// +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 v1alpha1 - -import ( - unsafe "unsafe" - - coordinationv1 "k8s.io/api/coordination/v1" - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - conversion "k8s.io/apimachinery/pkg/conversion" - runtime "k8s.io/apimachinery/pkg/runtime" - coordination "k8s.io/kubernetes/pkg/apis/coordination" -) - -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((*coordinationv1alpha1.LeaseCandidate)(nil), (*coordination.LeaseCandidate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_LeaseCandidate_To_coordination_LeaseCandidate(a.(*coordinationv1alpha1.LeaseCandidate), b.(*coordination.LeaseCandidate), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*coordination.LeaseCandidate)(nil), (*coordinationv1alpha1.LeaseCandidate)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_coordination_LeaseCandidate_To_v1alpha1_LeaseCandidate(a.(*coordination.LeaseCandidate), b.(*coordinationv1alpha1.LeaseCandidate), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*coordinationv1alpha1.LeaseCandidateList)(nil), (*coordination.LeaseCandidateList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_LeaseCandidateList_To_coordination_LeaseCandidateList(a.(*coordinationv1alpha1.LeaseCandidateList), b.(*coordination.LeaseCandidateList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*coordination.LeaseCandidateList)(nil), (*coordinationv1alpha1.LeaseCandidateList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_coordination_LeaseCandidateList_To_v1alpha1_LeaseCandidateList(a.(*coordination.LeaseCandidateList), b.(*coordinationv1alpha1.LeaseCandidateList), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*coordinationv1alpha1.LeaseCandidateSpec)(nil), (*coordination.LeaseCandidateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec(a.(*coordinationv1alpha1.LeaseCandidateSpec), b.(*coordination.LeaseCandidateSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*coordination.LeaseCandidateSpec)(nil), (*coordinationv1alpha1.LeaseCandidateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec(a.(*coordination.LeaseCandidateSpec), b.(*coordinationv1alpha1.LeaseCandidateSpec), scope) - }); err != nil { - return err - } - return nil -} - -func autoConvert_v1alpha1_LeaseCandidate_To_coordination_LeaseCandidate(in *coordinationv1alpha1.LeaseCandidate, out *coordination.LeaseCandidate, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - return nil -} - -// Convert_v1alpha1_LeaseCandidate_To_coordination_LeaseCandidate is an autogenerated conversion function. -func Convert_v1alpha1_LeaseCandidate_To_coordination_LeaseCandidate(in *coordinationv1alpha1.LeaseCandidate, out *coordination.LeaseCandidate, s conversion.Scope) error { - return autoConvert_v1alpha1_LeaseCandidate_To_coordination_LeaseCandidate(in, out, s) -} - -func autoConvert_coordination_LeaseCandidate_To_v1alpha1_LeaseCandidate(in *coordination.LeaseCandidate, out *coordinationv1alpha1.LeaseCandidate, s conversion.Scope) error { - out.ObjectMeta = in.ObjectMeta - if err := Convert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec(&in.Spec, &out.Spec, s); err != nil { - return err - } - return nil -} - -// Convert_coordination_LeaseCandidate_To_v1alpha1_LeaseCandidate is an autogenerated conversion function. -func Convert_coordination_LeaseCandidate_To_v1alpha1_LeaseCandidate(in *coordination.LeaseCandidate, out *coordinationv1alpha1.LeaseCandidate, s conversion.Scope) error { - return autoConvert_coordination_LeaseCandidate_To_v1alpha1_LeaseCandidate(in, out, s) -} - -func autoConvert_v1alpha1_LeaseCandidateList_To_coordination_LeaseCandidateList(in *coordinationv1alpha1.LeaseCandidateList, out *coordination.LeaseCandidateList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - out.Items = *(*[]coordination.LeaseCandidate)(unsafe.Pointer(&in.Items)) - return nil -} - -// Convert_v1alpha1_LeaseCandidateList_To_coordination_LeaseCandidateList is an autogenerated conversion function. -func Convert_v1alpha1_LeaseCandidateList_To_coordination_LeaseCandidateList(in *coordinationv1alpha1.LeaseCandidateList, out *coordination.LeaseCandidateList, s conversion.Scope) error { - return autoConvert_v1alpha1_LeaseCandidateList_To_coordination_LeaseCandidateList(in, out, s) -} - -func autoConvert_coordination_LeaseCandidateList_To_v1alpha1_LeaseCandidateList(in *coordination.LeaseCandidateList, out *coordinationv1alpha1.LeaseCandidateList, s conversion.Scope) error { - out.ListMeta = in.ListMeta - out.Items = *(*[]coordinationv1alpha1.LeaseCandidate)(unsafe.Pointer(&in.Items)) - return nil -} - -// Convert_coordination_LeaseCandidateList_To_v1alpha1_LeaseCandidateList is an autogenerated conversion function. -func Convert_coordination_LeaseCandidateList_To_v1alpha1_LeaseCandidateList(in *coordination.LeaseCandidateList, out *coordinationv1alpha1.LeaseCandidateList, s conversion.Scope) error { - return autoConvert_coordination_LeaseCandidateList_To_v1alpha1_LeaseCandidateList(in, out, s) -} - -func autoConvert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec(in *coordinationv1alpha1.LeaseCandidateSpec, out *coordination.LeaseCandidateSpec, s conversion.Scope) error { - out.LeaseName = in.LeaseName - out.PingTime = (*v1.MicroTime)(unsafe.Pointer(in.PingTime)) - out.RenewTime = (*v1.MicroTime)(unsafe.Pointer(in.RenewTime)) - out.BinaryVersion = in.BinaryVersion - out.EmulationVersion = in.EmulationVersion - out.PreferredStrategies = *(*[]coordination.CoordinatedLeaseStrategy)(unsafe.Pointer(&in.PreferredStrategies)) - return nil -} - -// Convert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec is an autogenerated conversion function. -func Convert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec(in *coordinationv1alpha1.LeaseCandidateSpec, out *coordination.LeaseCandidateSpec, s conversion.Scope) error { - return autoConvert_v1alpha1_LeaseCandidateSpec_To_coordination_LeaseCandidateSpec(in, out, s) -} - -func autoConvert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec(in *coordination.LeaseCandidateSpec, out *coordinationv1alpha1.LeaseCandidateSpec, s conversion.Scope) error { - out.LeaseName = in.LeaseName - out.PingTime = (*v1.MicroTime)(unsafe.Pointer(in.PingTime)) - out.RenewTime = (*v1.MicroTime)(unsafe.Pointer(in.RenewTime)) - out.BinaryVersion = in.BinaryVersion - out.EmulationVersion = in.EmulationVersion - out.PreferredStrategies = *(*[]coordinationv1.CoordinatedLeaseStrategy)(unsafe.Pointer(&in.PreferredStrategies)) - return nil -} - -// Convert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec is an autogenerated conversion function. -func Convert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec(in *coordination.LeaseCandidateSpec, out *coordinationv1alpha1.LeaseCandidateSpec, s conversion.Scope) error { - return autoConvert_coordination_LeaseCandidateSpec_To_v1alpha1_LeaseCandidateSpec(in, out, s) -} diff --git a/pkg/apis/coordination/v1alpha1/zz_generated.defaults.go b/pkg/apis/coordination/v1alpha1/zz_generated.defaults.go deleted file mode 100644 index 5070cb91b90..00000000000 --- a/pkg/apis/coordination/v1alpha1/zz_generated.defaults.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build !ignore_autogenerated -// +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 defaulter-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// RegisterDefaults adds defaulters functions to the given scheme. -// Public to allow building arbitrary schemes. -// All generated defaulters are covering - they call all nested defaulters. -func RegisterDefaults(scheme *runtime.Scheme) error { - return nil -} diff --git a/pkg/apis/coordination/v1alpha1/doc.go b/pkg/apis/coordination/v1alpha2/doc.go similarity index 83% rename from pkg/apis/coordination/v1alpha1/doc.go rename to pkg/apis/coordination/v1alpha2/doc.go index d9efbef91d7..73783d823d6 100644 --- a/pkg/apis/coordination/v1alpha1/doc.go +++ b/pkg/apis/coordination/v1alpha2/doc.go @@ -15,10 +15,10 @@ limitations under the License. */ // +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/coordination -// +k8s:conversion-gen-external-types=k8s.io/api/coordination/v1alpha1 +// +k8s:conversion-gen-external-types=k8s.io/api/coordination/v1alpha2 // +k8s:defaulter-gen=TypeMeta -// +k8s:defaulter-gen-input=k8s.io/api/coordination/v1alpha1 +// +k8s:defaulter-gen-input=k8s.io/api/coordination/v1alpha2 // +groupName=coordination.k8s.io -package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha1" +package v1alpha2 // import "k8s.io/kubernetes/pkg/apis/coordination/v1alpha2" diff --git a/pkg/apis/coordination/v1alpha1/register.go b/pkg/apis/coordination/v1alpha2/register.go similarity index 90% rename from pkg/apis/coordination/v1alpha1/register.go rename to pkg/apis/coordination/v1alpha2/register.go index d05aa11e357..549d1539df0 100644 --- a/pkg/apis/coordination/v1alpha1/register.go +++ b/pkg/apis/coordination/v1alpha2/register.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package v1alpha2 import ( - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -25,7 +25,7 @@ import ( const GroupName = "coordination.k8s.io" // SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"} // Resource takes an unqualified resource and returns a Group qualified GroupResource func Resource(resource string) schema.GroupResource { @@ -33,7 +33,7 @@ func Resource(resource string) schema.GroupResource { } var ( - localSchemeBuilder = &coordinationv1alpha1.SchemeBuilder + localSchemeBuilder = &coordinationv1alpha2.SchemeBuilder // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme AddToScheme = localSchemeBuilder.AddToScheme ) diff --git a/pkg/apis/coordination/validation/validation.go b/pkg/apis/coordination/validation/validation.go index 44bb45052c9..0f282ea88bd 100644 --- a/pkg/apis/coordination/validation/validation.go +++ b/pkg/apis/coordination/validation/validation.go @@ -111,7 +111,9 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath * } } bv := semver.Version{} - if spec.BinaryVersion != "" { + if spec.BinaryVersion == "" { + allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), "")) + } else { var err error bv, err = semver.Parse(spec.BinaryVersion) if err != nil { @@ -124,29 +126,18 @@ func ValidateLeaseCandidateSpec(spec *coordination.LeaseCandidateSpec, fldPath * allErrs = append(allErrs, field.Invalid(fld, spec.BinaryVersion, "must be greater than or equal to `emulationVersion`")) } - if len(spec.PreferredStrategies) > 0 { - for i, strategy := range spec.PreferredStrategies { - fld := fldPath.Child("preferredStrategies").Index(i) - - strategySeen := make(map[coordination.CoordinatedLeaseStrategy]bool) - if _, ok := strategySeen[strategy]; ok { - allErrs = append(allErrs, field.Duplicate(fld, strategy)) - } else { - strategySeen[strategy] = true + if spec.Strategy == "" { + allErrs = append(allErrs, field.Required(fldPath.Child("strategy"), "")) + } else { + fld := fldPath.Child("strategy") + if spec.Strategy == coordination.OldestEmulationVersion { + zeroVersion := semver.Version{} + if ev.EQ(zeroVersion) { + allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'")) } - - if strategy == coordination.OldestEmulationVersion { - zeroVersion := semver.Version{} - if bv.EQ(zeroVersion) { - allErrs = append(allErrs, field.Required(fldPath.Child("binaryVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'")) - } - if ev.EQ(zeroVersion) { - allErrs = append(allErrs, field.Required(fldPath.Child("emulationVersion"), "must be specified when `strategy` is 'OldestEmulationVersion'")) - } - } - - allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(strategy, fld)...) } + + allErrs = append(allErrs, ValidateCoordinatedLeaseStrategy(spec.Strategy, fld)...) } // spec.PingTime is a MicroTime and doesn't need further validation // spec.RenewTime is a MicroTime and doesn't need further validation diff --git a/pkg/apis/coordination/validation/validation_test.go b/pkg/apis/coordination/validation/validation_test.go index 83fedd6db40..20018240084 100644 --- a/pkg/apis/coordination/validation/validation_test.go +++ b/pkg/apis/coordination/validation/validation_test.go @@ -171,25 +171,34 @@ func TestValidateLeaseCandidateSpec(t *testing.T) { "valid", false, &coordination.LeaseCandidateSpec{ - BinaryVersion: "1.30.0", - EmulationVersion: "1.30.0", - LeaseName: "test", - PreferredStrategies: []coordination.CoordinatedLeaseStrategy{coordination.OldestEmulationVersion}, + BinaryVersion: "1.30.0", + EmulationVersion: "1.30.0", + LeaseName: "test", + Strategy: coordination.OldestEmulationVersion, }, }, { - "valid custom strategy should not require binaryVersion and emulationVersion", + "valid custom strategy should not require emulationVersion", false, &coordination.LeaseCandidateSpec{ - LeaseName: "test", - PreferredStrategies: []coordination.CoordinatedLeaseStrategy{"custom.com/foo"}, + LeaseName: "test", + BinaryVersion: "1.30.0", + Strategy: coordination.CoordinatedLeaseStrategy("custom.com/foo"), + }, + }, + { + "binaryVersion is required", + true, + &coordination.LeaseCandidateSpec{ + LeaseName: "test", + Strategy: coordination.CoordinatedLeaseStrategy("custom.com/foo"), }, }, - { "no lease name", true, &coordination.LeaseCandidateSpec{ + BinaryVersion: "1.30.0", EmulationVersion: "1.30.0", }, }, @@ -211,22 +220,31 @@ func TestValidateLeaseCandidateSpec(t *testing.T) { }, }, { - "preferredStrategies bad", + "strategy bad", true, &coordination.LeaseCandidateSpec{ - BinaryVersion: "1.30.1", - EmulationVersion: "1.30.1", - LeaseName: "test", - PreferredStrategies: []coordination.CoordinatedLeaseStrategy{"foo"}, + BinaryVersion: "1.30.1", + EmulationVersion: "1.30.1", + LeaseName: "test", + Strategy: coordination.CoordinatedLeaseStrategy("foo"), }, }, { - "preferredStrategies good but emulationVersion missing", + "strategy missing", true, &coordination.LeaseCandidateSpec{ - BinaryVersion: "1.30.1", - LeaseName: "test", - PreferredStrategies: []coordination.CoordinatedLeaseStrategy{coordination.OldestEmulationVersion}, + BinaryVersion: "1.30.1", + EmulationVersion: "1.30.1", + LeaseName: "test", + }, + }, + { + "strategy good but emulationVersion missing", + true, + &coordination.LeaseCandidateSpec{ + BinaryVersion: "1.30.1", + LeaseName: "test", + Strategy: coordination.OldestEmulationVersion, }, }, } @@ -255,6 +273,7 @@ func TestValidateLeaseCandidateUpdate(t *testing.T) { BinaryVersion: "1.30.0", EmulationVersion: "1.30.0", LeaseName: "test", + Strategy: coordination.OldestEmulationVersion, }, }, update: coordination.LeaseCandidate{ @@ -262,6 +281,7 @@ func TestValidateLeaseCandidateUpdate(t *testing.T) { BinaryVersion: "1.30.0", EmulationVersion: "1.30.0", LeaseName: "test", + Strategy: coordination.OldestEmulationVersion, }, }, err: false, @@ -273,6 +293,7 @@ func TestValidateLeaseCandidateUpdate(t *testing.T) { BinaryVersion: "1.30.0", EmulationVersion: "1.30.0", LeaseName: "test", + Strategy: coordination.OldestEmulationVersion, }, }, update: coordination.LeaseCandidate{ @@ -280,6 +301,7 @@ func TestValidateLeaseCandidateUpdate(t *testing.T) { BinaryVersion: "1.30.0", EmulationVersion: "1.30.0", LeaseName: "test-update", + Strategy: coordination.OldestEmulationVersion, }, }, err: true, diff --git a/pkg/controlplane/apiserver/aggregator.go b/pkg/controlplane/apiserver/aggregator.go index 087896a3554..a9f4613fc8a 100644 --- a/pkg/controlplane/apiserver/aggregator.go +++ b/pkg/controlplane/apiserver/aggregator.go @@ -284,7 +284,7 @@ func DefaultGenericAPIServicePriorities() map[schema.GroupVersion]APIServicePrio {Group: "admissionregistration.k8s.io", Version: "v1beta1"}: {Group: 16700, Version: 12}, {Group: "admissionregistration.k8s.io", Version: "v1alpha1"}: {Group: 16700, Version: 9}, {Group: "coordination.k8s.io", Version: "v1"}: {Group: 16500, Version: 15}, - {Group: "coordination.k8s.io", Version: "v1alpha1"}: {Group: 16500, Version: 9}, + {Group: "coordination.k8s.io", Version: "v1alpha2"}: {Group: 16500, Version: 12}, {Group: "discovery.k8s.io", Version: "v1"}: {Group: 16200, Version: 15}, {Group: "discovery.k8s.io", Version: "v1beta1"}: {Group: 16200, Version: 12}, {Group: "flowcontrol.apiserver.k8s.io", Version: "v1"}: {Group: 16100, Version: 21}, diff --git a/pkg/controlplane/apiserver/server.go b/pkg/controlplane/apiserver/server.go index 773bef9df01..526f878fc91 100644 --- a/pkg/controlplane/apiserver/server.go +++ b/pkg/controlplane/apiserver/server.go @@ -159,7 +159,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele if utilfeature.DefaultFeatureGate.Enabled(apiserverfeatures.CoordinatedLeaderElection) { leaseInformer := s.VersionedInformers.Coordination().V1().Leases() - lcInformer := s.VersionedInformers.Coordination().V1alpha1().LeaseCandidates() + lcInformer := s.VersionedInformers.Coordination().V1alpha2().LeaseCandidates() // Ensure that informers are registered before starting. Coordinated Leader Election leader-elected // and may register informer handlers after they are started. _ = leaseInformer.Informer() @@ -170,7 +170,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele leaseInformer, lcInformer, client.CoordinationV1(), - client.CoordinationV1alpha1(), + client.CoordinationV1alpha2(), ) gccontroller := leaderelection.NewLeaseCandidateGC( client, diff --git a/pkg/controlplane/controller/leaderelection/election.go b/pkg/controlplane/controller/leaderelection/election.go index dde32d41bdb..9b77345f76c 100644 --- a/pkg/controlplane/controller/leaderelection/election.go +++ b/pkg/controlplane/controller/leaderelection/election.go @@ -22,12 +22,12 @@ import ( "github.com/blang/semver/v4" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" "k8s.io/utils/clock" ) -func pickBestLeaderOldestEmulationVersion(candidates []*v1alpha1.LeaseCandidate) *v1alpha1.LeaseCandidate { - var electee *v1alpha1.LeaseCandidate +func pickBestLeaderOldestEmulationVersion(candidates []*v1alpha2.LeaseCandidate) *v1alpha2.LeaseCandidate { + var electee *v1alpha2.LeaseCandidate for _, c := range candidates { if !validLeaseCandidateForOldestEmulationVersion(c) { continue @@ -39,72 +39,30 @@ func pickBestLeaderOldestEmulationVersion(candidates []*v1alpha1.LeaseCandidate) return electee } -// topologicalSortWithOneRoot has a caveat that there may only be one root (indegree=0) node in a valid ordering. -func topologicalSortWithOneRoot(graph map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy) []v1.CoordinatedLeaseStrategy { - inDegree := make(map[v1.CoordinatedLeaseStrategy]int) - for node := range graph { - inDegree[node] = 0 - } - for _, neighbors := range graph { - for _, neighbor := range neighbors { - inDegree[neighbor]++ - } - } - - var queue []v1.CoordinatedLeaseStrategy - for vertex, degree := range inDegree { - if degree == 0 { - queue = append(queue, vertex) - } - } - - // If multiple nodes have indegree of 0, multiple strategies are non-superceding and is a conflict. - if len(queue) > 1 { - return nil - } - - var sorted []v1.CoordinatedLeaseStrategy - for len(queue) > 0 { - vertex := queue[0] - queue = queue[1:] - sorted = append(sorted, vertex) - - for _, neighbor := range graph[vertex] { - inDegree[neighbor]-- - if inDegree[neighbor] == 0 { - queue = append(queue, neighbor) - } - } - } - - if len(sorted) != len(graph) { - return nil // Cycle detected - } - - return sorted -} - -func pickBestStrategy(candidates []*v1alpha1.LeaseCandidate) (v1.CoordinatedLeaseStrategy, error) { - graph := make(map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy) +func pickBestStrategy(candidates []*v1alpha2.LeaseCandidate) (v1.CoordinatedLeaseStrategy, error) { nilStrategy := v1.CoordinatedLeaseStrategy("") - for _, c := range candidates { - for i := range len(c.Spec.PreferredStrategies) - 1 { - graph[c.Spec.PreferredStrategies[i]] = append(graph[c.Spec.PreferredStrategies[i]], c.Spec.PreferredStrategies[i+1]) - } - if _, ok := graph[c.Spec.PreferredStrategies[len(c.Spec.PreferredStrategies)-1]]; !ok { - graph[c.Spec.PreferredStrategies[len(c.Spec.PreferredStrategies)-1]] = []v1.CoordinatedLeaseStrategy{} + if len(candidates) == 0 { + return nilStrategy, fmt.Errorf("no candidates") + } + candidateName := candidates[0].Name + strategy := candidates[0].Spec.Strategy + highestBV := getBinaryVersionOrZero(candidates[0]) + + for _, c := range candidates[1:] { + binVersion := getBinaryVersionOrZero(c) + result := highestBV.Compare(binVersion) + if result < 0 { + strategy = c.Spec.Strategy + highestBV = binVersion + candidateName = c.Name + } else if result == 0 && c.Spec.Strategy != strategy { + return nilStrategy, fmt.Errorf("candidates %q, %q at same binary version but received differing strategies %s, %s", candidateName, c.Name, strategy, c.Spec.Strategy) } } - - sorted := topologicalSortWithOneRoot(graph) - if sorted == nil { - return nilStrategy, fmt.Errorf("invalid strategy") - } - - return sorted[0], nil + return strategy, nil } -func validLeaseCandidateForOldestEmulationVersion(l *v1alpha1.LeaseCandidate) bool { +func validLeaseCandidateForOldestEmulationVersion(l *v1alpha2.LeaseCandidate) bool { _, err := semver.ParseTolerant(l.Spec.EmulationVersion) if err != nil { return false @@ -113,7 +71,7 @@ func validLeaseCandidateForOldestEmulationVersion(l *v1alpha1.LeaseCandidate) bo return err == nil } -func getEmulationVersionOrZero(l *v1alpha1.LeaseCandidate) semver.Version { +func getEmulationVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version { value := l.Spec.EmulationVersion v, err := semver.ParseTolerant(value) if err != nil { @@ -122,7 +80,7 @@ func getEmulationVersionOrZero(l *v1alpha1.LeaseCandidate) semver.Version { return v } -func getBinaryVersionOrZero(l *v1alpha1.LeaseCandidate) semver.Version { +func getBinaryVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version { value := l.Spec.BinaryVersion v, err := semver.ParseTolerant(value) if err != nil { @@ -132,7 +90,7 @@ func getBinaryVersionOrZero(l *v1alpha1.LeaseCandidate) semver.Version { } // -1: lhs better, 1: rhs better -func compare(lhs, rhs *v1alpha1.LeaseCandidate) int { +func compare(lhs, rhs *v1alpha2.LeaseCandidate) int { l := getEmulationVersionOrZero(lhs) r := getEmulationVersionOrZero(rhs) result := l.Compare(r) @@ -157,7 +115,7 @@ func isLeaseExpired(clock clock.Clock, lease *v1.Lease) bool { lease.Spec.RenewTime.Add(time.Duration(*lease.Spec.LeaseDurationSeconds)*time.Second).Before(currentTime) } -func isLeaseCandidateExpired(clock clock.Clock, lease *v1alpha1.LeaseCandidate) bool { +func isLeaseCandidateExpired(clock clock.Clock, lease *v1alpha2.LeaseCandidate) bool { currentTime := clock.Now() return lease.Spec.RenewTime == nil || lease.Spec.RenewTime.Add(leaseCandidateValidDuration).Before(currentTime) diff --git a/pkg/controlplane/controller/leaderelection/election_test.go b/pkg/controlplane/controller/leaderelection/election_test.go index c59de02690a..c6b08d2c7f7 100644 --- a/pkg/controlplane/controller/leaderelection/election_test.go +++ b/pkg/controlplane/controller/leaderelection/election_test.go @@ -22,42 +22,42 @@ import ( "github.com/blang/semver/v4" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { tests := []struct { name string - candidates []*v1alpha1.LeaseCandidate - want *v1alpha1.LeaseCandidate + candidates []*v1alpha2.LeaseCandidate + want *v1alpha2.LeaseCandidate }{ { name: "empty", - candidates: []*v1alpha1.LeaseCandidate{}, + candidates: []*v1alpha2.LeaseCandidate{}, want: nil, }, { name: "single candidate", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, }, }, - want: &v1alpha1.LeaseCandidate{ + want: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -65,14 +65,14 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { }, { name: "multiple candidates, different emulation versions", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -83,18 +83,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.2.0", BinaryVersion: "0.2.0", }, }, }, - want: &v1alpha1.LeaseCandidate{ + want: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "v1", BinaryVersion: "v1", }, @@ -102,14 +102,14 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { }, { name: "multiple candidates, same emulation versions, different binary versions", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -120,18 +120,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.2.0", }, }, }, - want: &v1alpha1.LeaseCandidate{ + want: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -139,14 +139,14 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { }, { name: "multiple candidates, same emulation versions, same binary versions, different creation timestamps", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -157,18 +157,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, }, }, - want: &v1alpha1.LeaseCandidate{ + want: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -192,13 +192,13 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) { func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) { tests := []struct { name string - candidate *v1alpha1.LeaseCandidate + candidate *v1alpha2.LeaseCandidate want bool }{ { name: "valid emulation and binary versions", - candidate: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + candidate: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "0.1.0", }, @@ -207,8 +207,8 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) { }, { name: "invalid emulation version", - candidate: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + candidate: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "invalid", BinaryVersion: "0.1.0", }, @@ -217,8 +217,8 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) { }, { name: "invalid binary version", - candidate: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + candidate: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", BinaryVersion: "invalid", }, @@ -239,13 +239,13 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) { func TestGetEmulationVersion(t *testing.T) { tests := []struct { name string - candidate *v1alpha1.LeaseCandidate + candidate *v1alpha2.LeaseCandidate want semver.Version }{ { name: "valid emulation version", - candidate: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + candidate: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "0.1.0", }, }, @@ -265,13 +265,13 @@ func TestGetEmulationVersion(t *testing.T) { func TestGetBinaryVersion(t *testing.T) { tests := []struct { name string - candidate *v1alpha1.LeaseCandidate + candidate *v1alpha2.LeaseCandidate want semver.Version }{ { name: "valid binary version", - candidate: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + candidate: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ BinaryVersion: "0.3.0", }, }, @@ -292,14 +292,14 @@ func TestCompare(t *testing.T) { nowTime := time.Now() cases := []struct { name string - lhs *v1alpha1.LeaseCandidate - rhs *v1alpha1.LeaseCandidate + lhs *v1alpha2.LeaseCandidate + rhs *v1alpha2.LeaseCandidate expectedResult int }{ { name: "identical versions earlier timestamp", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, @@ -307,8 +307,8 @@ func TestCompare(t *testing.T) { CreationTimestamp: metav1.Time{Time: nowTime.Add(time.Duration(1))}, }, }, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, @@ -320,9 +320,9 @@ func TestCompare(t *testing.T) { }, { name: "no lhs version", - lhs: &v1alpha1.LeaseCandidate{}, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{}, + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, @@ -331,25 +331,25 @@ func TestCompare(t *testing.T) { }, { name: "no rhs version", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, }, - rhs: &v1alpha1.LeaseCandidate{}, + rhs: &v1alpha2.LeaseCandidate{}, expectedResult: 1, }, { name: "invalid lhs version", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "xyz", BinaryVersion: "xyz", }, }, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, @@ -358,14 +358,14 @@ func TestCompare(t *testing.T) { }, { name: "invalid rhs version", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.21.0", }, }, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "xyz", BinaryVersion: "xyz", }, @@ -374,14 +374,14 @@ func TestCompare(t *testing.T) { }, { name: "lhs less than rhs", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.19.0", BinaryVersion: "1.20.0", }, }, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.20.0", }, @@ -390,14 +390,14 @@ func TestCompare(t *testing.T) { }, { name: "rhs less than lhs", - lhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + lhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.20.0", BinaryVersion: "1.20.0", }, }, - rhs: &v1alpha1.LeaseCandidate{ - Spec: v1alpha1.LeaseCandidateSpec{ + rhs: &v1alpha2.LeaseCandidate{ + Spec: v1alpha2.LeaseCandidateSpec{ EmulationVersion: "1.19.0", BinaryVersion: "1.20.0", }, @@ -418,93 +418,93 @@ func TestCompare(t *testing.T) { func TestShouldReelect(t *testing.T) { cases := []struct { name string - candidates []*v1alpha1.LeaseCandidate - currentLeader *v1alpha1.LeaseCandidate + candidates []*v1alpha2.LeaseCandidate + currentLeader *v1alpha2.LeaseCandidate expectResult bool }{ { name: "candidate with newer binary version", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, { ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.20.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.20.0", + Strategy: v1.OldestEmulationVersion, }, }, }, - currentLeader: &v1alpha1.LeaseCandidate{ + currentLeader: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, expectResult: false, }, { name: "no newer candidates", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, { ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, }, - currentLeader: &v1alpha1.LeaseCandidate{ + currentLeader: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, expectResult: false, }, { name: "no candidates", - candidates: []*v1alpha1.LeaseCandidate{}, - currentLeader: &v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{}, + currentLeader: &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + Strategy: v1.OldestEmulationVersion, }, }, expectResult: false, @@ -520,68 +520,24 @@ func TestShouldReelect(t *testing.T) { } } -func TestTopologicalSortWithOneRoot(t *testing.T) { - tests := []struct { - name string - graph map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy - want []v1.CoordinatedLeaseStrategy - }{ - { - name: "simple DAG", - graph: map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy{ - v1.OldestEmulationVersion: {"foo"}, - "foo": {"bar"}, - "bar": {}, - }, - want: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion, "foo", "bar"}, - }, - { - name: "cycle", - graph: map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy{ - v1.OldestEmulationVersion: {"foo"}, - "foo": {v1.OldestEmulationVersion}, - }, - want: nil, - }, - { - name: "multiple", - graph: map[v1.CoordinatedLeaseStrategy][]v1.CoordinatedLeaseStrategy{ - v1.OldestEmulationVersion: {"foo", "baz"}, - "foo": {"baz"}, - "baz": {}, - }, - want: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion, "foo", "baz"}, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - got := topologicalSortWithOneRoot(tc.graph) - if !equalStrategies(got, tc.want) { - t.Errorf("topologicalSortWithOneRoot() = %v, want %v", got, tc.want) - } - }) - } -} - func TestPickBestStrategy(t *testing.T) { tests := []struct { name string - candidates []*v1alpha1.LeaseCandidate + candidates []*v1alpha2.LeaseCandidate wantStrategy v1.CoordinatedLeaseStrategy wantError bool }{ { name: "single candidate, single preferred strategy", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -590,15 +546,15 @@ func TestPickBestStrategy(t *testing.T) { }, { name: "multiple candidates, different preferred strategies should fail", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + Strategy: v1.OldestEmulationVersion, }, }, { @@ -606,25 +562,26 @@ func TestPickBestStrategy(t *testing.T) { Name: "candidate2", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{"foo.com/bar"}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), }, }, }, wantError: true, }, { - name: "multiple candidates, multiple resolved preferred strategy", - candidates: []*v1alpha1.LeaseCandidate{ + name: "multiple candidates, different preferred strategy different binary version should resolve", + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion, "foo.com/bar"}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.32.0", + Strategy: v1.OldestEmulationVersion, }, }, { @@ -632,9 +589,10 @@ func TestPickBestStrategy(t *testing.T) { Name: "candidate2", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{"foo.com/bar"}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), }, }, }, @@ -642,16 +600,46 @@ func TestPickBestStrategy(t *testing.T) { wantError: false, }, { - name: "multiple candidates, same preferred strategy", - candidates: []*v1alpha1.LeaseCandidate{ + name: "multiple candidates, different preferred strategy different binary version should resolve, order agnostic", + candidates: []*v1alpha2.LeaseCandidate{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "candidate2", + Namespace: "default", + }, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), + }, + }, { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.32.0", + Strategy: v1.OldestEmulationVersion, + }, + }, + }, + wantStrategy: v1.OldestEmulationVersion, + wantError: false, + }, + { + name: "multiple candidates, different preferred strategy different binary version string comparison check", + candidates: []*v1alpha2.LeaseCandidate{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "candidate1", + Namespace: "default", + }, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.1.10", + Strategy: v1.OldestEmulationVersion, }, }, { @@ -659,9 +647,40 @@ func TestPickBestStrategy(t *testing.T) { Name: "candidate2", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.1.2", + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), + }, + }, + }, + wantStrategy: v1.OldestEmulationVersion, + wantError: false, + }, + + { + name: "multiple candidates, same preferred strategy", + candidates: []*v1alpha2.LeaseCandidate{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "candidate1", + Namespace: "default", + }, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.OldestEmulationVersion, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "candidate2", + Namespace: "default", + }, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -670,15 +689,16 @@ func TestPickBestStrategy(t *testing.T) { }, { name: "multiple candidates, conflicting preferred strategy", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.OldestEmulationVersion, }, }, { @@ -686,41 +706,16 @@ func TestPickBestStrategy(t *testing.T) { Name: "candidate2", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{"foo.com/bar"}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + BinaryVersion: "1.31.0", + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), }, }, }, wantStrategy: "", wantError: true, }, - { - name: "multiple candidates, cycle in preferred strategies", - candidates: []*v1alpha1.LeaseCandidate{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "candidate1", - Namespace: "default", - }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{"foo.com/bar", v1.OldestEmulationVersion}, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "candidate2", - Namespace: "default", - }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion, "foo.com/bar"}, - }, - }, - }, - wantError: true, - }, } for _, tc := range tests { @@ -737,19 +732,7 @@ func TestPickBestStrategy(t *testing.T) { } } -func equalStrategies(s1, s2 []v1.CoordinatedLeaseStrategy) bool { - if len(s1) != len(s2) { - return false - } - for i := range s1 { - if s1[i] != s2[i] { - return false - } - } - return true -} - -func shouldReelect(candidates []*v1alpha1.LeaseCandidate, currentLeader *v1alpha1.LeaseCandidate) bool { +func shouldReelect(candidates []*v1alpha2.LeaseCandidate, currentLeader *v1alpha2.LeaseCandidate) bool { pickedLeader := pickBestLeaderOldestEmulationVersion(candidates) if pickedLeader == nil { return false diff --git a/pkg/controlplane/controller/leaderelection/leaderelection_controller.go b/pkg/controlplane/controller/leaderelection/leaderelection_controller.go index cb53df92e81..b33e2a8ec48 100644 --- a/pkg/controlplane/controller/leaderelection/leaderelection_controller.go +++ b/pkg/controlplane/controller/leaderelection/leaderelection_controller.go @@ -23,7 +23,7 @@ import ( "time" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -31,9 +31,9 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" coordinationv1informers "k8s.io/client-go/informers/coordination/v1" - coordinationv1alpha1 "k8s.io/client-go/informers/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/client-go/informers/coordination/v1alpha2" coordinationv1client "k8s.io/client-go/kubernetes/typed/coordination/v1" - coordinationv1alpha1client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha1" + coordinationv1alpha2client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha2" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -64,8 +64,8 @@ type Controller struct { leaseClient coordinationv1client.CoordinationV1Interface leaseRegistration cache.ResourceEventHandlerRegistration - leaseCandidateInformer coordinationv1alpha1.LeaseCandidateInformer - leaseCandidateClient coordinationv1alpha1client.CoordinationV1alpha1Interface + leaseCandidateInformer coordinationv1alpha2.LeaseCandidateInformer + leaseCandidateClient coordinationv1alpha2client.CoordinationV1alpha2Interface leaseCandidateRegistration cache.ResourceEventHandlerRegistration queue workqueue.TypedRateLimitingInterface[types.NamespacedName] @@ -109,7 +109,7 @@ func (c *Controller) Run(ctx context.Context, workers int) { <-ctx.Done() } -func NewController(leaseInformer coordinationv1informers.LeaseInformer, leaseCandidateInformer coordinationv1alpha1.LeaseCandidateInformer, leaseClient coordinationv1client.CoordinationV1Interface, leaseCandidateClient coordinationv1alpha1client.CoordinationV1alpha1Interface) (*Controller, error) { +func NewController(leaseInformer coordinationv1informers.LeaseInformer, leaseCandidateInformer coordinationv1alpha2.LeaseCandidateInformer, leaseClient coordinationv1client.CoordinationV1Interface, leaseCandidateClient coordinationv1alpha2client.CoordinationV1alpha2Interface) (*Controller, error) { c := &Controller{ leaseInformer: leaseInformer, leaseCandidateInformer: leaseCandidateInformer, @@ -174,7 +174,7 @@ func (c *Controller) processNextElectionItem(ctx context.Context) bool { } func (c *Controller) enqueueCandidate(obj any) { - lc, ok := obj.(*v1alpha1.LeaseCandidate) + lc, ok := obj.(*v1alpha2.LeaseCandidate) if !ok { return } @@ -196,7 +196,7 @@ func (c *Controller) enqueueLease(obj any) { c.queue.Add(types.NamespacedName{Namespace: lease.Namespace, Name: lease.Name}) } -func (c *Controller) electionNeeded(candidates []*v1alpha1.LeaseCandidate, leaseNN types.NamespacedName) (bool, error) { +func (c *Controller) electionNeeded(candidates []*v1alpha2.LeaseCandidate, leaseNN types.NamespacedName) (bool, error) { lease, err := c.leaseInformer.Lister().Leases(leaseNN.Namespace).Get(leaseNN.Name) if err != nil && !apierrors.IsNotFound(err) { return false, fmt.Errorf("error reading lease: %w", err) @@ -313,7 +313,7 @@ func (c *Controller) reconcileElectionStep(ctx context.Context, leaseNN types.Na } } - var ackedCandidates []*v1alpha1.LeaseCandidate + var ackedCandidates []*v1alpha2.LeaseCandidate for _, candidate := range candidates { if candidate.Spec.RenewTime.Add(electionDuration).After(now) { ackedCandidates = append(ackedCandidates, candidate) @@ -415,12 +415,12 @@ func (c *Controller) reconcileElectionStep(ctx context.Context, leaseNN types.Na return defaultRequeueInterval, nil } -func (c *Controller) listAdmissableCandidates(leaseNN types.NamespacedName) ([]*v1alpha1.LeaseCandidate, error) { +func (c *Controller) listAdmissableCandidates(leaseNN types.NamespacedName) ([]*v1alpha2.LeaseCandidate, error) { leases, err := c.leaseCandidateInformer.Lister().LeaseCandidates(leaseNN.Namespace).List(labels.Everything()) if err != nil { return nil, err } - var results []*v1alpha1.LeaseCandidate + var results []*v1alpha2.LeaseCandidate for _, l := range leases { if l.Spec.LeaseName != leaseNN.Name { continue diff --git a/pkg/controlplane/controller/leaderelection/leaderelection_controller_test.go b/pkg/controlplane/controller/leaderelection/leaderelection_controller_test.go index eb04b1e70af..d0f14225581 100644 --- a/pkg/controlplane/controller/leaderelection/leaderelection_controller_test.go +++ b/pkg/controlplane/controller/leaderelection/leaderelection_controller_test.go @@ -25,7 +25,7 @@ import ( "time" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -42,7 +42,7 @@ func TestReconcileElectionStep(t *testing.T) { tests := []struct { name string leaseNN types.NamespacedName - candidates []*v1alpha1.LeaseCandidate + candidates []*v1alpha2.LeaseCandidate existingLease *v1.Lease expectLease bool expectedHolderIdentity *string @@ -55,7 +55,7 @@ func TestReconcileElectionStep(t *testing.T) { { name: "no candidates, no lease, noop", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{}, + candidates: []*v1alpha2.LeaseCandidate{}, existingLease: nil, expectLease: false, expectedHolderIdentity: nil, @@ -66,7 +66,7 @@ func TestReconcileElectionStep(t *testing.T) { { name: "no candidates, lease exists. noop, not managed by CLE", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{}, + candidates: []*v1alpha2.LeaseCandidate{}, existingLease: &v1.Lease{}, expectLease: false, expectedHolderIdentity: nil, @@ -77,18 +77,18 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, no existing lease should create lease", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -102,18 +102,18 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, lease exists, unoptimal should set preferredHolder", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -121,12 +121,12 @@ func TestReconcileElectionStep(t *testing.T) { Namespace: "default", Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.18.0", - BinaryVersion: "1.18.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.18.0", + BinaryVersion: "1.18.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -151,19 +151,19 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, should only elect leader from acked candidates", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * electionDuration))), - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-4 * electionDuration))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * electionDuration))), + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-4 * electionDuration))), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -171,13 +171,13 @@ func TestReconcileElectionStep(t *testing.T) { Namespace: "default", Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.20.0", - BinaryVersion: "1.20.0", - PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.20.0", + BinaryVersion: "1.20.0", + PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -191,18 +191,18 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, lease exists, lease expired", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -226,19 +226,19 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, no acked candidates should return error", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-1 * time.Minute))), - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * time.Minute))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-1 * time.Minute))), + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * time.Minute))), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -251,18 +251,18 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, should ping on election", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * electionDuration))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-2 * electionDuration))), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -277,19 +277,19 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidate exist, pinged candidate should have until electionDuration until election decision is made", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-1 * time.Minute))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + PingTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now().Add(-1 * time.Minute))), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -302,18 +302,18 @@ func TestReconcileElectionStep(t *testing.T) { { name: "candidates exist, lease exists, lease expired, 3rdparty strategy", leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"}, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{"foo.com/bar"}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(fakeClock.Now())), + Strategy: v1.CoordinatedLeaseStrategy("foo.com/bar"), }, }, }, @@ -344,9 +344,9 @@ func TestReconcileElectionStep(t *testing.T) { controller, err := NewController( informerFactory.Coordination().V1().Leases(), - informerFactory.Coordination().V1alpha1().LeaseCandidates(), + informerFactory.Coordination().V1alpha2().LeaseCandidates(), client.CoordinationV1(), - client.CoordinationV1alpha1(), + client.CoordinationV1alpha2(), ) controller.clock = fakeClock if err != nil { @@ -363,7 +363,7 @@ func TestReconcileElectionStep(t *testing.T) { // Set up the fake client with the candidates for _, candidate := range tc.candidates { - _, err = client.CoordinationV1alpha1().LeaseCandidates(candidate.Namespace).Create(ctx, candidate, metav1.CreateOptions{}) + _, err = client.CoordinationV1alpha2().LeaseCandidates(candidate.Namespace).Create(ctx, candidate, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } @@ -414,11 +414,11 @@ func TestReconcileElectionStep(t *testing.T) { // Verify that ping to candidate was issued if tc.candidatesPinged { pinged := false - candidatesList, err := client.CoordinationV1alpha1().LeaseCandidates(tc.leaseNN.Namespace).List(ctx, metav1.ListOptions{}) + candidatesList, err := client.CoordinationV1alpha2().LeaseCandidates(tc.leaseNN.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { t.Fatal(err) } - oldCandidateMap := make(map[string]*v1alpha1.LeaseCandidate) + oldCandidateMap := make(map[string]*v1alpha2.LeaseCandidate) for _, candidate := range tc.candidates { oldCandidateMap[candidate.Name] = candidate } @@ -443,25 +443,25 @@ func TestController(t *testing.T) { cases := []struct { name string leases []*v1.Lease - candidates []*v1alpha1.LeaseCandidate - createAfterControllerStart []*v1alpha1.LeaseCandidate + candidates []*v1alpha2.LeaseCandidate + createAfterControllerStart []*v1alpha2.LeaseCandidate deleteLeaseAfterControllerStart []types.NamespacedName expectedLeaderLeases []*v1.Lease }{ { name: "single candidate leader election", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -479,18 +479,18 @@ func TestController(t *testing.T) { }, { name: "multiple candidate leader election", - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -498,12 +498,12 @@ func TestController(t *testing.T) { Namespace: "kube-system", Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.20.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.20.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -511,12 +511,12 @@ func TestController(t *testing.T) { Namespace: "kube-system", Name: "component-identity-3", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.20.0", - BinaryVersion: "1.20.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.20.0", + BinaryVersion: "1.20.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -547,18 +547,18 @@ func TestController(t *testing.T) { }, }, }, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -593,18 +593,18 @@ func TestController(t *testing.T) { }, }, }, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -636,33 +636,33 @@ func TestController(t *testing.T) { }, }, }, - candidates: []*v1alpha1.LeaseCandidate{ + candidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-1", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.20.0", - BinaryVersion: "1.20.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.20.0", + BinaryVersion: "1.20.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, - createAfterControllerStart: []*v1alpha1.LeaseCandidate{ + createAfterControllerStart: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "kube-system", Name: "component-identity-2", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -693,9 +693,9 @@ func TestController(t *testing.T) { informerFactory := informers.NewSharedInformerFactory(client, 0) controller, err := NewController( informerFactory.Coordination().V1().Leases(), - informerFactory.Coordination().V1alpha1().LeaseCandidates(), + informerFactory.Coordination().V1alpha2().LeaseCandidates(), client.CoordinationV1(), - client.CoordinationV1alpha1(), + client.CoordinationV1alpha2(), ) if err != nil { t.Fatal(err) @@ -710,7 +710,7 @@ func TestController(t *testing.T) { } for _, obj := range tc.candidates { t.Logf("Pre-creating lease candidate %s/%s", obj.Namespace, obj.Name) - _, err := client.CoordinationV1alpha1().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{}) + _, err := client.CoordinationV1alpha2().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{}) if err != nil { t.Fatalf("Error pre-creating lease candidate %s/%s: %v", obj.Namespace, obj.Name, err) } @@ -748,7 +748,7 @@ func TestController(t *testing.T) { if *ph == *l.Spec.HolderIdentity { continue } - if _, err := client.CoordinationV1alpha1().LeaseCandidates(expectedLease.Namespace).Get(ctx, *l.Spec.HolderIdentity, metav1.GetOptions{}); err != nil { + if _, err := client.CoordinationV1alpha2().LeaseCandidates(expectedLease.Namespace).Get(ctx, *l.Spec.HolderIdentity, metav1.GetOptions{}); err != nil { continue // only candidate-aware controllers will follow preferredHolder } @@ -772,7 +772,7 @@ func TestController(t *testing.T) { case <-ctx.Done(): return case <-ticker.C: - cs, err := client.CoordinationV1alpha1().LeaseCandidates("").List(ctx, metav1.ListOptions{}) + cs, err := client.CoordinationV1alpha2().LeaseCandidates("").List(ctx, metav1.ListOptions{}) if err != nil { t.Logf("Error listing lease candidates: %v", err) continue @@ -781,7 +781,7 @@ func TestController(t *testing.T) { if c.Spec.PingTime != nil && (c.Spec.RenewTime == nil || c.Spec.PingTime.Time.After(c.Spec.RenewTime.Time)) { t.Logf("Answering ping for %s/%s", c.Namespace, c.Name) c.Spec.RenewTime = &metav1.MicroTime{Time: time.Now()} - _, err = client.CoordinationV1alpha1().LeaseCandidates(c.Namespace).Update(ctx, &c, metav1.UpdateOptions{}) + _, err = client.CoordinationV1alpha2().LeaseCandidates(c.Namespace).Update(ctx, &c, metav1.UpdateOptions{}) if err != nil { t.Logf("Error updating lease candidate %s/%s: %v", c.Namespace, c.Name, err) } @@ -793,7 +793,7 @@ func TestController(t *testing.T) { for _, obj := range tc.createAfterControllerStart { t.Logf("Post-creating lease candidate %s/%s", obj.Namespace, obj.Name) - _, err := client.CoordinationV1alpha1().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{}) + _, err := client.CoordinationV1alpha2().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{}) if err != nil { t.Fatalf("Error post-creating lease candidate %s/%s: %v", obj.Namespace, obj.Name, err) } diff --git a/pkg/controlplane/controller/leaderelection/leasecandidategc_controller.go b/pkg/controlplane/controller/leaderelection/leasecandidategc_controller.go index 9e11f623beb..a5e10f3cc5b 100644 --- a/pkg/controlplane/controller/leaderelection/leasecandidategc_controller.go +++ b/pkg/controlplane/controller/leaderelection/leasecandidategc_controller.go @@ -26,9 +26,9 @@ import ( "k8s.io/apimachinery/pkg/labels" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - coordinationv1alpha1informers "k8s.io/client-go/informers/coordination/v1alpha1" + coordinationv1alpha2informers "k8s.io/client-go/informers/coordination/v1alpha2" "k8s.io/client-go/kubernetes" - listers "k8s.io/client-go/listers/coordination/v1alpha1" + listers "k8s.io/client-go/listers/coordination/v1alpha2" "k8s.io/client-go/tools/cache" "k8s.io/utils/clock" @@ -39,7 +39,7 @@ type LeaseCandidateGCController struct { kubeclientset kubernetes.Interface leaseCandidateLister listers.LeaseCandidateLister - leaseCandidateInformer coordinationv1alpha1informers.LeaseCandidateInformer + leaseCandidateInformer coordinationv1alpha2informers.LeaseCandidateInformer leaseCandidatesSynced cache.InformerSynced gcCheckPeriod time.Duration @@ -48,7 +48,7 @@ type LeaseCandidateGCController struct { } // NewLeaseCandidateGC creates a new LeaseCandidateGCController. -func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Duration, leaseCandidateInformer coordinationv1alpha1informers.LeaseCandidateInformer) *LeaseCandidateGCController { +func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Duration, leaseCandidateInformer coordinationv1alpha2informers.LeaseCandidateInformer) *LeaseCandidateGCController { return &LeaseCandidateGCController{ kubeclientset: clientset, leaseCandidateLister: leaseCandidateInformer.Lister(), @@ -87,7 +87,7 @@ func (c *LeaseCandidateGCController) gc(ctx context.Context) { if !isLeaseCandidateExpired(c.clock, leaseCandidate) { continue } - lc, err := c.kubeclientset.CoordinationV1alpha1().LeaseCandidates(leaseCandidate.Namespace).Get(ctx, leaseCandidate.Name, metav1.GetOptions{}) + lc, err := c.kubeclientset.CoordinationV1alpha2().LeaseCandidates(leaseCandidate.Namespace).Get(ctx, leaseCandidate.Name, metav1.GetOptions{}) if err != nil { klog.ErrorS(err, "Error getting lc") continue @@ -96,7 +96,7 @@ func (c *LeaseCandidateGCController) gc(ctx context.Context) { if !isLeaseCandidateExpired(c.clock, lc) { continue } - if err := c.kubeclientset.CoordinationV1alpha1().LeaseCandidates(lc.Namespace).Delete( + if err := c.kubeclientset.CoordinationV1alpha2().LeaseCandidates(lc.Namespace).Delete( ctx, lc.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { klog.ErrorS(err, "Error deleting lease") } diff --git a/pkg/controlplane/controller/leaderelection/leasecandidategc_controller_test.go b/pkg/controlplane/controller/leaderelection/leasecandidategc_controller_test.go index da46af13e65..92b18b02d93 100644 --- a/pkg/controlplane/controller/leaderelection/leasecandidategc_controller_test.go +++ b/pkg/controlplane/controller/leaderelection/leasecandidategc_controller_test.go @@ -22,7 +22,7 @@ import ( "time" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/informers" @@ -33,24 +33,24 @@ import ( func TestLeaseCandidateGCController(t *testing.T) { tests := []struct { name string - leaseCandidates []*v1alpha1.LeaseCandidate + leaseCandidates []*v1alpha2.LeaseCandidate expectedDeletedCount int }{ { name: "delete expired lease candidates", - leaseCandidates: []*v1alpha1.LeaseCandidate{ + leaseCandidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)}, }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now().Add(-1 * leaseCandidateValidDuration))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now().Add(-1 * leaseCandidateValidDuration))), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -59,12 +59,12 @@ func TestLeaseCandidateGCController(t *testing.T) { Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)}, }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-B", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now().Add(-1 * leaseCandidateValidDuration))), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-B", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now().Add(-1 * leaseCandidateValidDuration))), + Strategy: v1.OldestEmulationVersion, }, }, { @@ -73,12 +73,12 @@ func TestLeaseCandidateGCController(t *testing.T) { Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-C", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-C", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -86,19 +86,19 @@ func TestLeaseCandidateGCController(t *testing.T) { }, { name: "no expired lease candidates", - leaseCandidates: []*v1alpha1.LeaseCandidate{ + leaseCandidates: []*v1alpha2.LeaseCandidate{ { ObjectMeta: metav1.ObjectMeta{ Name: "candidate1", Namespace: "default", CreationTimestamp: metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "component-A", - EmulationVersion: "1.19.0", - BinaryVersion: "1.19.0", - RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "component-A", + EmulationVersion: "1.19.0", + BinaryVersion: "1.19.0", + RenewTime: ptr.To(metav1.NewMicroTime(time.Now())), + Strategy: v1.OldestEmulationVersion, }, }, }, @@ -111,12 +111,12 @@ func TestLeaseCandidateGCController(t *testing.T) { ctx := context.Background() client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0) - leaseCandidateInformer := informerFactory.Coordination().V1alpha1().LeaseCandidates() + leaseCandidateInformer := informerFactory.Coordination().V1alpha2().LeaseCandidates() controller := NewLeaseCandidateGC(client, 10*time.Millisecond, leaseCandidateInformer) // Create lease candidates for _, lc := range tc.leaseCandidates { - _, err := client.CoordinationV1alpha1().LeaseCandidates(lc.Namespace).Create(ctx, lc, metav1.CreateOptions{}) + _, err := client.CoordinationV1alpha2().LeaseCandidates(lc.Namespace).Create(ctx, lc, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } @@ -127,7 +127,7 @@ func TestLeaseCandidateGCController(t *testing.T) { go controller.Run(ctx) err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 600*time.Second, true, func(ctx context.Context) (done bool, err error) { - lcs, err := client.CoordinationV1alpha1().LeaseCandidates("default").List(ctx, metav1.ListOptions{}) + lcs, err := client.CoordinationV1alpha2().LeaseCandidates("default").List(ctx, metav1.ListOptions{}) if err != nil { return true, err } diff --git a/pkg/controlplane/instance.go b/pkg/controlplane/instance.go index a34728a5097..255157707e6 100644 --- a/pkg/controlplane/instance.go +++ b/pkg/controlplane/instance.go @@ -38,7 +38,7 @@ import ( certificatesapiv1 "k8s.io/api/certificates/v1" certificatesv1alpha1 "k8s.io/api/certificates/v1alpha1" coordinationapiv1 "k8s.io/api/coordination/v1" - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2" apiv1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" eventsv1 "k8s.io/api/events/v1" @@ -471,7 +471,7 @@ var ( apiserverinternalv1alpha1.SchemeGroupVersion, authenticationv1alpha1.SchemeGroupVersion, apiserverinternalv1alpha1.SchemeGroupVersion, - coordinationv1alpha1.SchemeGroupVersion, + coordinationv1alpha2.SchemeGroupVersion, resourcev1alpha3.SchemeGroupVersion, certificatesv1alpha1.SchemeGroupVersion, networkingapiv1alpha1.SchemeGroupVersion, diff --git a/pkg/kubeapiserver/default_storage_factory_builder.go b/pkg/kubeapiserver/default_storage_factory_builder.go index ba679bfdaa7..8ebda0944a4 100644 --- a/pkg/kubeapiserver/default_storage_factory_builder.go +++ b/pkg/kubeapiserver/default_storage_factory_builder.go @@ -73,7 +73,7 @@ func NewStorageFactoryConfig() *StorageFactoryConfig { // // TODO (https://github.com/kubernetes/kubernetes/issues/108451): remove the override in 1.25. // apisstorage.Resource("csistoragecapacities").WithVersion("v1beta1"), - coordination.Resource("leasecandidates").WithVersion("v1alpha1"), + coordination.Resource("leasecandidates").WithVersion("v1alpha2"), networking.Resource("ipaddresses").WithVersion("v1beta1"), networking.Resource("servicecidrs").WithVersion("v1beta1"), admissionregistration.Resource("mutatingadmissionpolicies").WithVersion("v1alpha1"), diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index dacbaca4c9d..3ed1c4917ea 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -34,7 +34,7 @@ import ( certificatesv1alpha1 "k8s.io/api/certificates/v1alpha1" certificatesv1beta1 "k8s.io/api/certificates/v1beta1" coordinationv1 "k8s.io/api/coordination/v1" - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2" apiv1 "k8s.io/api/core/v1" discoveryv1beta1 "k8s.io/api/discovery/v1beta1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" @@ -435,7 +435,7 @@ func AddHandlers(h printers.PrintHandler) { leaseCandidateColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, - {Name: "LeaseName", Type: "string", Description: coordinationv1alpha1.LeaseCandidateSpec{}.SwaggerDoc()["leaseName"]}, + {Name: "LeaseName", Type: "string", Description: coordinationv1alpha2.LeaseCandidateSpec{}.SwaggerDoc()["leaseName"]}, {Name: "BinaryVersion", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["binaryVersion"]}, {Name: "EmulationVersion", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["emulationVersion"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, diff --git a/pkg/registry/coordination/rest/storage_coordination.go b/pkg/registry/coordination/rest/storage_coordination.go index f9bdf215bd8..16261f75779 100644 --- a/pkg/registry/coordination/rest/storage_coordination.go +++ b/pkg/registry/coordination/rest/storage_coordination.go @@ -18,7 +18,7 @@ package rest import ( coordinationv1 "k8s.io/api/coordination/v1" - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2" "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/rest" genericapiserver "k8s.io/apiserver/pkg/server" @@ -42,10 +42,10 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag apiGroupInfo.VersionedResourcesStorageMap[coordinationv1.SchemeGroupVersion.Version] = storageMap } - if storageMap, err := p.v1alpha1Storage(apiResourceConfigSource, restOptionsGetter); err != nil { + if storageMap, err := p.v1alpha2Storage(apiResourceConfigSource, restOptionsGetter); err != nil { return genericapiserver.APIGroupInfo{}, err } else if len(storageMap) > 0 { - apiGroupInfo.VersionedResourcesStorageMap[coordinationv1alpha1.SchemeGroupVersion.Version] = storageMap + apiGroupInfo.VersionedResourcesStorageMap[coordinationv1alpha2.SchemeGroupVersion.Version] = storageMap } return apiGroupInfo, nil @@ -65,11 +65,11 @@ func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.API return storage, nil } -func (p RESTStorageProvider) v1alpha1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) { +func (p RESTStorageProvider) v1alpha2Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) { storage := map[string]rest.Storage{} // identity - if resource := "leasecandidates"; apiResourceConfigSource.ResourceEnabled(coordinationv1alpha1.SchemeGroupVersion.WithResource(resource)) { + if resource := "leasecandidates"; apiResourceConfigSource.ResourceEnabled(coordinationv1alpha2.SchemeGroupVersion.WithResource(resource)) { leaseCandidateStorage, err := leasecandidatestorage.NewREST(restOptionsGetter) if err != nil { return storage, err diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/generated.pb.go b/staging/src/k8s.io/api/coordination/v1alpha1/generated.pb.go deleted file mode 100644 index 9e072e62d01..00000000000 --- a/staging/src/k8s.io/api/coordination/v1alpha1/generated.pb.go +++ /dev/null @@ -1,1036 +0,0 @@ -/* -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 protoc-gen-gogo. DO NOT EDIT. -// source: k8s.io/api/coordination/v1alpha1/generated.proto - -package v1alpha1 - -import ( - fmt "fmt" - - io "io" - - proto "github.com/gogo/protobuf/proto" - - k8s_io_api_coordination_v1 "k8s.io/api/coordination/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -func (m *LeaseCandidate) Reset() { *m = LeaseCandidate{} } -func (*LeaseCandidate) ProtoMessage() {} -func (*LeaseCandidate) Descriptor() ([]byte, []int) { - return fileDescriptor_cb9e87df9da593c2, []int{0} -} -func (m *LeaseCandidate) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaseCandidate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *LeaseCandidate) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaseCandidate.Merge(m, src) -} -func (m *LeaseCandidate) XXX_Size() int { - return m.Size() -} -func (m *LeaseCandidate) XXX_DiscardUnknown() { - xxx_messageInfo_LeaseCandidate.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaseCandidate proto.InternalMessageInfo - -func (m *LeaseCandidateList) Reset() { *m = LeaseCandidateList{} } -func (*LeaseCandidateList) ProtoMessage() {} -func (*LeaseCandidateList) Descriptor() ([]byte, []int) { - return fileDescriptor_cb9e87df9da593c2, []int{1} -} -func (m *LeaseCandidateList) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaseCandidateList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *LeaseCandidateList) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaseCandidateList.Merge(m, src) -} -func (m *LeaseCandidateList) XXX_Size() int { - return m.Size() -} -func (m *LeaseCandidateList) XXX_DiscardUnknown() { - xxx_messageInfo_LeaseCandidateList.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaseCandidateList proto.InternalMessageInfo - -func (m *LeaseCandidateSpec) Reset() { *m = LeaseCandidateSpec{} } -func (*LeaseCandidateSpec) ProtoMessage() {} -func (*LeaseCandidateSpec) Descriptor() ([]byte, []int) { - return fileDescriptor_cb9e87df9da593c2, []int{2} -} -func (m *LeaseCandidateSpec) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaseCandidateSpec) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *LeaseCandidateSpec) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaseCandidateSpec.Merge(m, src) -} -func (m *LeaseCandidateSpec) XXX_Size() int { - return m.Size() -} -func (m *LeaseCandidateSpec) XXX_DiscardUnknown() { - xxx_messageInfo_LeaseCandidateSpec.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaseCandidateSpec proto.InternalMessageInfo - -func init() { - proto.RegisterType((*LeaseCandidate)(nil), "k8s.io.api.coordination.v1alpha1.LeaseCandidate") - proto.RegisterType((*LeaseCandidateList)(nil), "k8s.io.api.coordination.v1alpha1.LeaseCandidateList") - proto.RegisterType((*LeaseCandidateSpec)(nil), "k8s.io.api.coordination.v1alpha1.LeaseCandidateSpec") -} - -func init() { - proto.RegisterFile("k8s.io/api/coordination/v1alpha1/generated.proto", fileDescriptor_cb9e87df9da593c2) -} - -var fileDescriptor_cb9e87df9da593c2 = []byte{ - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcb, 0x6e, 0xd3, 0x4c, - 0x14, 0xc7, 0xe3, 0x36, 0xf9, 0x94, 0xcc, 0xd7, 0xa0, 0x30, 0x15, 0x92, 0x95, 0x85, 0x13, 0x65, - 0x55, 0x21, 0x31, 0x6e, 0xa0, 0x42, 0x48, 0xec, 0x5c, 0x40, 0x42, 0x4a, 0x4b, 0xe5, 0x42, 0x25, - 0x50, 0x17, 0x4c, 0xec, 0x53, 0x67, 0x48, 0x7c, 0xd1, 0x78, 0x52, 0x94, 0x5d, 0x17, 0x3c, 0x00, - 0x8f, 0x15, 0x58, 0x75, 0xd9, 0x55, 0x44, 0xcc, 0x5b, 0xb0, 0x42, 0x33, 0xb1, 0x73, 0x6d, 0x94, - 0x88, 0x5d, 0xce, 0xe5, 0xf7, 0x3f, 0xe7, 0x7f, 0xac, 0x0c, 0x3a, 0xec, 0xbe, 0x88, 0x09, 0x0b, - 0x4d, 0x1a, 0x31, 0xd3, 0x09, 0x43, 0xee, 0xb2, 0x80, 0x0a, 0x16, 0x06, 0xe6, 0x75, 0x93, 0xf6, - 0xa2, 0x0e, 0x6d, 0x9a, 0x1e, 0x04, 0xc0, 0xa9, 0x00, 0x97, 0x44, 0x3c, 0x14, 0x21, 0xae, 0x4f, - 0x08, 0x42, 0x23, 0x46, 0xe6, 0x09, 0x92, 0x11, 0xd5, 0x27, 0x1e, 0x13, 0x9d, 0x7e, 0x9b, 0x38, - 0xa1, 0x6f, 0x7a, 0xa1, 0x17, 0x9a, 0x0a, 0x6c, 0xf7, 0xaf, 0x54, 0xa4, 0x02, 0xf5, 0x6b, 0x22, - 0x58, 0x7d, 0xbc, 0x7e, 0x85, 0xe5, 0xe1, 0xd5, 0xa3, 0x59, 0xaf, 0x4f, 0x9d, 0x0e, 0x0b, 0x80, - 0x0f, 0xcc, 0xa8, 0xeb, 0xc9, 0x44, 0x6c, 0xfa, 0x20, 0xe8, 0x7d, 0x94, 0xb9, 0x8e, 0xe2, 0xfd, - 0x40, 0x30, 0x1f, 0x56, 0x80, 0xe7, 0x9b, 0x80, 0xd8, 0xe9, 0x80, 0x4f, 0x97, 0xb9, 0xc6, 0x4f, - 0x0d, 0x3d, 0x68, 0x01, 0x8d, 0xe1, 0x98, 0x06, 0x2e, 0x73, 0xa9, 0x00, 0xfc, 0x19, 0x15, 0xe5, - 0x5a, 0x2e, 0x15, 0x54, 0xd7, 0xea, 0xda, 0xc1, 0xff, 0x4f, 0x0f, 0xc9, 0xec, 0x82, 0x53, 0x75, - 0x12, 0x75, 0x3d, 0x99, 0x88, 0x89, 0xec, 0x26, 0xd7, 0x4d, 0xf2, 0xae, 0xfd, 0x05, 0x1c, 0x71, - 0x02, 0x82, 0x5a, 0x78, 0x38, 0xaa, 0xe5, 0x92, 0x51, 0x0d, 0xcd, 0x72, 0xf6, 0x54, 0x15, 0x5f, - 0xa0, 0x7c, 0x1c, 0x81, 0xa3, 0xef, 0x28, 0xf5, 0x23, 0xb2, 0xe9, 0xfb, 0x90, 0xc5, 0x0d, 0xcf, - 0x23, 0x70, 0xac, 0xbd, 0x74, 0x42, 0x5e, 0x46, 0xb6, 0xd2, 0x6b, 0xfc, 0xd0, 0x10, 0x5e, 0x6c, - 0x6d, 0xb1, 0x58, 0xe0, 0xcb, 0x15, 0x43, 0x64, 0x3b, 0x43, 0x92, 0x56, 0x76, 0x2a, 0xe9, 0xb0, - 0x62, 0x96, 0x99, 0x33, 0xf3, 0x01, 0x15, 0x98, 0x00, 0x3f, 0xd6, 0x77, 0xea, 0xbb, 0x4b, 0xb7, - 0xda, 0xca, 0x8d, 0x55, 0x4e, 0xc5, 0x0b, 0x6f, 0xa5, 0x8c, 0x3d, 0x51, 0x6b, 0x7c, 0xcb, 0x2f, - 0x7b, 0x91, 0x46, 0xb1, 0x89, 0x4a, 0x3d, 0x99, 0x3d, 0xa5, 0x3e, 0x28, 0x33, 0x25, 0xeb, 0x61, - 0xca, 0x97, 0x5a, 0x59, 0xc1, 0x9e, 0xf5, 0xe0, 0x8f, 0xa8, 0x18, 0xb1, 0xc0, 0x7b, 0xcf, 0x7c, - 0x48, 0xef, 0x6d, 0x6e, 0x67, 0xfe, 0x84, 0x39, 0x3c, 0x94, 0x98, 0xb5, 0x27, 0x9d, 0x9f, 0xa5, - 0x22, 0xf6, 0x54, 0x0e, 0x5f, 0xa2, 0x12, 0x87, 0x00, 0xbe, 0x2a, 0xed, 0xdd, 0x7f, 0xd3, 0x2e, - 0xcb, 0xc5, 0xed, 0x4c, 0xc5, 0x9e, 0x09, 0xe2, 0x97, 0xa8, 0xdc, 0x66, 0x01, 0xe5, 0x83, 0x0b, - 0xe0, 0x31, 0x0b, 0x03, 0x3d, 0xaf, 0xdc, 0x3e, 0x4a, 0xdd, 0x96, 0xad, 0xf9, 0xa2, 0xbd, 0xd8, - 0x8b, 0x5f, 0xa1, 0x0a, 0xf8, 0xfd, 0x9e, 0x3a, 0x7c, 0xc6, 0x17, 0x14, 0xaf, 0xa7, 0x7c, 0xe5, - 0xf5, 0x52, 0xdd, 0x5e, 0x21, 0xf0, 0x8d, 0x86, 0xf6, 0x23, 0x0e, 0x57, 0xc0, 0x39, 0xb8, 0xe7, - 0x42, 0xfe, 0x6f, 0x3c, 0x06, 0xb1, 0xfe, 0x5f, 0x7d, 0xf7, 0xa0, 0x64, 0x9d, 0x26, 0xa3, 0xda, - 0xfe, 0xd9, 0x6a, 0xf9, 0xcf, 0xa8, 0xf6, 0x6c, 0xfd, 0x03, 0x41, 0x8e, 0xb3, 0x18, 0x5c, 0xf5, - 0xc1, 0x52, 0x70, 0x60, 0xdf, 0x37, 0xca, 0x7a, 0x33, 0x1c, 0x1b, 0xb9, 0xdb, 0xb1, 0x91, 0xbb, - 0x1b, 0x1b, 0xb9, 0x9b, 0xc4, 0xd0, 0x86, 0x89, 0xa1, 0xdd, 0x26, 0x86, 0x76, 0x97, 0x18, 0xda, - 0xaf, 0xc4, 0xd0, 0xbe, 0xff, 0x36, 0x72, 0x9f, 0xea, 0x9b, 0xde, 0xc4, 0xbf, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x05, 0x28, 0x49, 0xd9, 0x36, 0x05, 0x00, 0x00, -} - -func (m *LeaseCandidate) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseCandidate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaseCandidate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Spec.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size, err := m.ObjectMeta.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *LeaseCandidateList) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseCandidateList) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaseCandidateList) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Items) > 0 { - for iNdEx := len(m.Items) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Items[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - { - size, err := m.ListMeta.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *LeaseCandidateSpec) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseCandidateSpec) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaseCandidateSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.PreferredStrategies) > 0 { - for iNdEx := len(m.PreferredStrategies) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.PreferredStrategies[iNdEx]) - copy(dAtA[i:], m.PreferredStrategies[iNdEx]) - i = encodeVarintGenerated(dAtA, i, uint64(len(m.PreferredStrategies[iNdEx]))) - i-- - dAtA[i] = 0x32 - } - } - i -= len(m.EmulationVersion) - copy(dAtA[i:], m.EmulationVersion) - i = encodeVarintGenerated(dAtA, i, uint64(len(m.EmulationVersion))) - i-- - dAtA[i] = 0x2a - i -= len(m.BinaryVersion) - copy(dAtA[i:], m.BinaryVersion) - i = encodeVarintGenerated(dAtA, i, uint64(len(m.BinaryVersion))) - i-- - dAtA[i] = 0x22 - if m.RenewTime != nil { - { - size, err := m.RenewTime.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if m.PingTime != nil { - { - size, err := m.PingTime.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenerated(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - i -= len(m.LeaseName) - copy(dAtA[i:], m.LeaseName) - i = encodeVarintGenerated(dAtA, i, uint64(len(m.LeaseName))) - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintGenerated(dAtA []byte, offset int, v uint64) int { - offset -= sovGenerated(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *LeaseCandidate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.ObjectMeta.Size() - n += 1 + l + sovGenerated(uint64(l)) - l = m.Spec.Size() - n += 1 + l + sovGenerated(uint64(l)) - return n -} - -func (m *LeaseCandidateList) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.ListMeta.Size() - n += 1 + l + sovGenerated(uint64(l)) - if len(m.Items) > 0 { - for _, e := range m.Items { - l = e.Size() - n += 1 + l + sovGenerated(uint64(l)) - } - } - return n -} - -func (m *LeaseCandidateSpec) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.LeaseName) - n += 1 + l + sovGenerated(uint64(l)) - if m.PingTime != nil { - l = m.PingTime.Size() - n += 1 + l + sovGenerated(uint64(l)) - } - if m.RenewTime != nil { - l = m.RenewTime.Size() - n += 1 + l + sovGenerated(uint64(l)) - } - l = len(m.BinaryVersion) - n += 1 + l + sovGenerated(uint64(l)) - l = len(m.EmulationVersion) - n += 1 + l + sovGenerated(uint64(l)) - if len(m.PreferredStrategies) > 0 { - for _, s := range m.PreferredStrategies { - l = len(s) - n += 1 + l + sovGenerated(uint64(l)) - } - } - return n -} - -func sovGenerated(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenerated(x uint64) (n int) { - return sovGenerated(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *LeaseCandidate) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&LeaseCandidate{`, - `ObjectMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ObjectMeta), "ObjectMeta", "v1.ObjectMeta", 1), `&`, ``, 1) + `,`, - `Spec:` + strings.Replace(strings.Replace(this.Spec.String(), "LeaseCandidateSpec", "LeaseCandidateSpec", 1), `&`, ``, 1) + `,`, - `}`, - }, "") - return s -} -func (this *LeaseCandidateList) String() string { - if this == nil { - return "nil" - } - repeatedStringForItems := "[]LeaseCandidate{" - for _, f := range this.Items { - repeatedStringForItems += strings.Replace(strings.Replace(f.String(), "LeaseCandidate", "LeaseCandidate", 1), `&`, ``, 1) + "," - } - repeatedStringForItems += "}" - s := strings.Join([]string{`&LeaseCandidateList{`, - `ListMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ListMeta), "ListMeta", "v1.ListMeta", 1), `&`, ``, 1) + `,`, - `Items:` + repeatedStringForItems + `,`, - `}`, - }, "") - return s -} -func (this *LeaseCandidateSpec) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&LeaseCandidateSpec{`, - `LeaseName:` + fmt.Sprintf("%v", this.LeaseName) + `,`, - `PingTime:` + strings.Replace(fmt.Sprintf("%v", this.PingTime), "MicroTime", "v1.MicroTime", 1) + `,`, - `RenewTime:` + strings.Replace(fmt.Sprintf("%v", this.RenewTime), "MicroTime", "v1.MicroTime", 1) + `,`, - `BinaryVersion:` + fmt.Sprintf("%v", this.BinaryVersion) + `,`, - `EmulationVersion:` + fmt.Sprintf("%v", this.EmulationVersion) + `,`, - `PreferredStrategies:` + fmt.Sprintf("%v", this.PreferredStrategies) + `,`, - `}`, - }, "") - return s -} -func valueToStringGenerated(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *LeaseCandidate) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseCandidate: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseCandidate: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ObjectMeta", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ObjectMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Spec", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Spec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenerated(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenerated - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseCandidateList) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseCandidateList: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseCandidateList: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ListMeta", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ListMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Items", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Items = append(m.Items, LeaseCandidate{}) - if err := m.Items[len(m.Items)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenerated(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenerated - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseCandidateSpec) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseCandidateSpec: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseCandidateSpec: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseName", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.LeaseName = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PingTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.PingTime == nil { - m.PingTime = &v1.MicroTime{} - } - if err := m.PingTime.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RenewTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.RenewTime == nil { - m.RenewTime = &v1.MicroTime{} - } - if err := m.RenewTime.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BinaryVersion", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BinaryVersion = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EmulationVersion", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EmulationVersion = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PreferredStrategies", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenerated - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenerated - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenerated - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PreferredStrategies = append(m.PreferredStrategies, k8s_io_api_coordination_v1.CoordinatedLeaseStrategy(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenerated(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenerated - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGenerated(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenerated - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenerated - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenerated - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGenerated - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGenerated - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGenerated - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGenerated = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGenerated = fmt.Errorf("proto: unexpected end of group") -) diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/generated.proto b/staging/src/k8s.io/api/coordination/v1alpha1/generated.proto deleted file mode 100644 index 57895ad569d..00000000000 --- a/staging/src/k8s.io/api/coordination/v1alpha1/generated.proto +++ /dev/null @@ -1,105 +0,0 @@ -/* -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. -*/ - - -// This file was autogenerated by go-to-protobuf. Do not edit it manually! - -syntax = "proto2"; - -package k8s.io.api.coordination.v1alpha1; - -import "k8s.io/api/coordination/v1/generated.proto"; -import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; -import "k8s.io/apimachinery/pkg/runtime/generated.proto"; -import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; - -// Package-wide variables from generator "generated". -option go_package = "k8s.io/api/coordination/v1alpha1"; - -// LeaseCandidate defines a candidate for a Lease object. -// Candidates are created such that coordinated leader election will pick the best leader from the list of candidates. -message LeaseCandidate { - // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata - // +optional - optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; - - // spec contains the specification of the Lease. - // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status - // +optional - optional LeaseCandidateSpec spec = 2; -} - -// LeaseCandidateList is a list of Lease objects. -message LeaseCandidateList { - // Standard list metadata. - // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata - // +optional - optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; - - // items is a list of schema objects. - repeated LeaseCandidate items = 2; -} - -// LeaseCandidateSpec is a specification of a Lease. -message LeaseCandidateSpec { - // LeaseName is the name of the lease for which this candidate is contending. - // This field is immutable. - // +required - optional string leaseName = 1; - - // PingTime is the last time that the server has requested the LeaseCandidate - // to renew. It is only done during leader election to check if any - // LeaseCandidates have become ineligible. When PingTime is updated, the - // LeaseCandidate will respond by updating RenewTime. - // +optional - optional .k8s.io.apimachinery.pkg.apis.meta.v1.MicroTime pingTime = 2; - - // RenewTime is the time that the LeaseCandidate was last updated. - // Any time a Lease needs to do leader election, the PingTime field - // is updated to signal to the LeaseCandidate that they should update - // the RenewTime. - // Old LeaseCandidate objects are also garbage collected if it has been hours - // since the last renew. The PingTime field is updated regularly to prevent - // garbage collection for still active LeaseCandidates. - // +optional - optional .k8s.io.apimachinery.pkg.apis.meta.v1.MicroTime renewTime = 3; - - // BinaryVersion is the binary version. It must be in a semver format without leading `v`. - // This field is required when strategy is "OldestEmulationVersion" - // +optional - optional string binaryVersion = 4; - - // EmulationVersion is the emulation version. It must be in a semver format without leading `v`. - // EmulationVersion must be less than or equal to BinaryVersion. - // This field is required when strategy is "OldestEmulationVersion" - // +optional - optional string emulationVersion = 5; - - // PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election. - // The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated - // leader election to make a decision about the final election strategy. This follows as - // - If all clients have strategy X as the first element in this list, strategy X will be used. - // - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y - // will be used. - // - If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader - // election will not operate the Lease until resolved. - // (Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled. - // +featureGate=CoordinatedLeaderElection - // +listType=atomic - // +required - repeated string preferredStrategies = 6; -} - diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/coordination/v1alpha1/types_swagger_doc_generated.go deleted file mode 100644 index 0e52809c8ca..00000000000 --- a/staging/src/k8s.io/api/coordination/v1alpha1/types_swagger_doc_generated.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -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. -*/ - -package v1alpha1 - -// This file contains a collection of methods that can be used from go-restful to -// generate Swagger API documentation for its models. Please read this PR for more -// information on the implementation: https://github.com/emicklei/go-restful/pull/215 -// -// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if -// they are on one line! For multiple line or blocks that you want to ignore use ---. -// Any context after a --- is ignored. -// -// Those methods can be generated by using hack/update-codegen.sh - -// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT. -var map_LeaseCandidate = map[string]string{ - "": "LeaseCandidate defines a candidate for a Lease object. Candidates are created such that coordinated leader election will pick the best leader from the list of candidates.", - "metadata": "More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata", - "spec": "spec contains the specification of the Lease. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status", -} - -func (LeaseCandidate) SwaggerDoc() map[string]string { - return map_LeaseCandidate -} - -var map_LeaseCandidateList = map[string]string{ - "": "LeaseCandidateList is a list of Lease objects.", - "metadata": "Standard list metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata", - "items": "items is a list of schema objects.", -} - -func (LeaseCandidateList) SwaggerDoc() map[string]string { - return map_LeaseCandidateList -} - -var map_LeaseCandidateSpec = map[string]string{ - "": "LeaseCandidateSpec is a specification of a Lease.", - "leaseName": "LeaseName is the name of the lease for which this candidate is contending. This field is immutable.", - "pingTime": "PingTime is the last time that the server has requested the LeaseCandidate to renew. It is only done during leader election to check if any LeaseCandidates have become ineligible. When PingTime is updated, the LeaseCandidate will respond by updating RenewTime.", - "renewTime": "RenewTime is the time that the LeaseCandidate was last updated. Any time a Lease needs to do leader election, the PingTime field is updated to signal to the LeaseCandidate that they should update the RenewTime. Old LeaseCandidate objects are also garbage collected if it has been hours since the last renew. The PingTime field is updated regularly to prevent garbage collection for still active LeaseCandidates.", - "binaryVersion": "BinaryVersion is the binary version. It must be in a semver format without leading `v`. This field is required when strategy is \"OldestEmulationVersion\"", - "emulationVersion": "EmulationVersion is the emulation version. It must be in a semver format without leading `v`. EmulationVersion must be less than or equal to BinaryVersion. This field is required when strategy is \"OldestEmulationVersion\"", - "preferredStrategies": "PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election. The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated leader election to make a decision about the final election strategy. This follows as - If all clients have strategy X as the first element in this list, strategy X will be used. - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y\n will be used.\n- If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader\n election will not operate the Lease until resolved.\n(Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled.", -} - -func (LeaseCandidateSpec) SwaggerDoc() map[string]string { - return map_LeaseCandidateSpec -} - -// AUTO-GENERATED FUNCTIONS END HERE diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.deepcopy.go b/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 9cf15d21dce..00000000000 --- a/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,116 +0,0 @@ -//go:build !ignore_autogenerated -// +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 v1alpha1 - -import ( - v1 "k8s.io/api/coordination/v1" - 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 *LeaseCandidate) DeepCopyInto(out *LeaseCandidate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaseCandidate. -func (in *LeaseCandidate) DeepCopy() *LeaseCandidate { - if in == nil { - return nil - } - out := new(LeaseCandidate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *LeaseCandidate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LeaseCandidateList) DeepCopyInto(out *LeaseCandidateList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]LeaseCandidate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaseCandidateList. -func (in *LeaseCandidateList) DeepCopy() *LeaseCandidateList { - if in == nil { - return nil - } - out := new(LeaseCandidateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *LeaseCandidateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LeaseCandidateSpec) DeepCopyInto(out *LeaseCandidateSpec) { - *out = *in - if in.PingTime != nil { - in, out := &in.PingTime, &out.PingTime - *out = (*in).DeepCopy() - } - if in.RenewTime != nil { - in, out := &in.RenewTime, &out.RenewTime - *out = (*in).DeepCopy() - } - if in.PreferredStrategies != nil { - in, out := &in.PreferredStrategies, &out.PreferredStrategies - *out = make([]v1.CoordinatedLeaseStrategy, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeaseCandidateSpec. -func (in *LeaseCandidateSpec) DeepCopy() *LeaseCandidateSpec { - if in == nil { - return nil - } - out := new(LeaseCandidateSpec) - in.DeepCopyInto(out) - return out -} diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.prerelease-lifecycle.go b/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.prerelease-lifecycle.go deleted file mode 100644 index f42bef65c9d..00000000000 --- a/staging/src/k8s.io/api/coordination/v1alpha1/zz_generated.prerelease-lifecycle.go +++ /dev/null @@ -1,58 +0,0 @@ -//go:build !ignore_autogenerated -// +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 prerelease-lifecycle-gen. DO NOT EDIT. - -package v1alpha1 - -// APILifecycleIntroduced is an autogenerated function, returning the release in which the API struct was introduced as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:introduced" tags in types.go. -func (in *LeaseCandidate) APILifecycleIntroduced() (major, minor int) { - return 1, 31 -} - -// APILifecycleDeprecated is an autogenerated function, returning the release in which the API struct was or will be deprecated as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:deprecated" tags in types.go or "k8s:prerelease-lifecycle-gen:introduced" plus three minor. -func (in *LeaseCandidate) APILifecycleDeprecated() (major, minor int) { - return 1, 34 -} - -// APILifecycleRemoved is an autogenerated function, returning the release in which the API is no longer served as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:removed" tags in types.go or "k8s:prerelease-lifecycle-gen:deprecated" plus three minor. -func (in *LeaseCandidate) APILifecycleRemoved() (major, minor int) { - return 1, 37 -} - -// APILifecycleIntroduced is an autogenerated function, returning the release in which the API struct was introduced as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:introduced" tags in types.go. -func (in *LeaseCandidateList) APILifecycleIntroduced() (major, minor int) { - return 1, 31 -} - -// APILifecycleDeprecated is an autogenerated function, returning the release in which the API struct was or will be deprecated as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:deprecated" tags in types.go or "k8s:prerelease-lifecycle-gen:introduced" plus three minor. -func (in *LeaseCandidateList) APILifecycleDeprecated() (major, minor int) { - return 1, 34 -} - -// APILifecycleRemoved is an autogenerated function, returning the release in which the API is no longer served as int versions of major and minor for comparison. -// It is controlled by "k8s:prerelease-lifecycle-gen:removed" tags in types.go or "k8s:prerelease-lifecycle-gen:deprecated" plus three minor. -func (in *LeaseCandidateList) APILifecycleRemoved() (major, minor int) { - return 1, 37 -} diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/doc.go b/staging/src/k8s.io/api/coordination/v1alpha2/doc.go similarity index 92% rename from staging/src/k8s.io/api/coordination/v1alpha1/doc.go rename to staging/src/k8s.io/api/coordination/v1alpha2/doc.go index 33a0b0ea97f..5e6d655302e 100644 --- a/staging/src/k8s.io/api/coordination/v1alpha1/doc.go +++ b/staging/src/k8s.io/api/coordination/v1alpha2/doc.go @@ -21,4 +21,4 @@ limitations under the License. // +groupName=coordination.k8s.io -package v1alpha1 // import "k8s.io/api/coordination/v1alpha1" +package v1alpha2 // import "k8s.io/api/coordination/v1alpha2" diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/register.go b/staging/src/k8s.io/api/coordination/v1alpha2/register.go similarity index 95% rename from staging/src/k8s.io/api/coordination/v1alpha1/register.go rename to staging/src/k8s.io/api/coordination/v1alpha2/register.go index 6e57905a190..86bb8e0f2e3 100644 --- a/staging/src/k8s.io/api/coordination/v1alpha1/register.go +++ b/staging/src/k8s.io/api/coordination/v1alpha2/register.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2024 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. @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package v1alpha2 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,7 +26,7 @@ import ( const GroupName = "coordination.k8s.io" // SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"} // Resource takes an unqualified resource and returns a Group qualified GroupResource func Resource(resource string) schema.GroupResource { diff --git a/staging/src/k8s.io/api/coordination/v1alpha1/types.go b/staging/src/k8s.io/api/coordination/v1alpha2/types.go similarity index 75% rename from staging/src/k8s.io/api/coordination/v1alpha1/types.go rename to staging/src/k8s.io/api/coordination/v1alpha2/types.go index 14066600cf5..2f53b097a28 100644 --- a/staging/src/k8s.io/api/coordination/v1alpha1/types.go +++ b/staging/src/k8s.io/api/coordination/v1alpha2/types.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2024 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. @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package v1alpha2 import ( v1 "k8s.io/api/coordination/v1" @@ -23,7 +23,7 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:prerelease-lifecycle-gen:introduced=1.31 +// +k8s:prerelease-lifecycle-gen:introduced=1.32 // LeaseCandidate defines a candidate for a Lease object. // Candidates are created such that coordinated leader election will pick the best leader from the list of candidates. @@ -61,31 +61,26 @@ type LeaseCandidateSpec struct { // +optional RenewTime *metav1.MicroTime `json:"renewTime,omitempty" protobuf:"bytes,3,opt,name=renewTime"` // BinaryVersion is the binary version. It must be in a semver format without leading `v`. - // This field is required when strategy is "OldestEmulationVersion" - // +optional - BinaryVersion string `json:"binaryVersion,omitempty" protobuf:"bytes,4,opt,name=binaryVersion"` + // This field is required. + // +required + BinaryVersion string `json:"binaryVersion" protobuf:"bytes,4,name=binaryVersion"` // EmulationVersion is the emulation version. It must be in a semver format without leading `v`. // EmulationVersion must be less than or equal to BinaryVersion. // This field is required when strategy is "OldestEmulationVersion" // +optional EmulationVersion string `json:"emulationVersion,omitempty" protobuf:"bytes,5,opt,name=emulationVersion"` - // PreferredStrategies indicates the list of strategies for picking the leader for coordinated leader election. - // The list is ordered, and the first strategy supersedes all other strategies. The list is used by coordinated - // leader election to make a decision about the final election strategy. This follows as - // - If all clients have strategy X as the first element in this list, strategy X will be used. - // - If a candidate has strategy [X] and another candidate has strategy [Y, X], Y supersedes X and strategy Y - // will be used. - // - If a candidate has strategy [X, Y] and another candidate has strategy [Y, X], this is a user error and leader - // election will not operate the Lease until resolved. + // Strategy is the strategy that coordinated leader election will use for picking the leader. + // If multiple candidates for the same Lease return different strategies, the strategy provided + // by the candidate with the latest BinaryVersion will be used. If there is still conflict, + // this is a user error and coordinated leader election will not operate the Lease until resolved. // (Alpha) Using this field requires the CoordinatedLeaderElection feature gate to be enabled. // +featureGate=CoordinatedLeaderElection - // +listType=atomic // +required - PreferredStrategies []v1.CoordinatedLeaseStrategy `json:"preferredStrategies,omitempty" protobuf:"bytes,6,opt,name=preferredStrategies"` + Strategy v1.CoordinatedLeaseStrategy `json:"strategy,omitempty" protobuf:"bytes,6,opt,name=strategy"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:prerelease-lifecycle-gen:introduced=1.31 +// +k8s:prerelease-lifecycle-gen:introduced=1.32 // LeaseCandidateList is a list of Lease objects. type LeaseCandidateList struct { diff --git a/staging/src/k8s.io/api/roundtrip_test.go b/staging/src/k8s.io/api/roundtrip_test.go index 0faa385926a..e16583a5955 100644 --- a/staging/src/k8s.io/api/roundtrip_test.go +++ b/staging/src/k8s.io/api/roundtrip_test.go @@ -45,7 +45,7 @@ import ( certificatesv1alpha1 "k8s.io/api/certificates/v1alpha1" certificatesv1beta1 "k8s.io/api/certificates/v1beta1" coordinationv1 "k8s.io/api/coordination/v1" - coordinationv1alpha1 "k8s.io/api/coordination/v1alpha1" + coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2" coordinationv1beta1 "k8s.io/api/coordination/v1beta1" corev1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" @@ -113,7 +113,7 @@ var groups = []runtime.SchemeBuilder{ certificatesv1alpha1.SchemeBuilder, coordinationv1.SchemeBuilder, coordinationv1beta1.SchemeBuilder, - coordinationv1alpha1.SchemeBuilder, + coordinationv1alpha2.SchemeBuilder, corev1.SchemeBuilder, discoveryv1.SchemeBuilder, discoveryv1beta1.SchemeBuilder, diff --git a/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate.go b/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate.go index 74cf5bb5c25..6ccd4cfbeed 100644 --- a/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate.go +++ b/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate.go @@ -22,14 +22,14 @@ import ( "time" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" - coordinationv1alpha1client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha1" + coordinationv1alpha2client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha2" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -43,7 +43,7 @@ type CacheSyncWaiter interface { } type LeaseCandidate struct { - leaseClient coordinationv1alpha1client.LeaseCandidateInterface + leaseClient coordinationv1alpha2client.LeaseCandidateInterface leaseCandidateInformer cache.SharedIndexInformer informerFactory informers.SharedInformerFactory hasSynced cache.InformerSynced @@ -60,7 +60,7 @@ type LeaseCandidate struct { clock clock.Clock binaryVersion, emulationVersion string - preferredStrategies []v1.CoordinatedLeaseStrategy + strategy v1.CoordinatedLeaseStrategy } // NewCandidate creates new LeaseCandidate controller that creates a @@ -73,7 +73,7 @@ func NewCandidate(clientset kubernetes.Interface, candidateName string, targetLease string, binaryVersion, emulationVersion string, - preferredStrategies []v1.CoordinatedLeaseStrategy, + strategy v1.CoordinatedLeaseStrategy, ) (*LeaseCandidate, CacheSyncWaiter, error) { fieldSelector := fields.OneTermEqualSelector("metadata.name", candidateName).String() // A separate informer factory is required because this must start before informerFactories @@ -84,10 +84,10 @@ func NewCandidate(clientset kubernetes.Interface, options.FieldSelector = fieldSelector }), ) - leaseCandidateInformer := informerFactory.Coordination().V1alpha1().LeaseCandidates().Informer() + leaseCandidateInformer := informerFactory.Coordination().V1alpha2().LeaseCandidates().Informer() lc := &LeaseCandidate{ - leaseClient: clientset.CoordinationV1alpha1().LeaseCandidates(candidateNamespace), + leaseClient: clientset.CoordinationV1alpha2().LeaseCandidates(candidateNamespace), leaseCandidateInformer: leaseCandidateInformer, informerFactory: informerFactory, name: candidateName, @@ -96,13 +96,13 @@ func NewCandidate(clientset kubernetes.Interface, clock: clock.RealClock{}, binaryVersion: binaryVersion, emulationVersion: emulationVersion, - preferredStrategies: preferredStrategies, + strategy: strategy, } lc.queue = workqueue.NewTypedRateLimitingQueueWithConfig(workqueue.DefaultTypedControllerRateLimiter[int](), workqueue.TypedRateLimitingQueueConfig[int]{Name: "leasecandidate"}) h, err := leaseCandidateInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ UpdateFunc: func(oldObj, newObj interface{}) { - if leasecandidate, ok := newObj.(*v1alpha1.LeaseCandidate); ok { + if leasecandidate, ok := newObj.(*v1alpha2.LeaseCandidate); ok { if leasecandidate.Spec.PingTime != nil && leasecandidate.Spec.PingTime.After(leasecandidate.Spec.RenewTime.Time) { lc.enqueueLease() } @@ -184,17 +184,17 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error { return nil } -func (c *LeaseCandidate) newLeaseCandidate() *v1alpha1.LeaseCandidate { - lc := &v1alpha1.LeaseCandidate{ +func (c *LeaseCandidate) newLeaseCandidate() *v1alpha2.LeaseCandidate { + lc := &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: c.name, Namespace: c.namespace, }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: c.leaseName, - BinaryVersion: c.binaryVersion, - EmulationVersion: c.emulationVersion, - PreferredStrategies: c.preferredStrategies, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: c.leaseName, + BinaryVersion: c.binaryVersion, + EmulationVersion: c.emulationVersion, + Strategy: c.strategy, }, } lc.Spec.RenewTime = &metav1.MicroTime{Time: c.clock.Now()} diff --git a/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate_test.go b/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate_test.go index c50059180e3..661643a1e83 100644 --- a/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate_test.go +++ b/staging/src/k8s.io/client-go/tools/leaderelection/leasecandidate_test.go @@ -53,7 +53,7 @@ func TestLeaseCandidateCreation(t *testing.T) { tc.leaseName, tc.binaryVersion, tc.emulationVersion, - []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + v1.OldestEmulationVersion, ) if err != nil { t.Fatal(err) @@ -87,7 +87,7 @@ func TestLeaseCandidateAck(t *testing.T) { tc.leaseName, tc.binaryVersion, tc.emulationVersion, - []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, + v1.OldestEmulationVersion, ) if err != nil { t.Fatal(err) @@ -101,12 +101,12 @@ func TestLeaseCandidateAck(t *testing.T) { // Update PingTime and verify that the client renews ensureAfter := &metav1.MicroTime{Time: time.Now()} - lc, err := client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{}) + lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{}) if err == nil { if lc.Spec.PingTime == nil { c := lc.DeepCopy() c.Spec.PingTime = &metav1.MicroTime{Time: time.Now()} - _, err = client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{}) + _, err = client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{}) if err != nil { t.Error(err) } @@ -120,7 +120,7 @@ func TestLeaseCandidateAck(t *testing.T) { func pollForLease(ctx context.Context, tc testcase, client *fake.Clientset, t *metav1.MicroTime) error { return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 10*time.Second, true, func(ctx context.Context) (done bool, err error) { - lc, err := client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{}) + lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { return false, nil diff --git a/test/integration/apiserver/coordinated_leader_election_test.go b/test/integration/apiserver/coordinated_leader_election_test.go index 55e496d63b6..5bfe1946fc6 100644 --- a/test/integration/apiserver/coordinated_leader_election_test.go +++ b/test/integration/apiserver/coordinated_leader_election_test.go @@ -24,7 +24,7 @@ import ( "time" v1 "k8s.io/api/coordination/v1" - v1alpha1 "k8s.io/api/coordination/v1alpha1" + v1alpha2 "k8s.io/api/coordination/v1alpha2" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -144,28 +144,28 @@ func TestLeaseCandidateCleanup(t *testing.T) { if err != nil { t.Fatal(err) } - expiredLC := &v1alpha1.LeaseCandidate{ + expiredLC := &v1alpha2.LeaseCandidate{ ObjectMeta: metav1.ObjectMeta{ Name: "expired", Namespace: "default", }, - Spec: v1alpha1.LeaseCandidateSpec{ - LeaseName: "foobaz", - BinaryVersion: "0.1.0", - EmulationVersion: "0.1.0", - PreferredStrategies: []v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion}, - RenewTime: &metav1.MicroTime{Time: time.Now().Add(-2 * time.Hour)}, - PingTime: &metav1.MicroTime{Time: time.Now().Add(-1 * time.Hour)}, + Spec: v1alpha2.LeaseCandidateSpec{ + LeaseName: "foobaz", + BinaryVersion: "0.1.0", + EmulationVersion: "0.1.0", + Strategy: v1.OldestEmulationVersion, + RenewTime: &metav1.MicroTime{Time: time.Now().Add(-2 * time.Hour)}, + PingTime: &metav1.MicroTime{Time: time.Now().Add(-1 * time.Hour)}, }, } ctx := context.Background() - _, err = clientset.CoordinationV1alpha1().LeaseCandidates("default").Create(ctx, expiredLC, metav1.CreateOptions{}) + _, err = clientset.CoordinationV1alpha2().LeaseCandidates("default").Create(ctx, expiredLC, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } err = wait.PollUntilContextTimeout(ctx, 1000*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (done bool, err error) { - _, err = clientset.CoordinationV1alpha1().LeaseCandidates("default").Get(ctx, "expired", metav1.GetOptions{}) + _, err = clientset.CoordinationV1alpha2().LeaseCandidates("default").Get(ctx, "expired", metav1.GetOptions{}) if apierrors.IsNotFound(err) { return true, nil } @@ -218,7 +218,7 @@ func (t *cleTest) createAndRunFakeController(name string, namespace string, targ targetLease, binaryVersion, compatibilityVersion, - []v1.CoordinatedLeaseStrategy{"OldestEmulationVersion"}, + v1.OldestEmulationVersion, ) if err != nil { t.t.Error(err) diff --git a/test/integration/etcd/data.go b/test/integration/etcd/data.go index 285297d5a95..5d3d7713a94 100644 --- a/test/integration/etcd/data.go +++ b/test/integration/etcd/data.go @@ -172,10 +172,10 @@ func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionRes }, // -- - // k8s.io/kubernetes/pkg/apis/coordination/v1alpha1 - gvr("coordination.k8s.io", "v1alpha1", "leasecandidates"): { - Stub: `{"metadata": {"name": "leasecandidatev1alpha1"}, "spec": {"leaseName": "lease", "binaryVersion": "0.1.0", "emulationVersion": "0.1.0", "preferredStrategies": ["OldestEmulationVersion"]}}`, - ExpectedEtcdPath: "/registry/leasecandidates/" + namespace + "/leasecandidatev1alpha1", + // k8s.io/kubernetes/pkg/apis/coordination/v1alpha2 + gvr("coordination.k8s.io", "v1alpha2", "leasecandidates"): { + Stub: `{"metadata": {"name": "leasecandidatev1alpha2"}, "spec": {"leaseName": "lease", "binaryVersion": "0.1.0", "emulationVersion": "0.1.0", "strategy": "OldestEmulationVersion"}}`, + ExpectedEtcdPath: "/registry/leasecandidates/" + namespace + "/leasecandidatev1alpha2", }, // --