From 9dde1f84ee0e4c9054e5684e8fe7178b074b6469 Mon Sep 17 00:00:00 2001 From: Suyash Choudhary <57896905+sssash18@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:51:12 +0530 Subject: [PATCH] passing drain context only in drainNode --- pkg/util/provider/drain/drain.go | 1 + pkg/util/provider/machinecontroller/machine_util.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/util/provider/drain/drain.go b/pkg/util/provider/drain/drain.go index 4b8b0efd1..3b55d7c92 100644 --- a/pkg/util/provider/drain/drain.go +++ b/pkg/util/provider/drain/drain.go @@ -996,6 +996,7 @@ func (o *Options) evictPodWithoutPVInternal(ctx context.Context, attemptEvict bo if i >= nretries { attemptEvict = false } + if attemptEvict { err = o.evictPod(ctx, pod, policyGroupVersion) } else { diff --git a/pkg/util/provider/machinecontroller/machine_util.go b/pkg/util/provider/machinecontroller/machine_util.go index 25554d76d..5158a581a 100644 --- a/pkg/util/provider/machinecontroller/machine_util.go +++ b/pkg/util/provider/machinecontroller/machine_util.go @@ -1044,7 +1044,7 @@ func (c *controller) drainNode(ctx context.Context, deleteMachineRequest *driver ReadonlyFilesystem v1.NodeConditionType = "ReadonlyFilesystem" ) - drainContext, cancelFn := context.WithDeadline(ctx, deleteMachineRequest.Machine.DeletionTimestamp.Add(timeOutDuration)) + drainContext, cancelFn := context.WithDeadline(ctx, time.Now().Add(timeOutDuration)) defer cancelFn() if !isValidNodeName(nodeName) { message := "Skipping drain as nodeName is not a valid one for machine." @@ -1114,7 +1114,7 @@ func (c *controller) drainNode(ctx context.Context, deleteMachineRequest *driver } // update node with the machine's phase prior to termination - if err = c.UpdateNodeTerminationCondition(drainContext, machine); err != nil { + if err = c.UpdateNodeTerminationCondition(ctx, machine); err != nil { if forceDeleteMachine { klog.Warningf("Failed to update node conditions: %v. However, since it's a force deletion shall continue deletion of VM.", err) } else { @@ -1185,7 +1185,7 @@ func (c *controller) drainNode(ctx context.Context, deleteMachineRequest *driver } updateRetryPeriod, updateErr := c.machineStatusUpdate( - drainContext, + ctx, machine, v1alpha1.LastOperation{ Description: description,