Skip to content

Commit bf1a6ee

Browse files
Jefftreek8s-publishing-bot
authored andcommitted
v1alpha2 LeaseCandidate API
Kubernetes-commit: 0ce7b688a65a65031c6ee8c616989e4b0be4ce9f
1 parent ec12655 commit bf1a6ee

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

Diff for: tools/leaderelection/leasecandidate.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222
"time"
2323

2424
v1 "k8s.io/api/coordination/v1"
25-
v1alpha1 "k8s.io/api/coordination/v1alpha1"
25+
v1alpha2 "k8s.io/api/coordination/v1alpha2"
2626
apierrors "k8s.io/apimachinery/pkg/api/errors"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/fields"
2929
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3030
"k8s.io/client-go/informers"
3131
"k8s.io/client-go/kubernetes"
32-
coordinationv1alpha1client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha1"
32+
coordinationv1alpha2client "k8s.io/client-go/kubernetes/typed/coordination/v1alpha2"
3333
"k8s.io/client-go/tools/cache"
3434
"k8s.io/client-go/util/workqueue"
3535
"k8s.io/klog/v2"
@@ -43,7 +43,7 @@ type CacheSyncWaiter interface {
4343
}
4444

4545
type LeaseCandidate struct {
46-
leaseClient coordinationv1alpha1client.LeaseCandidateInterface
46+
leaseClient coordinationv1alpha2client.LeaseCandidateInterface
4747
leaseCandidateInformer cache.SharedIndexInformer
4848
informerFactory informers.SharedInformerFactory
4949
hasSynced cache.InformerSynced
@@ -60,7 +60,7 @@ type LeaseCandidate struct {
6060
clock clock.Clock
6161

6262
binaryVersion, emulationVersion string
63-
preferredStrategies []v1.CoordinatedLeaseStrategy
63+
strategy v1.CoordinatedLeaseStrategy
6464
}
6565

6666
// NewCandidate creates new LeaseCandidate controller that creates a
@@ -73,7 +73,7 @@ func NewCandidate(clientset kubernetes.Interface,
7373
candidateName string,
7474
targetLease string,
7575
binaryVersion, emulationVersion string,
76-
preferredStrategies []v1.CoordinatedLeaseStrategy,
76+
strategy v1.CoordinatedLeaseStrategy,
7777
) (*LeaseCandidate, CacheSyncWaiter, error) {
7878
fieldSelector := fields.OneTermEqualSelector("metadata.name", candidateName).String()
7979
// A separate informer factory is required because this must start before informerFactories
@@ -84,10 +84,10 @@ func NewCandidate(clientset kubernetes.Interface,
8484
options.FieldSelector = fieldSelector
8585
}),
8686
)
87-
leaseCandidateInformer := informerFactory.Coordination().V1alpha1().LeaseCandidates().Informer()
87+
leaseCandidateInformer := informerFactory.Coordination().V1alpha2().LeaseCandidates().Informer()
8888

8989
lc := &LeaseCandidate{
90-
leaseClient: clientset.CoordinationV1alpha1().LeaseCandidates(candidateNamespace),
90+
leaseClient: clientset.CoordinationV1alpha2().LeaseCandidates(candidateNamespace),
9191
leaseCandidateInformer: leaseCandidateInformer,
9292
informerFactory: informerFactory,
9393
name: candidateName,
@@ -96,13 +96,13 @@ func NewCandidate(clientset kubernetes.Interface,
9696
clock: clock.RealClock{},
9797
binaryVersion: binaryVersion,
9898
emulationVersion: emulationVersion,
99-
preferredStrategies: preferredStrategies,
99+
strategy: strategy,
100100
}
101101
lc.queue = workqueue.NewTypedRateLimitingQueueWithConfig(workqueue.DefaultTypedControllerRateLimiter[int](), workqueue.TypedRateLimitingQueueConfig[int]{Name: "leasecandidate"})
102102

103103
h, err := leaseCandidateInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
104104
UpdateFunc: func(oldObj, newObj interface{}) {
105-
if leasecandidate, ok := newObj.(*v1alpha1.LeaseCandidate); ok {
105+
if leasecandidate, ok := newObj.(*v1alpha2.LeaseCandidate); ok {
106106
if leasecandidate.Spec.PingTime != nil && leasecandidate.Spec.PingTime.After(leasecandidate.Spec.RenewTime.Time) {
107107
lc.enqueueLease()
108108
}
@@ -184,17 +184,17 @@ func (c *LeaseCandidate) ensureLease(ctx context.Context) error {
184184
return nil
185185
}
186186

187-
func (c *LeaseCandidate) newLeaseCandidate() *v1alpha1.LeaseCandidate {
188-
lc := &v1alpha1.LeaseCandidate{
187+
func (c *LeaseCandidate) newLeaseCandidate() *v1alpha2.LeaseCandidate {
188+
lc := &v1alpha2.LeaseCandidate{
189189
ObjectMeta: metav1.ObjectMeta{
190190
Name: c.name,
191191
Namespace: c.namespace,
192192
},
193-
Spec: v1alpha1.LeaseCandidateSpec{
194-
LeaseName: c.leaseName,
195-
BinaryVersion: c.binaryVersion,
196-
EmulationVersion: c.emulationVersion,
197-
PreferredStrategies: c.preferredStrategies,
193+
Spec: v1alpha2.LeaseCandidateSpec{
194+
LeaseName: c.leaseName,
195+
BinaryVersion: c.binaryVersion,
196+
EmulationVersion: c.emulationVersion,
197+
Strategy: c.strategy,
198198
},
199199
}
200200
lc.Spec.RenewTime = &metav1.MicroTime{Time: c.clock.Now()}

Diff for: tools/leaderelection/leasecandidate_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestLeaseCandidateCreation(t *testing.T) {
5353
tc.leaseName,
5454
tc.binaryVersion,
5555
tc.emulationVersion,
56-
[]v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion},
56+
v1.OldestEmulationVersion,
5757
)
5858
if err != nil {
5959
t.Fatal(err)
@@ -87,7 +87,7 @@ func TestLeaseCandidateAck(t *testing.T) {
8787
tc.leaseName,
8888
tc.binaryVersion,
8989
tc.emulationVersion,
90-
[]v1.CoordinatedLeaseStrategy{v1.OldestEmulationVersion},
90+
v1.OldestEmulationVersion,
9191
)
9292
if err != nil {
9393
t.Fatal(err)
@@ -101,12 +101,12 @@ func TestLeaseCandidateAck(t *testing.T) {
101101

102102
// Update PingTime and verify that the client renews
103103
ensureAfter := &metav1.MicroTime{Time: time.Now()}
104-
lc, err := client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
104+
lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
105105
if err == nil {
106106
if lc.Spec.PingTime == nil {
107107
c := lc.DeepCopy()
108108
c.Spec.PingTime = &metav1.MicroTime{Time: time.Now()}
109-
_, err = client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{})
109+
_, err = client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Update(ctx, c, metav1.UpdateOptions{})
110110
if err != nil {
111111
t.Error(err)
112112
}
@@ -120,7 +120,7 @@ func TestLeaseCandidateAck(t *testing.T) {
120120

121121
func pollForLease(ctx context.Context, tc testcase, client *fake.Clientset, t *metav1.MicroTime) error {
122122
return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 10*time.Second, true, func(ctx context.Context) (done bool, err error) {
123-
lc, err := client.CoordinationV1alpha1().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
123+
lc, err := client.CoordinationV1alpha2().LeaseCandidates(tc.candidateNamespace).Get(ctx, tc.candidateName, metav1.GetOptions{})
124124
if err != nil {
125125
if errors.IsNotFound(err) {
126126
return false, nil

0 commit comments

Comments
 (0)