Skip to content

fix: ProviderConfig reconciler to filter usages by namespace#936

Merged
phisco merged 2 commits intocrossplane:mainfrom
kruthiwusirika5:fix/providerconfig-namespace-filter
May 4, 2026
Merged

fix: ProviderConfig reconciler to filter usages by namespace#936
phisco merged 2 commits intocrossplane:mainfrom
kruthiwusirika5:fix/providerconfig-namespace-filter

Conversation

@kruthiwusirika5
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

coderabbitai Bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d6025287-1ef8-472f-8f85-8b90965a45ea

📥 Commits

Reviewing files that changed from the base of the PR and between f27f023 and 4a7e553.

📒 Files selected for processing (2)
  • pkg/reconciler/providerconfig/reconciler.go
  • pkg/reconciler/providerconfig/reconciler_test.go

📝 Walkthrough

Walkthrough

This PR scopes ProviderConfigUsage listing to the reconciled ProviderConfig's namespace when present, and records the ProviderConfig namespace in the reconciler's logging context. It prevents cross-namespace ProviderConfigUsage interference during deletion checks.

Changes

Cohort / File(s) Summary
Namespace scoping in reconciler
pkg/reconciler/providerconfig/reconciler.go
Changed ProviderConfigUsage list to build variadic listOpts that always include existing matchingLabels and conditionally add client.InNamespace(pc.GetNamespace()) when the ProviderConfig has a non-empty namespace; added ProviderConfig namespace to logger context.
Tests for namespaced vs cluster-scoped behavior
pkg/reconciler/providerconfig/reconciler_test.go
Updated tests to set an expected reconcile.Request in want and added cases asserting Client.List receives namespaced list options for namespaced ProviderConfigs and no namespace option for cluster-scoped ProviderConfigs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Breaking Changes ❌ Error PR changes exported public API types from xpv2 to xpv1 packages without 'breaking-change' label, causing compilation incompatibility despite semantic equivalence. Add 'breaking-change' label to acknowledge API migration, or maintain xpv2 types in public signatures with internal xpv1 conversion for backward compatibility.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: filtering ProviderConfigUsages by namespace in the reconciler.
Description check ✅ Passed The PR description is detailed and directly related to the changeset, explaining the bug fix, specific changes, and test coverage.
Linked Issues check ✅ Passed The PR fully addresses the linked issue #7154 by scoping ProviderConfigUsage listing to the ProviderConfig's namespace [#7154], adding namespace to logging context, and adding comprehensive tests for both namespaced and cluster-scoped scenarios.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objective of namespace-scoping ProviderConfigUsage filtering; no out-of-scope modifications detected.

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
@kruthiwusirika5
Copy link
Copy Markdown
Contributor Author

Hi @jbw976 — this PR is ready for review when you have time.

Summary: Fixes crossplane/crossplane#7154. When a ProviderConfig is namespaced, the reconciler now scopes the ProviderConfigUsage List to that namespace (InNamespace(pc.GetNamespace())), so a namespaced ProviderConfig is no longer blocked from deletion by usages in other namespaces. Cluster-scoped ProviderConfigs are unchanged.

Changes: Scoped List for namespaced ProviderConfig, added namespace to reconciler log context, and two unit tests (namespaced → List with InNamespace, cluster-scoped → List without InNamespace).

go test ./pkg/reconciler/providerconfig/... passes. CodeRabbit’s pre-merge checks passed (it hit rate limit before posting a full review). Happy to address any feedback.

@kruthiwusirika5
Copy link
Copy Markdown
Contributor Author

Hi @phisco

This PR is ready for review, kindly review it

Summary: Fixes crossplane/crossplane#7154. When a ProviderConfig is namespaced, the reconciler now scopes the ProviderConfigUsage List to that namespace (InNamespace(pc.GetNamespace())), so a namespaced ProviderConfig is no longer blocked from deletion by usages in other namespaces. Cluster-scoped ProviderConfigs are unchanged.

Changes: Scoped List for namespaced ProviderConfig, added namespace to reconciler log context, and two unit tests (namespaced → List with InNamespace, cluster-scoped → List without InNamespace).

go test ./pkg/reconciler/providerconfig/... passes. CodeRabbit’s pre-merge checks passed (it hit rate limit before posting a full review). Happy to address any feedback.

Copy link
Copy Markdown
Contributor

@phisco phisco left a comment

Choose a reason for hiding this comment

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

Thanks @kruthiwusirika5! LGTM, except for the linting issues, let me know when you manage to fix them 🙏

The MockList callbacks declared ctx and list parameters that are
not used in the test bodies. Rename them to _ to satisfy revive's
unused-parameter rule.

Signed-off-by: Kruthi Wusirika <kruthiwusirika@gmail.com>
@kruthiwusirika5
Copy link
Copy Markdown
Contributor Author

kruthiwusirika5 commented Apr 27, 2026

@phisco @jbw976 lint fix pushed — revive unused-parameter on the two new MockList callbacks. Ready for re-review whenever you have a moment.

@kruthiwusirika5
Copy link
Copy Markdown
Contributor Author

Two quick notes to help unblock this:

1. The CodeRabbit "Breaking Changes" pre-merge flag is a false positive.

The full diff (both files) does not convert any exported type between xpv1 and xpv2 packages. Concretely:

  • pkg/reconciler/providerconfig/reconciler.go — adds "namespace" to the existing logger context and switches one client.List call from positional args to a conditional []client.ListOption slice that appends client.InNamespace(pc.GetNamespace()) only when the ProviderConfig is namespaced. No exported function signature is modified, no new public type is introduced, and the single xpv1.LabelKeyProviderKind reference on the matchingLabels line is unchanged from before this PR.
  • pkg/reconciler/providerconfig/reconciler_test.go — adds two table-driven test cases and one field to the unexported (test-package-internal) want struct.

So the breaking-change label should not be needed. Happy to be told otherwise if I'm missing something.

2. The actual merge blocker looks like a stale approval, not a code issue.

@phisco your approval from 2026-03-30 was against 2ddf578 (the original commit). The only push since then (4a7e553, 2026-04-27) is a lint-only fix that renames two unused MockList callback parameters to _ to satisfy revive's unused-parameter rule — no behavior change, no test change, no public-API change. If the dismiss-stale-approvals branch policy is what's keeping mergeable_state at blocked, would you mind a quick re-stamp when you have a minute?

All checks (DCO, CodeRabbit walkthrough) are green on the new HEAD. Thanks!

@kruthiwusirika5
Copy link
Copy Markdown
Contributor Author

Gentle nudge @phisco — your approval was on the original commit; the only push since was a lint-only rename of two unused MockList parameters to satisfy revive. Branch protection is treating that as a stale approval and the PR is sitting at mergeStateStatus: BLOCKED. A quick re-stamp would unblock it whenever you have a moment. Thanks!

@phisco phisco merged commit a596e1f into crossplane:main May 4, 2026
10 checks passed
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.

2 participants