backend: Replace context.TODO() with explicit background context in long-running goroutine#5095
backend: Replace context.TODO() with explicit background context in long-running goroutine#5095itvi-1234 wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
…ong-running goroutine Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: itvi-1234 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @sniok @vyncent-t @skoeva This is a small code cleanup. It replaces the temporary context.TODO() placeholders with the proper ctx (context.Background()) variable that was already defined at the start of the function. Because Node Draining takes a long time, it runs in the background. Using the correct background context ensures the draining process safely finishes its job, even if the user accidentally closes their browser before it completes. Could you please review this PR , lemme know if any changes needed 🚀 |
There was a problem hiding this comment.
Pull request overview
This PR updates the backend node-drain async goroutine to consistently use its explicitly created context.Background() (ctx) instead of context.TODO() when calling Kubernetes client APIs, making the intended “outlives request scope” behavior explicit and consistent.
Changes:
- Use the goroutine’s
ctxforNodes().GetandNodes().Update. - Use the same
ctxfor listing and deleting pods during the drain operation.
|
Hi @sniok , any directions regarding this PR |
Summary
This PR cleans up technical debt in the Golang backend inside the
drainNodeasynchronous API handler. It replaces repeatedcontext.TODO()usages with the correctly initialized, explicitcontext.Background()wrapper variablectxthat the goroutine actually instantiated but failed to pass downstream.Changes
backend/cmd/headlamp.go: Inside thedrainNodegoroutine, replacedcontext.TODO()in KubernetesnodeClientandclientset.CoreV1().Pods()calls with the availablectxvariable to explicitly signify that this work outlives the HTTP request scope.