Skip to content

backend: Replace context.TODO() with explicit background context in long-running goroutine#5095

Open
itvi-1234 wants to merge 1 commit intokubernetes-sigs:mainfrom
itvi-1234:fix/backend-context-usage
Open

backend: Replace context.TODO() with explicit background context in long-running goroutine#5095
itvi-1234 wants to merge 1 commit intokubernetes-sigs:mainfrom
itvi-1234:fix/backend-context-usage

Conversation

@itvi-1234
Copy link
Copy Markdown
Contributor

Summary

This PR cleans up technical debt in the Golang backend inside the drainNode asynchronous API handler. It replaces repeated context.TODO() usages with the correctly initialized, explicit context.Background() wrapper variable ctx that the goroutine actually instantiated but failed to pass downstream.

Changes

  • backend/cmd/headlamp.go: Inside the drainNode goroutine, replaced context.TODO() in Kubernetes nodeClient and clientset.CoreV1().Pods() calls with the available ctx variable to explicitly signify that this work outlives the HTTP request scope.

…ong-running goroutine

Signed-off-by: itvi-1234 <rjsumit71@gmail.com>
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: itvi-1234
Once this PR has been reviewed and has the lgtm label, please assign illume for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from skoeva and vyncent-t April 8, 2026 11:50
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 8, 2026
@itvi-1234
Copy link
Copy Markdown
Contributor Author

itvi-1234 commented Apr 8, 2026

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 🚀

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ctx for Nodes().Get and Nodes().Update.
  • Use the same ctx for listing and deleting pods during the drain operation.

@itvi-1234
Copy link
Copy Markdown
Contributor Author

itvi-1234 commented Apr 9, 2026

Hi @illume , @sniok The PR looks fine , lemme know if any changes needed

@itvi-1234
Copy link
Copy Markdown
Contributor Author

Hi @sniok , any directions regarding this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants