mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-27 07:28:14 +00:00
Add LeaseCandidate v1beta1
Kubernetes-commit: 5ba4a90fdad6bf9cdfa69e166aff9786efc9430c
This commit is contained in:
parent
8489267318
commit
dbe73bc712
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user