Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3304ad6

Browse files
cartermckinnonk8s-publishing-bot
authored andcommittedMay 13, 2025
fix(kubelet): update lease duration when config changes
Kubernetes-commit: 2fe65bbf48b365e86e825a7165085f5781c3d5a5
1 parent 11a2332 commit 3304ad6

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed
 

‎apimachinery/lease/controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
clientset "k8s.io/client-go/kubernetes"
2929
coordclientset "k8s.io/client-go/kubernetes/typed/coordination/v1"
3030
"k8s.io/utils/clock"
31-
"k8s.io/utils/pointer"
31+
"k8s.io/utils/ptr"
3232

3333
"k8s.io/klog/v2"
3434
)
@@ -221,13 +221,14 @@ func (c *controller) newLease(base *coordinationv1.Lease) (*coordinationv1.Lease
221221
Namespace: c.leaseNamespace,
222222
},
223223
Spec: coordinationv1.LeaseSpec{
224-
HolderIdentity: pointer.StringPtr(c.holderIdentity),
225-
LeaseDurationSeconds: pointer.Int32Ptr(c.leaseDurationSeconds),
224+
HolderIdentity: ptr.To(c.holderIdentity),
226225
},
227226
}
228227
} else {
229228
lease = base.DeepCopy()
230229
}
230+
// update the duration, the controller's config may have changed since lease creation
231+
lease.Spec.LeaseDurationSeconds = ptr.To(c.leaseDurationSeconds)
231232
lease.Spec.RenewTime = &metav1.MicroTime{Time: c.clock.Now()}
232233

233234
if c.newLeasePostProcessFunc != nil {

‎apimachinery/lease/controller_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
clienttesting "k8s.io/client-go/testing"
3838
testingclock "k8s.io/utils/clock/testing"
3939
"k8s.io/utils/pointer"
40+
"k8s.io/utils/ptr"
4041

4142
"k8s.io/klog/v2"
4243
"k8s.io/klog/v2/ktesting"
@@ -194,6 +195,53 @@ func TestNewNodeLease(t *testing.T) {
194195
},
195196
},
196197
},
198+
{
199+
desc: "non-nil base with owner ref, lease duration is updated",
200+
controller: &controller{
201+
client: fake.NewSimpleClientset(node),
202+
holderIdentity: node.Name,
203+
leaseDurationSeconds: 456,
204+
clock: fakeClock,
205+
},
206+
base: &coordinationv1.Lease{
207+
ObjectMeta: metav1.ObjectMeta{
208+
Name: node.Name,
209+
Namespace: corev1.NamespaceNodeLease,
210+
OwnerReferences: []metav1.OwnerReference{
211+
{
212+
APIVersion: corev1.SchemeGroupVersion.WithKind("Node").Version,
213+
Kind: corev1.SchemeGroupVersion.WithKind("Node").Kind,
214+
Name: node.Name,
215+
UID: node.UID,
216+
},
217+
},
218+
},
219+
Spec: coordinationv1.LeaseSpec{
220+
HolderIdentity: ptr.To(node.Name),
221+
LeaseDurationSeconds: ptr.To[int32](123),
222+
RenewTime: &metav1.MicroTime{Time: fakeClock.Now().Add(-10 * time.Second)},
223+
},
224+
},
225+
expect: &coordinationv1.Lease{
226+
ObjectMeta: metav1.ObjectMeta{
227+
Name: node.Name,
228+
Namespace: corev1.NamespaceNodeLease,
229+
OwnerReferences: []metav1.OwnerReference{
230+
{
231+
APIVersion: corev1.SchemeGroupVersion.WithKind("Node").Version,
232+
Kind: corev1.SchemeGroupVersion.WithKind("Node").Kind,
233+
Name: node.Name,
234+
UID: node.UID,
235+
},
236+
},
237+
},
238+
Spec: coordinationv1.LeaseSpec{
239+
HolderIdentity: ptr.To(node.Name),
240+
LeaseDurationSeconds: ptr.To[int32](456),
241+
RenewTime: &metav1.MicroTime{Time: fakeClock.Now()},
242+
},
243+
},
244+
},
197245
}
198246

199247
for _, tc := range cases {

0 commit comments

Comments
 (0)
Please sign in to comment.