From 72f2e1cc0d543c942e318d3100386ffc6369f576 Mon Sep 17 00:00:00 2001 From: Andrew Sy Kim Date: Tue, 1 Nov 2022 12:25:01 -0400 Subject: [PATCH] lease controller: update NewController to accept leaseName as a parameter, remove NewControllerWithLeaseName Signed-off-by: Andrew Sy Kim --- pkg/controlplane/instance.go | 2 +- pkg/kubelet/kubelet.go | 1 + .../apimachinery/lease/controller.go | 25 ++----------------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/pkg/controlplane/instance.go b/pkg/controlplane/instance.go index 669ae582b4b..d725263cfed 100644 --- a/pkg/controlplane/instance.go +++ b/pkg/controlplane/instance.go @@ -476,7 +476,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget) leaseName := m.GenericAPIServer.APIServerID holderIdentity := m.GenericAPIServer.APIServerID + "_" + string(uuid.NewUUID()) - controller := lease.NewControllerWithLeaseName( + controller := lease.NewController( clock.RealClock{}, kubeClient, holderIdentity, diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index a9660e711e6..6fdca955a20 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -833,6 +833,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, kubeCfg.NodeLeaseDurationSeconds, klet.onRepeatedHeartbeatFailure, renewInterval, + string(klet.nodeName), v1.NamespaceNodeLease, util.SetNodeOwnerFunc(klet.heartbeatClient, string(klet.nodeName))) diff --git a/staging/src/k8s.io/component-helpers/apimachinery/lease/controller.go b/staging/src/k8s.io/component-helpers/apimachinery/lease/controller.go index 0602b786a7f..203285e7442 100644 --- a/staging/src/k8s.io/component-helpers/apimachinery/lease/controller.go +++ b/staging/src/k8s.io/component-helpers/apimachinery/lease/controller.go @@ -72,28 +72,7 @@ type controller struct { } // NewController constructs and returns a controller -func NewController(clock clock.Clock, client clientset.Interface, holderIdentity string, leaseDurationSeconds int32, onRepeatedHeartbeatFailure func(), renewInterval time.Duration, leaseNamespace string, newLeasePostProcessFunc ProcessLeaseFunc) Controller { - var leaseClient coordclientset.LeaseInterface - if client != nil { - leaseClient = client.CoordinationV1().Leases(leaseNamespace) - } - return &controller{ - client: client, - leaseClient: leaseClient, - holderIdentity: holderIdentity, - leaseName: holderIdentity, - leaseNamespace: leaseNamespace, - leaseDurationSeconds: leaseDurationSeconds, - renewInterval: renewInterval, - clock: clock, - onRepeatedHeartbeatFailure: onRepeatedHeartbeatFailure, - newLeasePostProcessFunc: newLeasePostProcessFunc, - } -} - -// NewControllerWithLeaseName is a copy of NewController but accepts a leaseName parameter. -// Use this constructor in cases when the lease name and holder identity should be different. -func NewControllerWithLeaseName(clock clock.Clock, client clientset.Interface, holderIdentity string, leaseDurationSeconds int32, onRepeatedHeartbeatFailure func(), renewInterval time.Duration, leaseName, leaseNamespace string, newLeasePostProcessFunc ProcessLeaseFunc) Controller { +func NewController(clock clock.Clock, client clientset.Interface, holderIdentity string, leaseDurationSeconds int32, onRepeatedHeartbeatFailure func(), renewInterval time.Duration, leaseName, leaseNamespace string, newLeasePostProcessFunc ProcessLeaseFunc) Controller { var leaseClient coordclientset.LeaseInterface if client != nil { leaseClient = client.CoordinationV1().Leases(leaseNamespace) @@ -174,7 +153,7 @@ func (c *controller) backoffEnsureLease() (*coordinationv1.Lease, bool) { // ensureLease creates the lease if it does not exist. Returns the lease and // a bool (true if this call created the lease), or any error that occurs. func (c *controller) ensureLease() (*coordinationv1.Lease, bool, error) { - lease, err := c.leaseClient.Get(context.TODO(), c.holderIdentity, metav1.GetOptions{}) + lease, err := c.leaseClient.Get(context.TODO(), c.leaseName, metav1.GetOptions{}) if apierrors.IsNotFound(err) { // lease does not exist, create it. leaseToCreate, err := c.newLease(nil)