mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	LeaseCandidate alpha -> beta,
This commit is contained in:
		@@ -166,7 +166,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if utilfeature.DefaultFeatureGate.Enabled(apiserverfeatures.CoordinatedLeaderElection) {
 | 
						if utilfeature.DefaultFeatureGate.Enabled(apiserverfeatures.CoordinatedLeaderElection) {
 | 
				
			||||||
		leaseInformer := s.VersionedInformers.Coordination().V1().Leases()
 | 
							leaseInformer := s.VersionedInformers.Coordination().V1().Leases()
 | 
				
			||||||
		lcInformer := s.VersionedInformers.Coordination().V1alpha2().LeaseCandidates()
 | 
							lcInformer := s.VersionedInformers.Coordination().V1beta1().LeaseCandidates()
 | 
				
			||||||
		// Ensure that informers are registered before starting. Coordinated Leader Election leader-elected
 | 
							// Ensure that informers are registered before starting. Coordinated Leader Election leader-elected
 | 
				
			||||||
		// and may register informer handlers after they are started.
 | 
							// and may register informer handlers after they are started.
 | 
				
			||||||
		_ = leaseInformer.Informer()
 | 
							_ = leaseInformer.Informer()
 | 
				
			||||||
@@ -177,7 +177,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
 | 
				
			|||||||
					leaseInformer,
 | 
										leaseInformer,
 | 
				
			||||||
					lcInformer,
 | 
										lcInformer,
 | 
				
			||||||
					client.CoordinationV1(),
 | 
										client.CoordinationV1(),
 | 
				
			||||||
					client.CoordinationV1alpha2(),
 | 
										client.CoordinationV1beta1(),
 | 
				
			||||||
				)
 | 
									)
 | 
				
			||||||
				gccontroller := leaderelection.NewLeaseCandidateGC(
 | 
									gccontroller := leaderelection.NewLeaseCandidateGC(
 | 
				
			||||||
					client,
 | 
										client,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,12 +22,12 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/blang/semver/v4"
 | 
						"github.com/blang/semver/v4"
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/utils/clock"
 | 
						"k8s.io/utils/clock"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func pickBestLeaderOldestEmulationVersion(candidates []*v1alpha2.LeaseCandidate) *v1alpha2.LeaseCandidate {
 | 
					func pickBestLeaderOldestEmulationVersion(candidates []*v1beta1.LeaseCandidate) *v1beta1.LeaseCandidate {
 | 
				
			||||||
	var electee *v1alpha2.LeaseCandidate
 | 
						var electee *v1beta1.LeaseCandidate
 | 
				
			||||||
	for _, c := range candidates {
 | 
						for _, c := range candidates {
 | 
				
			||||||
		if !validLeaseCandidateForOldestEmulationVersion(c) {
 | 
							if !validLeaseCandidateForOldestEmulationVersion(c) {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
@@ -39,7 +39,7 @@ func pickBestLeaderOldestEmulationVersion(candidates []*v1alpha2.LeaseCandidate)
 | 
				
			|||||||
	return electee
 | 
						return electee
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func pickBestStrategy(candidates []*v1alpha2.LeaseCandidate) (v1.CoordinatedLeaseStrategy, error) {
 | 
					func pickBestStrategy(candidates []*v1beta1.LeaseCandidate) (v1.CoordinatedLeaseStrategy, error) {
 | 
				
			||||||
	nilStrategy := v1.CoordinatedLeaseStrategy("")
 | 
						nilStrategy := v1.CoordinatedLeaseStrategy("")
 | 
				
			||||||
	if len(candidates) == 0 {
 | 
						if len(candidates) == 0 {
 | 
				
			||||||
		return nilStrategy, fmt.Errorf("no candidates")
 | 
							return nilStrategy, fmt.Errorf("no candidates")
 | 
				
			||||||
@@ -62,7 +62,7 @@ func pickBestStrategy(candidates []*v1alpha2.LeaseCandidate) (v1.CoordinatedLeas
 | 
				
			|||||||
	return strategy, nil
 | 
						return strategy, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func validLeaseCandidateForOldestEmulationVersion(l *v1alpha2.LeaseCandidate) bool {
 | 
					func validLeaseCandidateForOldestEmulationVersion(l *v1beta1.LeaseCandidate) bool {
 | 
				
			||||||
	_, err := semver.ParseTolerant(l.Spec.EmulationVersion)
 | 
						_, err := semver.ParseTolerant(l.Spec.EmulationVersion)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
@@ -71,7 +71,7 @@ func validLeaseCandidateForOldestEmulationVersion(l *v1alpha2.LeaseCandidate) bo
 | 
				
			|||||||
	return err == nil
 | 
						return err == nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getEmulationVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version {
 | 
					func getEmulationVersionOrZero(l *v1beta1.LeaseCandidate) semver.Version {
 | 
				
			||||||
	value := l.Spec.EmulationVersion
 | 
						value := l.Spec.EmulationVersion
 | 
				
			||||||
	v, err := semver.ParseTolerant(value)
 | 
						v, err := semver.ParseTolerant(value)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -80,7 +80,7 @@ func getEmulationVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version {
 | 
				
			|||||||
	return v
 | 
						return v
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getBinaryVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version {
 | 
					func getBinaryVersionOrZero(l *v1beta1.LeaseCandidate) semver.Version {
 | 
				
			||||||
	value := l.Spec.BinaryVersion
 | 
						value := l.Spec.BinaryVersion
 | 
				
			||||||
	v, err := semver.ParseTolerant(value)
 | 
						v, err := semver.ParseTolerant(value)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -90,7 +90,7 @@ func getBinaryVersionOrZero(l *v1alpha2.LeaseCandidate) semver.Version {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// -1: lhs better, 1: rhs better
 | 
					// -1: lhs better, 1: rhs better
 | 
				
			||||||
func compare(lhs, rhs *v1alpha2.LeaseCandidate) int {
 | 
					func compare(lhs, rhs *v1beta1.LeaseCandidate) int {
 | 
				
			||||||
	l := getEmulationVersionOrZero(lhs)
 | 
						l := getEmulationVersionOrZero(lhs)
 | 
				
			||||||
	r := getEmulationVersionOrZero(rhs)
 | 
						r := getEmulationVersionOrZero(rhs)
 | 
				
			||||||
	result := l.Compare(r)
 | 
						result := l.Compare(r)
 | 
				
			||||||
@@ -115,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)
 | 
							lease.Spec.RenewTime.Add(time.Duration(*lease.Spec.LeaseDurationSeconds)*time.Second).Before(currentTime)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func isLeaseCandidateExpired(clock clock.Clock, lease *v1alpha2.LeaseCandidate) bool {
 | 
					func isLeaseCandidateExpired(clock clock.Clock, lease *v1beta1.LeaseCandidate) bool {
 | 
				
			||||||
	currentTime := clock.Now()
 | 
						currentTime := clock.Now()
 | 
				
			||||||
	return lease.Spec.RenewTime == nil ||
 | 
						return lease.Spec.RenewTime == nil ||
 | 
				
			||||||
		lease.Spec.RenewTime.Add(leaseCandidateValidDuration).Before(currentTime)
 | 
							lease.Spec.RenewTime.Add(leaseCandidateValidDuration).Before(currentTime)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,42 +22,42 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/blang/semver/v4"
 | 
						"github.com/blang/semver/v4"
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
					func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name       string
 | 
							name       string
 | 
				
			||||||
		candidates []*v1alpha2.LeaseCandidate
 | 
							candidates []*v1beta1.LeaseCandidate
 | 
				
			||||||
		want       *v1alpha2.LeaseCandidate
 | 
							want       *v1beta1.LeaseCandidate
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:       "empty",
 | 
								name:       "empty",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{},
 | 
								candidates: []*v1beta1.LeaseCandidate{},
 | 
				
			||||||
			want:       nil,
 | 
								want:       nil,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "single candidate",
 | 
								name: "single candidate",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.1.0",
 | 
											BinaryVersion:    "0.1.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: &v1alpha2.LeaseCandidate{
 | 
								want: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name:      "candidate1",
 | 
										Name:      "candidate1",
 | 
				
			||||||
					Namespace: "default",
 | 
										Namespace: "default",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
					BinaryVersion:    "0.1.0",
 | 
										BinaryVersion:    "0.1.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -65,14 +65,14 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, different emulation versions",
 | 
								name: "multiple candidates, different emulation versions",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.1.0",
 | 
											BinaryVersion:    "0.1.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -83,18 +83,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.2.0",
 | 
											EmulationVersion: "0.2.0",
 | 
				
			||||||
						BinaryVersion:    "0.2.0",
 | 
											BinaryVersion:    "0.2.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: &v1alpha2.LeaseCandidate{
 | 
								want: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name:      "candidate1",
 | 
										Name:      "candidate1",
 | 
				
			||||||
					Namespace: "default",
 | 
										Namespace: "default",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "v1",
 | 
										EmulationVersion: "v1",
 | 
				
			||||||
					BinaryVersion:    "v1",
 | 
										BinaryVersion:    "v1",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -102,14 +102,14 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, same emulation versions, different binary versions",
 | 
								name: "multiple candidates, same emulation versions, different binary versions",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.1.0",
 | 
											BinaryVersion:    "0.1.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -120,18 +120,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.2.0",
 | 
											BinaryVersion:    "0.2.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: &v1alpha2.LeaseCandidate{
 | 
								want: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name:      "candidate1",
 | 
										Name:      "candidate1",
 | 
				
			||||||
					Namespace: "default",
 | 
										Namespace: "default",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
					BinaryVersion:    "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",
 | 
								name: "multiple candidates, same emulation versions, same binary versions, different creation timestamps",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * time.Hour)},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.1.0",
 | 
											BinaryVersion:    "0.1.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -157,18 +157,18 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "0.1.0",
 | 
											EmulationVersion: "0.1.0",
 | 
				
			||||||
						BinaryVersion:    "0.1.0",
 | 
											BinaryVersion:    "0.1.0",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			want: &v1alpha2.LeaseCandidate{
 | 
								want: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name:      "candidate1",
 | 
										Name:      "candidate1",
 | 
				
			||||||
					Namespace: "default",
 | 
										Namespace: "default",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
					BinaryVersion:    "0.1.0",
 | 
										BinaryVersion:    "0.1.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -192,13 +192,13 @@ func TestPickBestLeaderOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) {
 | 
					func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name      string
 | 
							name      string
 | 
				
			||||||
		candidate *v1alpha2.LeaseCandidate
 | 
							candidate *v1beta1.LeaseCandidate
 | 
				
			||||||
		want      bool
 | 
							want      bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "valid emulation and binary versions",
 | 
								name: "valid emulation and binary versions",
 | 
				
			||||||
			candidate: &v1alpha2.LeaseCandidate{
 | 
								candidate: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
					BinaryVersion:    "0.1.0",
 | 
										BinaryVersion:    "0.1.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -207,8 +207,8 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "invalid emulation version",
 | 
								name: "invalid emulation version",
 | 
				
			||||||
			candidate: &v1alpha2.LeaseCandidate{
 | 
								candidate: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "invalid",
 | 
										EmulationVersion: "invalid",
 | 
				
			||||||
					BinaryVersion:    "0.1.0",
 | 
										BinaryVersion:    "0.1.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -217,8 +217,8 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "invalid binary version",
 | 
								name: "invalid binary version",
 | 
				
			||||||
			candidate: &v1alpha2.LeaseCandidate{
 | 
								candidate: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
					BinaryVersion:    "invalid",
 | 
										BinaryVersion:    "invalid",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -239,13 +239,13 @@ func TestValidLeaseCandidateForOldestEmulationVersion(t *testing.T) {
 | 
				
			|||||||
func TestGetEmulationVersion(t *testing.T) {
 | 
					func TestGetEmulationVersion(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name      string
 | 
							name      string
 | 
				
			||||||
		candidate *v1alpha2.LeaseCandidate
 | 
							candidate *v1beta1.LeaseCandidate
 | 
				
			||||||
		want      semver.Version
 | 
							want      semver.Version
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "valid emulation version",
 | 
								name: "valid emulation version",
 | 
				
			||||||
			candidate: &v1alpha2.LeaseCandidate{
 | 
								candidate: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "0.1.0",
 | 
										EmulationVersion: "0.1.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@@ -265,13 +265,13 @@ func TestGetEmulationVersion(t *testing.T) {
 | 
				
			|||||||
func TestGetBinaryVersion(t *testing.T) {
 | 
					func TestGetBinaryVersion(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name      string
 | 
							name      string
 | 
				
			||||||
		candidate *v1alpha2.LeaseCandidate
 | 
							candidate *v1beta1.LeaseCandidate
 | 
				
			||||||
		want      semver.Version
 | 
							want      semver.Version
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "valid binary version",
 | 
								name: "valid binary version",
 | 
				
			||||||
			candidate: &v1alpha2.LeaseCandidate{
 | 
								candidate: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					BinaryVersion: "0.3.0",
 | 
										BinaryVersion: "0.3.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@@ -292,14 +292,14 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
	nowTime := time.Now()
 | 
						nowTime := time.Now()
 | 
				
			||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		name           string
 | 
							name           string
 | 
				
			||||||
		lhs            *v1alpha2.LeaseCandidate
 | 
							lhs            *v1beta1.LeaseCandidate
 | 
				
			||||||
		rhs            *v1alpha2.LeaseCandidate
 | 
							rhs            *v1beta1.LeaseCandidate
 | 
				
			||||||
		expectedResult int
 | 
							expectedResult int
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "identical versions earlier timestamp",
 | 
								name: "identical versions earlier timestamp",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -307,8 +307,8 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
					CreationTimestamp: metav1.Time{Time: nowTime.Add(time.Duration(1))},
 | 
										CreationTimestamp: metav1.Time{Time: nowTime.Add(time.Duration(1))},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -320,9 +320,9 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "no lhs version",
 | 
								name: "no lhs version",
 | 
				
			||||||
			lhs:  &v1alpha2.LeaseCandidate{},
 | 
								lhs:  &v1beta1.LeaseCandidate{},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -331,25 +331,25 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "no rhs version",
 | 
								name: "no rhs version",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs:            &v1alpha2.LeaseCandidate{},
 | 
								rhs:            &v1beta1.LeaseCandidate{},
 | 
				
			||||||
			expectedResult: 1,
 | 
								expectedResult: 1,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "invalid lhs version",
 | 
								name: "invalid lhs version",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "xyz",
 | 
										EmulationVersion: "xyz",
 | 
				
			||||||
					BinaryVersion:    "xyz",
 | 
										BinaryVersion:    "xyz",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -358,14 +358,14 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "invalid rhs version",
 | 
								name: "invalid rhs version",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.21.0",
 | 
										BinaryVersion:    "1.21.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "xyz",
 | 
										EmulationVersion: "xyz",
 | 
				
			||||||
					BinaryVersion:    "xyz",
 | 
										BinaryVersion:    "xyz",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -374,14 +374,14 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "lhs less than rhs",
 | 
								name: "lhs less than rhs",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.19.0",
 | 
										EmulationVersion: "1.19.0",
 | 
				
			||||||
					BinaryVersion:    "1.20.0",
 | 
										BinaryVersion:    "1.20.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.20.0",
 | 
										BinaryVersion:    "1.20.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -390,14 +390,14 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "rhs less than lhs",
 | 
								name: "rhs less than lhs",
 | 
				
			||||||
			lhs: &v1alpha2.LeaseCandidate{
 | 
								lhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.20.0",
 | 
										EmulationVersion: "1.20.0",
 | 
				
			||||||
					BinaryVersion:    "1.20.0",
 | 
										BinaryVersion:    "1.20.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			rhs: &v1alpha2.LeaseCandidate{
 | 
								rhs: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.19.0",
 | 
										EmulationVersion: "1.19.0",
 | 
				
			||||||
					BinaryVersion:    "1.20.0",
 | 
										BinaryVersion:    "1.20.0",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -418,18 +418,18 @@ func TestCompare(t *testing.T) {
 | 
				
			|||||||
func TestShouldReelect(t *testing.T) {
 | 
					func TestShouldReelect(t *testing.T) {
 | 
				
			||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		name          string
 | 
							name          string
 | 
				
			||||||
		candidates    []*v1alpha2.LeaseCandidate
 | 
							candidates    []*v1beta1.LeaseCandidate
 | 
				
			||||||
		currentLeader *v1alpha2.LeaseCandidate
 | 
							currentLeader *v1beta1.LeaseCandidate
 | 
				
			||||||
		expectResult  bool
 | 
							expectResult  bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "candidate with newer binary version",
 | 
								name: "candidate with newer binary version",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name: "component-identity-1",
 | 
											Name: "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
						Strategy:         v1.OldestEmulationVersion,
 | 
											Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -439,18 +439,18 @@ func TestShouldReelect(t *testing.T) {
 | 
				
			|||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name: "component-identity-2",
 | 
											Name: "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.20.0",
 | 
											BinaryVersion:    "1.20.0",
 | 
				
			||||||
						Strategy:         v1.OldestEmulationVersion,
 | 
											Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			currentLeader: &v1alpha2.LeaseCandidate{
 | 
								currentLeader: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "component-identity-1",
 | 
										Name: "component-identity-1",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.19.0",
 | 
										EmulationVersion: "1.19.0",
 | 
				
			||||||
					BinaryVersion:    "1.19.0",
 | 
										BinaryVersion:    "1.19.0",
 | 
				
			||||||
					Strategy:         v1.OldestEmulationVersion,
 | 
										Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -460,12 +460,12 @@ func TestShouldReelect(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "no newer candidates",
 | 
								name: "no newer candidates",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name: "component-identity-1",
 | 
											Name: "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
						Strategy:         v1.OldestEmulationVersion,
 | 
											Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -475,18 +475,18 @@ func TestShouldReelect(t *testing.T) {
 | 
				
			|||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name: "component-identity-2",
 | 
											Name: "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
						Strategy:         v1.OldestEmulationVersion,
 | 
											Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			currentLeader: &v1alpha2.LeaseCandidate{
 | 
								currentLeader: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "component-identity-1",
 | 
										Name: "component-identity-1",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.19.0",
 | 
										EmulationVersion: "1.19.0",
 | 
				
			||||||
					BinaryVersion:    "1.19.0",
 | 
										BinaryVersion:    "1.19.0",
 | 
				
			||||||
					Strategy:         v1.OldestEmulationVersion,
 | 
										Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -496,12 +496,12 @@ func TestShouldReelect(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:       "no candidates",
 | 
								name:       "no candidates",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{},
 | 
								candidates: []*v1beta1.LeaseCandidate{},
 | 
				
			||||||
			currentLeader: &v1alpha2.LeaseCandidate{
 | 
								currentLeader: &v1beta1.LeaseCandidate{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "component-identity-1",
 | 
										Name: "component-identity-1",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Spec: v1alpha2.LeaseCandidateSpec{
 | 
									Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
					EmulationVersion: "1.19.0",
 | 
										EmulationVersion: "1.19.0",
 | 
				
			||||||
					BinaryVersion:    "1.19.0",
 | 
										BinaryVersion:    "1.19.0",
 | 
				
			||||||
					Strategy:         v1.OldestEmulationVersion,
 | 
										Strategy:         v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -523,19 +523,19 @@ func TestShouldReelect(t *testing.T) {
 | 
				
			|||||||
func TestPickBestStrategy(t *testing.T) {
 | 
					func TestPickBestStrategy(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name         string
 | 
							name         string
 | 
				
			||||||
		candidates   []*v1alpha2.LeaseCandidate
 | 
							candidates   []*v1beta1.LeaseCandidate
 | 
				
			||||||
		wantStrategy v1.CoordinatedLeaseStrategy
 | 
							wantStrategy v1.CoordinatedLeaseStrategy
 | 
				
			||||||
		wantError    bool
 | 
							wantError    bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "single candidate, single preferred strategy",
 | 
								name: "single candidate, single preferred strategy",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName: "component-A",
 | 
											LeaseName: "component-A",
 | 
				
			||||||
						Strategy:  v1.OldestEmulationVersion,
 | 
											Strategy:  v1.OldestEmulationVersion,
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -546,13 +546,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, different preferred strategies should fail",
 | 
								name: "multiple candidates, different preferred strategies should fail",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName: "component-A",
 | 
											LeaseName: "component-A",
 | 
				
			||||||
						Strategy:  v1.OldestEmulationVersion,
 | 
											Strategy:  v1.OldestEmulationVersion,
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -562,7 +562,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName: "component-A",
 | 
											LeaseName: "component-A",
 | 
				
			||||||
						Strategy:  v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
											Strategy:  v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -572,13 +572,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, different preferred strategy different binary version should resolve",
 | 
								name: "multiple candidates, different preferred strategy different binary version should resolve",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.32.0",
 | 
											BinaryVersion: "1.32.0",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -589,7 +589,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
											Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
				
			||||||
@@ -601,13 +601,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, different preferred strategy different binary version should resolve, order agnostic",
 | 
								name: "multiple candidates, different preferred strategy different binary version should resolve, order agnostic",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
											Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
				
			||||||
@@ -618,7 +618,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.32.0",
 | 
											BinaryVersion: "1.32.0",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -630,13 +630,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, different preferred strategy different binary version string comparison check",
 | 
								name: "multiple candidates, different preferred strategy different binary version string comparison check",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.1.10",
 | 
											BinaryVersion: "1.1.10",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -647,7 +647,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.1.2",
 | 
											BinaryVersion: "1.1.2",
 | 
				
			||||||
						Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
											Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
				
			||||||
@@ -660,13 +660,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, same preferred strategy",
 | 
								name: "multiple candidates, same preferred strategy",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -677,7 +677,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -689,13 +689,13 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidates, conflicting preferred strategy",
 | 
								name: "multiple candidates, conflicting preferred strategy",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:      "candidate1",
 | 
											Name:      "candidate1",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.OldestEmulationVersion,
 | 
											Strategy:      v1.OldestEmulationVersion,
 | 
				
			||||||
@@ -706,7 +706,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
						Name:      "candidate2",
 | 
											Name:      "candidate2",
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:     "component-A",
 | 
											LeaseName:     "component-A",
 | 
				
			||||||
						BinaryVersion: "1.31.0",
 | 
											BinaryVersion: "1.31.0",
 | 
				
			||||||
						Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
											Strategy:      v1.CoordinatedLeaseStrategy("foo.com/bar"),
 | 
				
			||||||
@@ -732,7 +732,7 @@ func TestPickBestStrategy(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func shouldReelect(candidates []*v1alpha2.LeaseCandidate, currentLeader *v1alpha2.LeaseCandidate) bool {
 | 
					func shouldReelect(candidates []*v1beta1.LeaseCandidate, currentLeader *v1beta1.LeaseCandidate) bool {
 | 
				
			||||||
	pickedLeader := pickBestLeaderOldestEmulationVersion(candidates)
 | 
						pickedLeader := pickBestLeaderOldestEmulationVersion(candidates)
 | 
				
			||||||
	if pickedLeader == nil {
 | 
						if pickedLeader == nil {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
						apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
@@ -31,9 +31,9 @@ import (
 | 
				
			|||||||
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
						utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	coordinationv1informers "k8s.io/client-go/informers/coordination/v1"
 | 
						coordinationv1informers "k8s.io/client-go/informers/coordination/v1"
 | 
				
			||||||
	coordinationv1alpha2 "k8s.io/client-go/informers/coordination/v1alpha2"
 | 
						coordinationv1beta1 "k8s.io/client-go/informers/coordination/v1beta1"
 | 
				
			||||||
	coordinationv1client "k8s.io/client-go/kubernetes/typed/coordination/v1"
 | 
						coordinationv1client "k8s.io/client-go/kubernetes/typed/coordination/v1"
 | 
				
			||||||
	coordinationv1alpha2client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha2"
 | 
						coordinationv1beta1client "k8s.io/client-go/kubernetes/typed/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/client-go/tools/cache"
 | 
						"k8s.io/client-go/tools/cache"
 | 
				
			||||||
	"k8s.io/client-go/util/workqueue"
 | 
						"k8s.io/client-go/util/workqueue"
 | 
				
			||||||
	"k8s.io/klog/v2"
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
@@ -64,8 +64,8 @@ type Controller struct {
 | 
				
			|||||||
	leaseClient       coordinationv1client.CoordinationV1Interface
 | 
						leaseClient       coordinationv1client.CoordinationV1Interface
 | 
				
			||||||
	leaseRegistration cache.ResourceEventHandlerRegistration
 | 
						leaseRegistration cache.ResourceEventHandlerRegistration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	leaseCandidateInformer     coordinationv1alpha2.LeaseCandidateInformer
 | 
						leaseCandidateInformer     coordinationv1beta1.LeaseCandidateInformer
 | 
				
			||||||
	leaseCandidateClient       coordinationv1alpha2client.CoordinationV1alpha2Interface
 | 
						leaseCandidateClient       coordinationv1beta1client.CoordinationV1beta1Interface
 | 
				
			||||||
	leaseCandidateRegistration cache.ResourceEventHandlerRegistration
 | 
						leaseCandidateRegistration cache.ResourceEventHandlerRegistration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	queue workqueue.TypedRateLimitingInterface[types.NamespacedName]
 | 
						queue workqueue.TypedRateLimitingInterface[types.NamespacedName]
 | 
				
			||||||
@@ -109,7 +109,7 @@ func (c *Controller) Run(ctx context.Context, workers int) {
 | 
				
			|||||||
	<-ctx.Done()
 | 
						<-ctx.Done()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewController(leaseInformer coordinationv1informers.LeaseInformer, leaseCandidateInformer coordinationv1alpha2.LeaseCandidateInformer, leaseClient coordinationv1client.CoordinationV1Interface, leaseCandidateClient coordinationv1alpha2client.CoordinationV1alpha2Interface) (*Controller, error) {
 | 
					func NewController(leaseInformer coordinationv1informers.LeaseInformer, leaseCandidateInformer coordinationv1beta1.LeaseCandidateInformer, leaseClient coordinationv1client.CoordinationV1Interface, leaseCandidateClient coordinationv1beta1client.CoordinationV1beta1Interface) (*Controller, error) {
 | 
				
			||||||
	c := &Controller{
 | 
						c := &Controller{
 | 
				
			||||||
		leaseInformer:          leaseInformer,
 | 
							leaseInformer:          leaseInformer,
 | 
				
			||||||
		leaseCandidateInformer: leaseCandidateInformer,
 | 
							leaseCandidateInformer: leaseCandidateInformer,
 | 
				
			||||||
@@ -174,7 +174,7 @@ func (c *Controller) processNextElectionItem(ctx context.Context) bool {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) enqueueCandidate(obj any) {
 | 
					func (c *Controller) enqueueCandidate(obj any) {
 | 
				
			||||||
	lc, ok := obj.(*v1alpha2.LeaseCandidate)
 | 
						lc, ok := obj.(*v1beta1.LeaseCandidate)
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -196,7 +196,7 @@ func (c *Controller) enqueueLease(obj any) {
 | 
				
			|||||||
	c.queue.Add(types.NamespacedName{Namespace: lease.Namespace, Name: lease.Name})
 | 
						c.queue.Add(types.NamespacedName{Namespace: lease.Namespace, Name: lease.Name})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) electionNeeded(candidates []*v1alpha2.LeaseCandidate, leaseNN types.NamespacedName) (bool, error) {
 | 
					func (c *Controller) electionNeeded(candidates []*v1beta1.LeaseCandidate, leaseNN types.NamespacedName) (bool, error) {
 | 
				
			||||||
	lease, err := c.leaseInformer.Lister().Leases(leaseNN.Namespace).Get(leaseNN.Name)
 | 
						lease, err := c.leaseInformer.Lister().Leases(leaseNN.Namespace).Get(leaseNN.Name)
 | 
				
			||||||
	if err != nil && !apierrors.IsNotFound(err) {
 | 
						if err != nil && !apierrors.IsNotFound(err) {
 | 
				
			||||||
		return false, fmt.Errorf("error reading lease: %w", 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 []*v1alpha2.LeaseCandidate
 | 
						var ackedCandidates []*v1beta1.LeaseCandidate
 | 
				
			||||||
	for _, candidate := range candidates {
 | 
						for _, candidate := range candidates {
 | 
				
			||||||
		if candidate.Spec.RenewTime.Add(electionDuration).After(now) {
 | 
							if candidate.Spec.RenewTime.Add(electionDuration).After(now) {
 | 
				
			||||||
			ackedCandidates = append(ackedCandidates, candidate)
 | 
								ackedCandidates = append(ackedCandidates, candidate)
 | 
				
			||||||
@@ -415,12 +415,12 @@ func (c *Controller) reconcileElectionStep(ctx context.Context, leaseNN types.Na
 | 
				
			|||||||
	return defaultRequeueInterval, nil
 | 
						return defaultRequeueInterval, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) listAdmissableCandidates(leaseNN types.NamespacedName) ([]*v1alpha2.LeaseCandidate, error) {
 | 
					func (c *Controller) listAdmissableCandidates(leaseNN types.NamespacedName) ([]*v1beta1.LeaseCandidate, error) {
 | 
				
			||||||
	leases, err := c.leaseCandidateInformer.Lister().LeaseCandidates(leaseNN.Namespace).List(labels.Everything())
 | 
						leases, err := c.leaseCandidateInformer.Lister().LeaseCandidates(leaseNN.Namespace).List(labels.Everything())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var results []*v1alpha2.LeaseCandidate
 | 
						var results []*v1beta1.LeaseCandidate
 | 
				
			||||||
	for _, l := range leases {
 | 
						for _, l := range leases {
 | 
				
			||||||
		if l.Spec.LeaseName != leaseNN.Name {
 | 
							if l.Spec.LeaseName != leaseNN.Name {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/api/errors"
 | 
						"k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
@@ -42,7 +42,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name                    string
 | 
							name                    string
 | 
				
			||||||
		leaseNN                 types.NamespacedName
 | 
							leaseNN                 types.NamespacedName
 | 
				
			||||||
		candidates              []*v1alpha2.LeaseCandidate
 | 
							candidates              []*v1beta1.LeaseCandidate
 | 
				
			||||||
		existingLease           *v1.Lease
 | 
							existingLease           *v1.Lease
 | 
				
			||||||
		expectLease             bool
 | 
							expectLease             bool
 | 
				
			||||||
		expectedHolderIdentity  *string
 | 
							expectedHolderIdentity  *string
 | 
				
			||||||
@@ -55,7 +55,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:                   "no candidates, no lease, noop",
 | 
								name:                   "no candidates, no lease, noop",
 | 
				
			||||||
			leaseNN:                types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN:                types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates:             []*v1alpha2.LeaseCandidate{},
 | 
								candidates:             []*v1beta1.LeaseCandidate{},
 | 
				
			||||||
			existingLease:          nil,
 | 
								existingLease:          nil,
 | 
				
			||||||
			expectLease:            false,
 | 
								expectLease:            false,
 | 
				
			||||||
			expectedHolderIdentity: nil,
 | 
								expectedHolderIdentity: nil,
 | 
				
			||||||
@@ -66,7 +66,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:                   "no candidates, lease exists. noop, not managed by CLE",
 | 
								name:                   "no candidates, lease exists. noop, not managed by CLE",
 | 
				
			||||||
			leaseNN:                types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN:                types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates:             []*v1alpha2.LeaseCandidate{},
 | 
								candidates:             []*v1beta1.LeaseCandidate{},
 | 
				
			||||||
			existingLease:          &v1.Lease{},
 | 
								existingLease:          &v1.Lease{},
 | 
				
			||||||
			expectLease:            false,
 | 
								expectLease:            false,
 | 
				
			||||||
			expectedHolderIdentity: nil,
 | 
								expectedHolderIdentity: nil,
 | 
				
			||||||
@@ -77,13 +77,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, no existing lease should create lease",
 | 
								name:    "candidates exist, no existing lease should create lease",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -102,13 +102,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, lease exists, unoptimal should set preferredHolder",
 | 
								name:    "candidates exist, lease exists, unoptimal should set preferredHolder",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -121,7 +121,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-2",
 | 
											Name:      "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.18.0",
 | 
											EmulationVersion: "1.18.0",
 | 
				
			||||||
						BinaryVersion:    "1.18.0",
 | 
											BinaryVersion:    "1.18.0",
 | 
				
			||||||
@@ -151,13 +151,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, should only elect leader from acked candidates",
 | 
								name:    "candidates exist, should only elect leader from acked candidates",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -171,7 +171,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-2",
 | 
											Name:      "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.20.0",
 | 
											EmulationVersion: "1.20.0",
 | 
				
			||||||
						BinaryVersion:    "1.20.0",
 | 
											BinaryVersion:    "1.20.0",
 | 
				
			||||||
@@ -191,13 +191,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, lease exists, lease expired",
 | 
								name:    "candidates exist, lease exists, lease expired",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -226,13 +226,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, no acked candidates should return error",
 | 
								name:    "candidates exist, no acked candidates should return error",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -251,13 +251,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, should ping on election",
 | 
								name:    "candidates exist, should ping on election",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -277,13 +277,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidate exist, pinged candidate should have until electionDuration until election decision is made",
 | 
								name:    "candidate exist, pinged candidate should have until electionDuration until election decision is made",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -302,13 +302,13 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:    "candidates exist, lease exists, lease expired, 3rdparty strategy",
 | 
								name:    "candidates exist, lease exists, lease expired, 3rdparty strategy",
 | 
				
			||||||
			leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
								leaseNN: types.NamespacedName{Namespace: "default", Name: "component-A"},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "default",
 | 
											Namespace: "default",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -344,9 +344,9 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			controller, err := NewController(
 | 
								controller, err := NewController(
 | 
				
			||||||
				informerFactory.Coordination().V1().Leases(),
 | 
									informerFactory.Coordination().V1().Leases(),
 | 
				
			||||||
				informerFactory.Coordination().V1alpha2().LeaseCandidates(),
 | 
									informerFactory.Coordination().V1beta1().LeaseCandidates(),
 | 
				
			||||||
				client.CoordinationV1(),
 | 
									client.CoordinationV1(),
 | 
				
			||||||
				client.CoordinationV1alpha2(),
 | 
									client.CoordinationV1beta1(),
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
			controller.clock = fakeClock
 | 
								controller.clock = fakeClock
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
@@ -363,7 +363,7 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			// Set up the fake client with the candidates
 | 
								// Set up the fake client with the candidates
 | 
				
			||||||
			for _, candidate := range tc.candidates {
 | 
								for _, candidate := range tc.candidates {
 | 
				
			||||||
				_, err = client.CoordinationV1alpha2().LeaseCandidates(candidate.Namespace).Create(ctx, candidate, metav1.CreateOptions{})
 | 
									_, err = client.CoordinationV1beta1().LeaseCandidates(candidate.Namespace).Create(ctx, candidate, metav1.CreateOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					t.Fatal(err)
 | 
										t.Fatal(err)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -414,11 +414,11 @@ func TestReconcileElectionStep(t *testing.T) {
 | 
				
			|||||||
			// Verify that ping to candidate was issued
 | 
								// Verify that ping to candidate was issued
 | 
				
			||||||
			if tc.candidatesPinged {
 | 
								if tc.candidatesPinged {
 | 
				
			||||||
				pinged := false
 | 
									pinged := false
 | 
				
			||||||
				candidatesList, err := client.CoordinationV1alpha2().LeaseCandidates(tc.leaseNN.Namespace).List(ctx, metav1.ListOptions{})
 | 
									candidatesList, err := client.CoordinationV1beta1().LeaseCandidates(tc.leaseNN.Namespace).List(ctx, metav1.ListOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					t.Fatal(err)
 | 
										t.Fatal(err)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				oldCandidateMap := make(map[string]*v1alpha2.LeaseCandidate)
 | 
									oldCandidateMap := make(map[string]*v1beta1.LeaseCandidate)
 | 
				
			||||||
				for _, candidate := range tc.candidates {
 | 
									for _, candidate := range tc.candidates {
 | 
				
			||||||
					oldCandidateMap[candidate.Name] = candidate
 | 
										oldCandidateMap[candidate.Name] = candidate
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -443,20 +443,20 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
	cases := []struct {
 | 
						cases := []struct {
 | 
				
			||||||
		name                            string
 | 
							name                            string
 | 
				
			||||||
		leases                          []*v1.Lease
 | 
							leases                          []*v1.Lease
 | 
				
			||||||
		candidates                      []*v1alpha2.LeaseCandidate
 | 
							candidates                      []*v1beta1.LeaseCandidate
 | 
				
			||||||
		createAfterControllerStart      []*v1alpha2.LeaseCandidate
 | 
							createAfterControllerStart      []*v1beta1.LeaseCandidate
 | 
				
			||||||
		deleteLeaseAfterControllerStart []types.NamespacedName
 | 
							deleteLeaseAfterControllerStart []types.NamespacedName
 | 
				
			||||||
		expectedLeaderLeases            []*v1.Lease
 | 
							expectedLeaderLeases            []*v1.Lease
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "single candidate leader election",
 | 
								name: "single candidate leader election",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -479,13 +479,13 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "multiple candidate leader election",
 | 
								name: "multiple candidate leader election",
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -498,7 +498,7 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-2",
 | 
											Name:      "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.20.0",
 | 
											BinaryVersion:    "1.20.0",
 | 
				
			||||||
@@ -511,7 +511,7 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-3",
 | 
											Name:      "component-identity-3",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.20.0",
 | 
											EmulationVersion: "1.20.0",
 | 
				
			||||||
						BinaryVersion:    "1.20.0",
 | 
											BinaryVersion:    "1.20.0",
 | 
				
			||||||
@@ -547,13 +547,13 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -593,13 +593,13 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -636,13 +636,13 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			candidates: []*v1alpha2.LeaseCandidate{
 | 
								candidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-1",
 | 
											Name:      "component-identity-1",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.20.0",
 | 
											EmulationVersion: "1.20.0",
 | 
				
			||||||
						BinaryVersion:    "1.20.0",
 | 
											BinaryVersion:    "1.20.0",
 | 
				
			||||||
@@ -651,13 +651,13 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			createAfterControllerStart: []*v1alpha2.LeaseCandidate{
 | 
								createAfterControllerStart: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Namespace: "kube-system",
 | 
											Namespace: "kube-system",
 | 
				
			||||||
						Name:      "component-identity-2",
 | 
											Name:      "component-identity-2",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -693,9 +693,9 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
			informerFactory := informers.NewSharedInformerFactory(client, 0)
 | 
								informerFactory := informers.NewSharedInformerFactory(client, 0)
 | 
				
			||||||
			controller, err := NewController(
 | 
								controller, err := NewController(
 | 
				
			||||||
				informerFactory.Coordination().V1().Leases(),
 | 
									informerFactory.Coordination().V1().Leases(),
 | 
				
			||||||
				informerFactory.Coordination().V1alpha2().LeaseCandidates(),
 | 
									informerFactory.Coordination().V1beta1().LeaseCandidates(),
 | 
				
			||||||
				client.CoordinationV1(),
 | 
									client.CoordinationV1(),
 | 
				
			||||||
				client.CoordinationV1alpha2(),
 | 
									client.CoordinationV1beta1(),
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				t.Fatal(err)
 | 
									t.Fatal(err)
 | 
				
			||||||
@@ -710,7 +710,7 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			for _, obj := range tc.candidates {
 | 
								for _, obj := range tc.candidates {
 | 
				
			||||||
				t.Logf("Pre-creating lease candidate %s/%s", obj.Namespace, obj.Name)
 | 
									t.Logf("Pre-creating lease candidate %s/%s", obj.Namespace, obj.Name)
 | 
				
			||||||
				_, err := client.CoordinationV1alpha2().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{})
 | 
									_, err := client.CoordinationV1beta1().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					t.Fatalf("Error pre-creating lease candidate %s/%s: %v", obj.Namespace, obj.Name, err)
 | 
										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 {
 | 
												if *ph == *l.Spec.HolderIdentity {
 | 
				
			||||||
								continue
 | 
													continue
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							if _, err := client.CoordinationV1alpha2().LeaseCandidates(expectedLease.Namespace).Get(ctx, *l.Spec.HolderIdentity, metav1.GetOptions{}); err != nil {
 | 
												if _, err := client.CoordinationV1beta1().LeaseCandidates(expectedLease.Namespace).Get(ctx, *l.Spec.HolderIdentity, metav1.GetOptions{}); err != nil {
 | 
				
			||||||
								continue // only candidate-aware controllers will follow preferredHolder
 | 
													continue // only candidate-aware controllers will follow preferredHolder
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -772,7 +772,7 @@ func TestController(t *testing.T) {
 | 
				
			|||||||
					case <-ctx.Done():
 | 
										case <-ctx.Done():
 | 
				
			||||||
						return
 | 
											return
 | 
				
			||||||
					case <-ticker.C:
 | 
										case <-ticker.C:
 | 
				
			||||||
						cs, err := client.CoordinationV1alpha2().LeaseCandidates("").List(ctx, metav1.ListOptions{})
 | 
											cs, err := client.CoordinationV1beta1().LeaseCandidates("").List(ctx, metav1.ListOptions{})
 | 
				
			||||||
						if err != nil {
 | 
											if err != nil {
 | 
				
			||||||
							t.Logf("Error listing lease candidates: %v", err)
 | 
												t.Logf("Error listing lease candidates: %v", err)
 | 
				
			||||||
							continue
 | 
												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)) {
 | 
												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)
 | 
													t.Logf("Answering ping for %s/%s", c.Namespace, c.Name)
 | 
				
			||||||
								c.Spec.RenewTime = &metav1.MicroTime{Time: time.Now()}
 | 
													c.Spec.RenewTime = &metav1.MicroTime{Time: time.Now()}
 | 
				
			||||||
								_, err = client.CoordinationV1alpha2().LeaseCandidates(c.Namespace).Update(ctx, &c, metav1.UpdateOptions{})
 | 
													_, err = client.CoordinationV1beta1().LeaseCandidates(c.Namespace).Update(ctx, &c, metav1.UpdateOptions{})
 | 
				
			||||||
								if err != nil {
 | 
													if err != nil {
 | 
				
			||||||
									t.Logf("Error updating lease candidate %s/%s: %v", c.Namespace, c.Name, err)
 | 
														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 {
 | 
								for _, obj := range tc.createAfterControllerStart {
 | 
				
			||||||
				t.Logf("Post-creating lease candidate %s/%s", obj.Namespace, obj.Name)
 | 
									t.Logf("Post-creating lease candidate %s/%s", obj.Namespace, obj.Name)
 | 
				
			||||||
				_, err := client.CoordinationV1alpha2().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{})
 | 
									_, err := client.CoordinationV1beta1().LeaseCandidates(obj.Namespace).Create(ctx, obj, metav1.CreateOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					t.Fatalf("Error post-creating lease candidate %s/%s: %v", obj.Namespace, obj.Name, err)
 | 
										t.Fatalf("Error post-creating lease candidate %s/%s: %v", obj.Namespace, obj.Name, err)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,9 +26,9 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
						utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	coordinationv1alpha2informers "k8s.io/client-go/informers/coordination/v1alpha2"
 | 
						coordinationv1beta1informers "k8s.io/client-go/informers/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/client-go/kubernetes"
 | 
						"k8s.io/client-go/kubernetes"
 | 
				
			||||||
	listers "k8s.io/client-go/listers/coordination/v1alpha2"
 | 
						listers "k8s.io/client-go/listers/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/client-go/tools/cache"
 | 
						"k8s.io/client-go/tools/cache"
 | 
				
			||||||
	"k8s.io/utils/clock"
 | 
						"k8s.io/utils/clock"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,7 +39,7 @@ type LeaseCandidateGCController struct {
 | 
				
			|||||||
	kubeclientset kubernetes.Interface
 | 
						kubeclientset kubernetes.Interface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	leaseCandidateLister   listers.LeaseCandidateLister
 | 
						leaseCandidateLister   listers.LeaseCandidateLister
 | 
				
			||||||
	leaseCandidateInformer coordinationv1alpha2informers.LeaseCandidateInformer
 | 
						leaseCandidateInformer coordinationv1beta1informers.LeaseCandidateInformer
 | 
				
			||||||
	leaseCandidatesSynced  cache.InformerSynced
 | 
						leaseCandidatesSynced  cache.InformerSynced
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gcCheckPeriod time.Duration
 | 
						gcCheckPeriod time.Duration
 | 
				
			||||||
@@ -48,7 +48,7 @@ type LeaseCandidateGCController struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewLeaseCandidateGC creates a new LeaseCandidateGCController.
 | 
					// NewLeaseCandidateGC creates a new LeaseCandidateGCController.
 | 
				
			||||||
func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Duration, leaseCandidateInformer coordinationv1alpha2informers.LeaseCandidateInformer) *LeaseCandidateGCController {
 | 
					func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Duration, leaseCandidateInformer coordinationv1beta1informers.LeaseCandidateInformer) *LeaseCandidateGCController {
 | 
				
			||||||
	return &LeaseCandidateGCController{
 | 
						return &LeaseCandidateGCController{
 | 
				
			||||||
		kubeclientset:          clientset,
 | 
							kubeclientset:          clientset,
 | 
				
			||||||
		leaseCandidateLister:   leaseCandidateInformer.Lister(),
 | 
							leaseCandidateLister:   leaseCandidateInformer.Lister(),
 | 
				
			||||||
@@ -87,7 +87,7 @@ func (c *LeaseCandidateGCController) gc(ctx context.Context) {
 | 
				
			|||||||
		if !isLeaseCandidateExpired(c.clock, leaseCandidate) {
 | 
							if !isLeaseCandidateExpired(c.clock, leaseCandidate) {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		lc, err := c.kubeclientset.CoordinationV1alpha2().LeaseCandidates(leaseCandidate.Namespace).Get(ctx, leaseCandidate.Name, metav1.GetOptions{})
 | 
							lc, err := c.kubeclientset.CoordinationV1beta1().LeaseCandidates(leaseCandidate.Namespace).Get(ctx, leaseCandidate.Name, metav1.GetOptions{})
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			klog.ErrorS(err, "Error getting lc")
 | 
								klog.ErrorS(err, "Error getting lc")
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
@@ -96,7 +96,7 @@ func (c *LeaseCandidateGCController) gc(ctx context.Context) {
 | 
				
			|||||||
		if !isLeaseCandidateExpired(c.clock, lc) {
 | 
							if !isLeaseCandidateExpired(c.clock, lc) {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := c.kubeclientset.CoordinationV1alpha2().LeaseCandidates(lc.Namespace).Delete(
 | 
							if err := c.kubeclientset.CoordinationV1beta1().LeaseCandidates(lc.Namespace).Delete(
 | 
				
			||||||
			ctx, lc.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
 | 
								ctx, lc.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
 | 
				
			||||||
			klog.ErrorS(err, "Error deleting lease")
 | 
								klog.ErrorS(err, "Error deleting lease")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	"k8s.io/client-go/informers"
 | 
						"k8s.io/client-go/informers"
 | 
				
			||||||
@@ -33,19 +33,19 @@ import (
 | 
				
			|||||||
func TestLeaseCandidateGCController(t *testing.T) {
 | 
					func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name                 string
 | 
							name                 string
 | 
				
			||||||
		leaseCandidates      []*v1alpha2.LeaseCandidate
 | 
							leaseCandidates      []*v1beta1.LeaseCandidate
 | 
				
			||||||
		expectedDeletedCount int
 | 
							expectedDeletedCount int
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "delete expired lease candidates",
 | 
								name: "delete expired lease candidates",
 | 
				
			||||||
			leaseCandidates: []*v1alpha2.LeaseCandidate{
 | 
								leaseCandidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -59,7 +59,7 @@ func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			|||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now().Add(-1 * leaseCandidateValidDuration)},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-B",
 | 
											LeaseName:        "component-B",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -73,7 +73,7 @@ func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			|||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-C",
 | 
											LeaseName:        "component-C",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -86,14 +86,14 @@ func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "no expired lease candidates",
 | 
								name: "no expired lease candidates",
 | 
				
			||||||
			leaseCandidates: []*v1alpha2.LeaseCandidate{
 | 
								leaseCandidates: []*v1beta1.LeaseCandidate{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					ObjectMeta: metav1.ObjectMeta{
 | 
										ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
						Name:              "candidate1",
 | 
											Name:              "candidate1",
 | 
				
			||||||
						Namespace:         "default",
 | 
											Namespace:         "default",
 | 
				
			||||||
						CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
											CreationTimestamp: metav1.Time{Time: time.Now()},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					Spec: v1alpha2.LeaseCandidateSpec{
 | 
										Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
						LeaseName:        "component-A",
 | 
											LeaseName:        "component-A",
 | 
				
			||||||
						EmulationVersion: "1.19.0",
 | 
											EmulationVersion: "1.19.0",
 | 
				
			||||||
						BinaryVersion:    "1.19.0",
 | 
											BinaryVersion:    "1.19.0",
 | 
				
			||||||
@@ -111,12 +111,12 @@ func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			|||||||
			ctx := context.Background()
 | 
								ctx := context.Background()
 | 
				
			||||||
			client := fake.NewSimpleClientset()
 | 
								client := fake.NewSimpleClientset()
 | 
				
			||||||
			informerFactory := informers.NewSharedInformerFactory(client, 0)
 | 
								informerFactory := informers.NewSharedInformerFactory(client, 0)
 | 
				
			||||||
			leaseCandidateInformer := informerFactory.Coordination().V1alpha2().LeaseCandidates()
 | 
								leaseCandidateInformer := informerFactory.Coordination().V1beta1().LeaseCandidates()
 | 
				
			||||||
			controller := NewLeaseCandidateGC(client, 10*time.Millisecond, leaseCandidateInformer)
 | 
								controller := NewLeaseCandidateGC(client, 10*time.Millisecond, leaseCandidateInformer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Create lease candidates
 | 
								// Create lease candidates
 | 
				
			||||||
			for _, lc := range tc.leaseCandidates {
 | 
								for _, lc := range tc.leaseCandidates {
 | 
				
			||||||
				_, err := client.CoordinationV1alpha2().LeaseCandidates(lc.Namespace).Create(ctx, lc, metav1.CreateOptions{})
 | 
									_, err := client.CoordinationV1beta1().LeaseCandidates(lc.Namespace).Create(ctx, lc, metav1.CreateOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					t.Fatal(err)
 | 
										t.Fatal(err)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -127,7 +127,7 @@ func TestLeaseCandidateGCController(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			go controller.Run(ctx)
 | 
								go controller.Run(ctx)
 | 
				
			||||||
			err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 600*time.Second, true, func(ctx context.Context) (done bool, err error) {
 | 
								err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 600*time.Second, true, func(ctx context.Context) (done bool, err error) {
 | 
				
			||||||
				lcs, err := client.CoordinationV1alpha2().LeaseCandidates("default").List(ctx, metav1.ListOptions{})
 | 
									lcs, err := client.CoordinationV1beta1().LeaseCandidates("default").List(ctx, metav1.ListOptions{})
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					return true, err
 | 
										return true, err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,7 +79,7 @@ func NewStorageFactoryConfigEffectiveVersion(effectiveVersion basecompatibility.
 | 
				
			|||||||
		//
 | 
							//
 | 
				
			||||||
		// TODO (https://github.com/kubernetes/kubernetes/issues/108451): remove the override in 1.25.
 | 
							// TODO (https://github.com/kubernetes/kubernetes/issues/108451): remove the override in 1.25.
 | 
				
			||||||
		// apisstorage.Resource("csistoragecapacities").WithVersion("v1beta1"),
 | 
							// apisstorage.Resource("csistoragecapacities").WithVersion("v1beta1"),
 | 
				
			||||||
		coordination.Resource("leasecandidates").WithVersion("v1alpha2"),
 | 
							coordination.Resource("leasecandidates").WithVersion("v1beta1"),
 | 
				
			||||||
		// TODO(aojea) ipaddresses and servicecidrs are v1 in 1.33
 | 
							// TODO(aojea) ipaddresses and servicecidrs are v1 in 1.33
 | 
				
			||||||
		// remove them in 1.34 when all apiserver understand the v1 version.
 | 
							// remove them in 1.34 when all apiserver understand the v1 version.
 | 
				
			||||||
		networking.Resource("ipaddresses").WithVersion("v1beta1"),
 | 
							networking.Resource("ipaddresses").WithVersion("v1beta1"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ package rest
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	coordinationv1 "k8s.io/api/coordination/v1"
 | 
						coordinationv1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						coordinationv1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
				
			||||||
 | 
						coordinationv1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/apiserver/pkg/registry/generic"
 | 
						"k8s.io/apiserver/pkg/registry/generic"
 | 
				
			||||||
	"k8s.io/apiserver/pkg/registry/rest"
 | 
						"k8s.io/apiserver/pkg/registry/rest"
 | 
				
			||||||
	genericapiserver "k8s.io/apiserver/pkg/server"
 | 
						genericapiserver "k8s.io/apiserver/pkg/server"
 | 
				
			||||||
@@ -42,6 +43,12 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag
 | 
				
			|||||||
		apiGroupInfo.VersionedResourcesStorageMap[coordinationv1.SchemeGroupVersion.Version] = storageMap
 | 
							apiGroupInfo.VersionedResourcesStorageMap[coordinationv1.SchemeGroupVersion.Version] = storageMap
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if storageMap, err := p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
 | 
				
			||||||
 | 
							return genericapiserver.APIGroupInfo{}, err
 | 
				
			||||||
 | 
						} else if len(storageMap) > 0 {
 | 
				
			||||||
 | 
							apiGroupInfo.VersionedResourcesStorageMap[coordinationv1beta1.SchemeGroupVersion.Version] = storageMap
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if storageMap, err := p.v1alpha2Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
 | 
						if storageMap, err := p.v1alpha2Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
 | 
				
			||||||
		return genericapiserver.APIGroupInfo{}, err
 | 
							return genericapiserver.APIGroupInfo{}, err
 | 
				
			||||||
	} else if len(storageMap) > 0 {
 | 
						} else if len(storageMap) > 0 {
 | 
				
			||||||
@@ -65,6 +72,20 @@ func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.API
 | 
				
			|||||||
	return storage, nil
 | 
						return storage, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) {
 | 
				
			||||||
 | 
						storage := map[string]rest.Storage{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// identity
 | 
				
			||||||
 | 
						if resource := "leasecandidates"; apiResourceConfigSource.ResourceEnabled(coordinationv1beta1.SchemeGroupVersion.WithResource(resource)) {
 | 
				
			||||||
 | 
							leaseCandidateStorage, err := leasecandidatestorage.NewREST(restOptionsGetter)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return storage, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							storage[resource] = leaseCandidateStorage
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return storage, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p RESTStorageProvider) v1alpha2Storage(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{}
 | 
						storage := map[string]rest.Storage{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
 | 
				
			|||||||
	scheme.AddKnownTypes(SchemeGroupVersion,
 | 
						scheme.AddKnownTypes(SchemeGroupVersion,
 | 
				
			||||||
		&Lease{},
 | 
							&Lease{},
 | 
				
			||||||
		&LeaseList{},
 | 
							&LeaseList{},
 | 
				
			||||||
 | 
							&LeaseCandidate{},
 | 
				
			||||||
 | 
							&LeaseCandidateList{},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
 | 
						metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,14 +22,14 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
						apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/fields"
 | 
						"k8s.io/apimachinery/pkg/fields"
 | 
				
			||||||
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
						utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
				
			||||||
	"k8s.io/client-go/informers"
 | 
						"k8s.io/client-go/informers"
 | 
				
			||||||
	"k8s.io/client-go/kubernetes"
 | 
						"k8s.io/client-go/kubernetes"
 | 
				
			||||||
	coordinationv1alpha2client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha2"
 | 
						coordinationv1beta1client "k8s.io/client-go/kubernetes/typed/coordination/v1beta1"
 | 
				
			||||||
	"k8s.io/client-go/tools/cache"
 | 
						"k8s.io/client-go/tools/cache"
 | 
				
			||||||
	"k8s.io/client-go/util/workqueue"
 | 
						"k8s.io/client-go/util/workqueue"
 | 
				
			||||||
	"k8s.io/klog/v2"
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
@@ -43,7 +43,7 @@ type CacheSyncWaiter interface {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type LeaseCandidate struct {
 | 
					type LeaseCandidate struct {
 | 
				
			||||||
	leaseClient            coordinationv1alpha2client.LeaseCandidateInterface
 | 
						leaseClient            coordinationv1beta1client.LeaseCandidateInterface
 | 
				
			||||||
	leaseCandidateInformer cache.SharedIndexInformer
 | 
						leaseCandidateInformer cache.SharedIndexInformer
 | 
				
			||||||
	informerFactory        informers.SharedInformerFactory
 | 
						informerFactory        informers.SharedInformerFactory
 | 
				
			||||||
	hasSynced              cache.InformerSynced
 | 
						hasSynced              cache.InformerSynced
 | 
				
			||||||
@@ -84,10 +84,10 @@ func NewCandidate(clientset kubernetes.Interface,
 | 
				
			|||||||
			options.FieldSelector = fieldSelector
 | 
								options.FieldSelector = fieldSelector
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	leaseCandidateInformer := informerFactory.Coordination().V1alpha2().LeaseCandidates().Informer()
 | 
						leaseCandidateInformer := informerFactory.Coordination().V1beta1().LeaseCandidates().Informer()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lc := &LeaseCandidate{
 | 
						lc := &LeaseCandidate{
 | 
				
			||||||
		leaseClient:            clientset.CoordinationV1alpha2().LeaseCandidates(candidateNamespace),
 | 
							leaseClient:            clientset.CoordinationV1beta1().LeaseCandidates(candidateNamespace),
 | 
				
			||||||
		leaseCandidateInformer: leaseCandidateInformer,
 | 
							leaseCandidateInformer: leaseCandidateInformer,
 | 
				
			||||||
		informerFactory:        informerFactory,
 | 
							informerFactory:        informerFactory,
 | 
				
			||||||
		name:                   candidateName,
 | 
							name:                   candidateName,
 | 
				
			||||||
@@ -102,7 +102,7 @@ func NewCandidate(clientset kubernetes.Interface,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	h, err := leaseCandidateInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
 | 
						h, err := leaseCandidateInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
 | 
				
			||||||
		UpdateFunc: func(oldObj, newObj interface{}) {
 | 
							UpdateFunc: func(oldObj, newObj interface{}) {
 | 
				
			||||||
			if leasecandidate, ok := newObj.(*v1alpha2.LeaseCandidate); ok {
 | 
								if leasecandidate, ok := newObj.(*v1beta1.LeaseCandidate); ok {
 | 
				
			||||||
				if leasecandidate.Spec.PingTime != nil && leasecandidate.Spec.PingTime.After(leasecandidate.Spec.RenewTime.Time) {
 | 
									if leasecandidate.Spec.PingTime != nil && leasecandidate.Spec.PingTime.After(leasecandidate.Spec.RenewTime.Time) {
 | 
				
			||||||
					lc.enqueueLease()
 | 
										lc.enqueueLease()
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -184,13 +184,13 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *LeaseCandidate) newLeaseCandidate() *v1alpha2.LeaseCandidate {
 | 
					func (c *LeaseCandidate) newLeaseCandidate() *v1beta1.LeaseCandidate {
 | 
				
			||||||
	lc := &v1alpha2.LeaseCandidate{
 | 
						lc := &v1beta1.LeaseCandidate{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name:      c.name,
 | 
								Name:      c.name,
 | 
				
			||||||
			Namespace: c.namespace,
 | 
								Namespace: c.namespace,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: v1alpha2.LeaseCandidateSpec{
 | 
							Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
			LeaseName:        c.leaseName,
 | 
								LeaseName:        c.leaseName,
 | 
				
			||||||
			BinaryVersion:    c.binaryVersion,
 | 
								BinaryVersion:    c.binaryVersion,
 | 
				
			||||||
			EmulationVersion: c.emulationVersion,
 | 
								EmulationVersion: c.emulationVersion,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,12 +101,12 @@ func TestLeaseCandidateAck(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Update PingTime and verify that the client renews
 | 
						// Update PingTime and verify that the client renews
 | 
				
			||||||
	ensureAfter := &metav1.MicroTime{Time: time.Now()}
 | 
						ensureAfter := &metav1.MicroTime{Time: time.Now()}
 | 
				
			||||||
	lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
 | 
						lc, err := client.CoordinationV1beta1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		if lc.Spec.PingTime == nil {
 | 
							if lc.Spec.PingTime == nil {
 | 
				
			||||||
			c := lc.DeepCopy()
 | 
								c := lc.DeepCopy()
 | 
				
			||||||
			c.Spec.PingTime = &metav1.MicroTime{Time: time.Now()}
 | 
								c.Spec.PingTime = &metav1.MicroTime{Time: time.Now()}
 | 
				
			||||||
			_, err = client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{})
 | 
								_, err = client.CoordinationV1beta1().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{})
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				t.Error(err)
 | 
									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 {
 | 
					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) {
 | 
						return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 10*time.Second, true, func(ctx context.Context) (done bool, err error) {
 | 
				
			||||||
		lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
 | 
							lc, err := client.CoordinationV1beta1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			if errors.IsNotFound(err) {
 | 
								if errors.IsNotFound(err) {
 | 
				
			||||||
				return false, nil
 | 
									return false, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,7 +24,7 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/coordination/v1"
 | 
						v1 "k8s.io/api/coordination/v1"
 | 
				
			||||||
	v1alpha2 "k8s.io/api/coordination/v1alpha2"
 | 
						v1beta1 "k8s.io/api/coordination/v1beta1"
 | 
				
			||||||
	apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
						apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
@@ -44,7 +44,7 @@ import (
 | 
				
			|||||||
func TestSingleLeaseCandidate(t *testing.T) {
 | 
					func TestSingleLeaseCandidate(t *testing.T) {
 | 
				
			||||||
	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
						featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1alpha2.SchemeGroupVersion)}
 | 
						flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1beta1.SchemeGroupVersion)}
 | 
				
			||||||
	server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
						server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -63,7 +63,7 @@ func TestSingleLeaseCandidate(t *testing.T) {
 | 
				
			|||||||
func TestMultipleLeaseCandidate(t *testing.T) {
 | 
					func TestMultipleLeaseCandidate(t *testing.T) {
 | 
				
			||||||
	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
						featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1alpha2.SchemeGroupVersion)}
 | 
						flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1beta1.SchemeGroupVersion)}
 | 
				
			||||||
	server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
						server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -86,7 +86,7 @@ func TestMultipleLeaseCandidate(t *testing.T) {
 | 
				
			|||||||
func TestLeaseSwapIfBetterAvailable(t *testing.T) {
 | 
					func TestLeaseSwapIfBetterAvailable(t *testing.T) {
 | 
				
			||||||
	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
						featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1alpha2.SchemeGroupVersion)}
 | 
						flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1beta1.SchemeGroupVersion)}
 | 
				
			||||||
	server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
						server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -108,7 +108,7 @@ func TestLeaseSwapIfBetterAvailable(t *testing.T) {
 | 
				
			|||||||
func TestUpgradeSkew(t *testing.T) {
 | 
					func TestUpgradeSkew(t *testing.T) {
 | 
				
			||||||
	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
						featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.CoordinatedLeaderElection, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1alpha2.SchemeGroupVersion)}
 | 
						flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1beta1.SchemeGroupVersion)}
 | 
				
			||||||
	server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
						server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -138,7 +138,7 @@ func TestLeaseCandidateCleanup(t *testing.T) {
 | 
				
			|||||||
		apiserver.LeaseCandidateGCPeriod = 30 * time.Minute
 | 
							apiserver.LeaseCandidateGCPeriod = 30 * time.Minute
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1alpha2.SchemeGroupVersion)}
 | 
						flags := []string{fmt.Sprintf("--runtime-config=%s=true", v1beta1.SchemeGroupVersion)}
 | 
				
			||||||
	server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
						server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), flags, framework.SharedEtcd())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
@@ -149,12 +149,12 @@ func TestLeaseCandidateCleanup(t *testing.T) {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	expiredLC := &v1alpha2.LeaseCandidate{
 | 
						expiredLC := &v1beta1.LeaseCandidate{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name:      "expired",
 | 
								Name:      "expired",
 | 
				
			||||||
			Namespace: "default",
 | 
								Namespace: "default",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: v1alpha2.LeaseCandidateSpec{
 | 
							Spec: v1beta1.LeaseCandidateSpec{
 | 
				
			||||||
			LeaseName:        "foobaz",
 | 
								LeaseName:        "foobaz",
 | 
				
			||||||
			BinaryVersion:    "0.1.0",
 | 
								BinaryVersion:    "0.1.0",
 | 
				
			||||||
			EmulationVersion: "0.1.0",
 | 
								EmulationVersion: "0.1.0",
 | 
				
			||||||
@@ -164,13 +164,13 @@ func TestLeaseCandidateCleanup(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx := context.Background()
 | 
						ctx := context.Background()
 | 
				
			||||||
	_, err = clientset.CoordinationV1alpha2().LeaseCandidates("default").Create(ctx, expiredLC, metav1.CreateOptions{})
 | 
						_, err = clientset.CoordinationV1beta1().LeaseCandidates("default").Create(ctx, expiredLC, metav1.CreateOptions{})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = wait.PollUntilContextTimeout(ctx, 1000*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (done bool, err error) {
 | 
						err = wait.PollUntilContextTimeout(ctx, 1000*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (done bool, err error) {
 | 
				
			||||||
		_, err = clientset.CoordinationV1alpha2().LeaseCandidates("default").Get(ctx, "expired", metav1.GetOptions{})
 | 
							_, err = clientset.CoordinationV1beta1().LeaseCandidates("default").Get(ctx, "expired", metav1.GetOptions{})
 | 
				
			||||||
		if apierrors.IsNotFound(err) {
 | 
							if apierrors.IsNotFound(err) {
 | 
				
			||||||
			return true, nil
 | 
								return true, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -231,10 +231,20 @@ func GetEtcdStorageDataForNamespaceServedAt(namespace string, v string, removeAl
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		// --
 | 
							// --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// k8s.io/kubernetes/pkg/apis/coordination/v1beta1
 | 
				
			||||||
 | 
							gvr("coordination.k8s.io", "v1beta1", "leasecandidates"): {
 | 
				
			||||||
 | 
								Stub:              `{"metadata": {"name": "leasecandidatev1beta1"}, "spec": {"leaseName": "lease", "binaryVersion": "0.1.0", "emulationVersion": "0.1.0", "strategy": "OldestEmulationVersion"}}`,
 | 
				
			||||||
 | 
								ExpectedEtcdPath:  "/registry/leasecandidates/" + namespace + "/leasecandidatev1beta1",
 | 
				
			||||||
 | 
								IntroducedVersion: "1.33",
 | 
				
			||||||
 | 
								RemovedVersion:    "1.39",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							// --
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// k8s.io/kubernetes/pkg/apis/coordination/v1alpha2
 | 
							// k8s.io/kubernetes/pkg/apis/coordination/v1alpha2
 | 
				
			||||||
		gvr("coordination.k8s.io", "v1alpha2", "leasecandidates"): {
 | 
							gvr("coordination.k8s.io", "v1alpha2", "leasecandidates"): {
 | 
				
			||||||
			Stub:              `{"metadata": {"name": "leasecandidatev1alpha2"}, "spec": {"leaseName": "lease", "binaryVersion": "0.1.0", "emulationVersion": "0.1.0", "strategy": "OldestEmulationVersion"}}`,
 | 
								Stub:              `{"metadata": {"name": "leasecandidatev1alpha2"}, "spec": {"leaseName": "lease", "binaryVersion": "0.1.0", "emulationVersion": "0.1.0", "strategy": "OldestEmulationVersion"}}`,
 | 
				
			||||||
			ExpectedEtcdPath:  "/registry/leasecandidates/" + namespace + "/leasecandidatev1alpha2",
 | 
								ExpectedEtcdPath:  "/registry/leasecandidates/" + namespace + "/leasecandidatev1alpha2",
 | 
				
			||||||
 | 
								ExpectedGVK:       gvkP("coordination.k8s.io", "v1beta1", "LeaseCandidate"),
 | 
				
			||||||
			IntroducedVersion: "1.32",
 | 
								IntroducedVersion: "1.32",
 | 
				
			||||||
			RemovedVersion:    "1.38",
 | 
								RemovedVersion:    "1.38",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user