Skip to content

fix: propagate reconcile ctx through NetpolReconciler instead of context.Background()#492

Open
mdryaan wants to merge 1 commit into
kubeslice:masterfrom
mdryaan:fix/netpol-compare-uses-background-context
Open

fix: propagate reconcile ctx through NetpolReconciler instead of context.Background()#492
mdryaan wants to merge 1 commit into
kubeslice:masterfrom
mdryaan:fix/netpol-compare-uses-background-context

Conversation

@mdryaan
Copy link
Copy Markdown

@mdryaan mdryaan commented May 24, 2026

Description

NetpolReconciler was using context.Background() in five places inside Compare, one place inside getSliceNameFromNsOfNetPol, and one direct r.Get call in Reconcile. The reconcile context carries the deadline, cancellation signal, and structured logger set up by controller-runtime — dropping it means API calls in this reconciler ignore timeouts,
can't be cancelled, and lose log correlation with the reconcile run they belong to.

Fixed by threading the reconcile ctx through Compare (added as a parameter) and getSliceNameFromNsOfNetPol (added as a parameter), and replacing every context.Background() call with ctx.

Fixes #491

How Has This Been Tested?

  • make fmt — no formatting changes
  • make vet — no issues
  • make build — builds cleanly
  • make test — all suites pass; pre-existing spoke timeout failures confirmed identical on master

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have ran go fmt
  • I have updated the helm chart as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit test cases.
  • I have verified the E2E test cases with new code changes.
  • I have added all the required E2E test cases.

Does this PR introduce a breaking change?


…ext.Background()

Signed-off-by: Md Raiyan <alikhurshid842001@gmail.com>
@mdryaan
Copy link
Copy Markdown
Author

mdryaan commented May 24, 2026

Hey @gourishkb @Rahul-D78, Could you please have a look at this PR whenever you have time? Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: NetpolReconciler.Compare uses context.Background() instead of the reconcile context

1 participant