Skip to content

Comments

fix: ProviderConfig reconciler to filter usages by namespace#936

Open
kruthiwusirika5 wants to merge 1 commit intocrossplane:mainfrom
kruthiwusirika5:fix/providerconfig-namespace-filter
Open

fix: ProviderConfig reconciler to filter usages by namespace#936
kruthiwusirika5 wants to merge 1 commit intocrossplane:mainfrom
kruthiwusirika5:fix/providerconfig-namespace-filter

Conversation

@kruthiwusirika5
Copy link

Fixes crossplane/crossplane#7154

What happened

When a ProviderConfig is namespaced, the reconciler listed ProviderConfigUsages by label only and did not scope the List to the ProviderConfig’s namespace. As a result, usages from other namespaces (e.g. a same-named ProviderConfig in another namespace) were counted, so a namespaced ProviderConfig could show users: 1 and be blocked from deletion even when all usages were in a different namespace.

Changes

  • Scoped List for namespaced ProviderConfig: When pc.GetNamespace() != "", add client.InNamespace(pc.GetNamespace()) to the list options so only ProviderConfigUsages in that namespace are considered. Cluster-scoped ProviderConfigs are unchanged (no InNamespace option).
  • Logging: Include "namespace", pc.GetNamespace() in the reconciler’s structured log context to make per-namespace debugging easier when multiple same-named ProviderConfigs exist.
  • Tests: Two unit tests were added:
    • ListUsagesScopedToNamespaceWhenNamespaced: asserts that when the ProviderConfig has a namespace, List is called with InNamespace set to that namespace.
    • ListUsagesNotScopedToNamespaceWhenClusterScoped: asserts that when the ProviderConfig is cluster-scoped (empty namespace), List is called without an InNamespace option.

Testing

  • go test ./pkg/reconciler/providerconfig/... passes, including the new cases.

@kruthiwusirika5 kruthiwusirika5 requested a review from a team as a code owner February 23, 2026 03:34
@kruthiwusirika5 kruthiwusirika5 force-pushed the fix/providerconfig-namespace-filter branch from aac6fe7 to f27f023 Compare February 23, 2026 03:35
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

Warning

Rate limit exceeded

@kruthiwusirika5 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This PR fixes a bug where ProviderConfig deletion was incorrectly blocked when a same-named ProviderConfig existed in a different namespace. The reconciler now scopes ProviderConfigUsage queries to the specific namespace of the ProviderConfig being reconciled, preventing cross-namespace interference.

Changes

Cohort / File(s) Summary
Namespace Scoping for ProviderConfig Queries
pkg/reconciler/providerconfig/reconciler.go
Modified the List call to include namespace scoping via InNamespace(pc.GetNamespace()) when the ProviderConfig has a namespace. Constructs variadic listOpts to conditionally apply namespace filtering based on whether the ProviderConfig is cluster-scoped or namespaced.
Test Coverage for Namespace Scoping
pkg/reconciler/providerconfig/reconciler_test.go
Added request field to test want struct and two new test cases: one verifying List is invoked with InNamespace() for namespaced ProviderConfigs, and another confirming List is invoked without namespace scoping for cluster-scoped ProviderConfigs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: fixing the ProviderConfig reconciler to filter usages by namespace, staying under the 72-character limit.
Description check ✅ Passed The description is well-related to the changeset, providing context on the bug, changes made, and testing performed. It references the linked issue and explains the namespace filtering logic.
Linked Issues check ✅ Passed The changes directly address the linked issue #7154 by implementing namespace-scoped filtering for ProviderConfigUsages. The reconciler now uses InNamespace when the ProviderConfig is namespaced, preventing cross-namespace usage counts.
Out of Scope Changes check ✅ Passed All changes are directly related to the scope of fixing issue #7154: namespace-scoped List filtering, logging context, and related unit tests. No extraneous or unrelated modifications were introduced.
Breaking Changes ✅ Passed No exported or public Go entities were modified. Changes are internal implementation details within the Reconcile method body only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…rossplane/crossplane#7154)

Signed-off-by: Sai Kruthi Wusirika <kruthi@multiscale.ai>
Signed-off-by: Kruthi Wusirika <kruthiwusirika@gmail.com>
@kruthiwusirika5 kruthiwusirika5 force-pushed the fix/providerconfig-namespace-filter branch from f27f023 to 2ddf578 Compare February 23, 2026 03:38
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.

Namespaced ProviderConfigUsage should consider ProviderConfig namespace.

1 participant