From 6396e9cf15d2386cab326cc98c519b94add7a474 Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Tue, 17 Sep 2024 18:04:43 -0700 Subject: [PATCH] chore: Fix possible Registration TTL race condition (#1665) --- pkg/controllers/nodeclaim/lifecycle/liveness.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/nodeclaim/lifecycle/liveness.go b/pkg/controllers/nodeclaim/lifecycle/liveness.go index f537ddc32f..f1181c95ac 100644 --- a/pkg/controllers/nodeclaim/lifecycle/liveness.go +++ b/pkg/controllers/nodeclaim/lifecycle/liveness.go @@ -48,8 +48,9 @@ func (l *Liveness) Reconcile(ctx context.Context, nodeClaim *v1.NodeClaim) (reco return reconcile.Result{Requeue: true}, nil } // If the Registered statusCondition hasn't gone True during the TTL since we first updated it, we should terminate the NodeClaim - if l.clock.Since(registered.LastTransitionTime.Time) < registrationTTL { - return reconcile.Result{RequeueAfter: registrationTTL - l.clock.Since(registered.LastTransitionTime.Time)}, nil + // NOTE: ttl has to be stored and checked in the same place since l.clock can advance after the check causing a race + if ttl := registrationTTL - l.clock.Since(registered.LastTransitionTime.Time); ttl > 0 { + return reconcile.Result{RequeueAfter: ttl}, nil } // Delete the NodeClaim if we believe the NodeClaim won't register since we haven't seen the node if err := l.kubeClient.Delete(ctx, nodeClaim); err != nil {