fix: ProviderConfig reconciler to filter usages by namespace#935
fix: ProviderConfig reconciler to filter usages by namespace#935kostyaplis wants to merge 1 commit intocrossplane:mainfrom
Conversation
Signed-off-by: Konstantin Plis <plis.konstantin@gmail.com>
5a6881e to
75f8eb9
Compare
📝 WalkthroughWalkthroughThe reconciler now builds a variadic slice of client ListOptions (including an InNamespace option when the ProviderConfig has a namespace) and passes them to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/reconciler/providerconfig/reconciler.go (1)
165-169: Nitpick: consider adding"namespace"to the log context alongside the new namespace-scoped behavior.Now that
pc.GetNamespace()drives a meaningful branch in the reconcile loop, including it in the structured log values would make per-namespace debugging much easier (e.g., when two same-named ProviderConfigs are reconciled concurrently, log lines will be distinguishable without needing to cross-reference the UID):🔍 Suggested observability improvement
log = log.WithValues( "uid", pc.GetUID(), "version", pc.GetResourceVersion(), "name", pc.GetName(), + "namespace", pc.GetNamespace(), )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/reconciler/providerconfig/reconciler.go` around lines 165 - 169, Add the ProviderConfig namespace to the structured logger context so per-namespace debugging is possible: update the log.WithValues call in reconciler.go (the block that sets log = log.WithValues("uid", pc.GetUID(), "version", pc.GetResourceVersion(), "name", pc.GetName())) to include "namespace" with pc.GetNamespace(); ensure the key is exactly "namespace" and the value uses pc.GetNamespace() so logs for Reconcile/ProviderConfig handling (e.g., in the reconcile loop and any functions using that log) are disambiguated when same-named resources exist in different namespaces.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/reconciler/providerconfig/reconciler.go`:
- Around line 181-184: Add unit tests that verify the namespace-scoping behavior
around the listOpts construction in reconciler.go: create two table-driven test
cases for the Reconciler handling of ProviderConfig (one where
fake.ProviderConfig has a Namespace set and one with an empty Namespace), then
assert that the client.List call is invoked with
client.InNamespace(pc.GetNamespace()) when pc.GetNamespace() != "" and that no
InNamespace option is passed when cluster-scoped; exercise the code path that
builds listOpts (the code using listOpts := []client.ListOption{matchingLabels}
and the branch with pc.GetNamespace()) and use a fake/client that records
received List options to make the assertions.
---
Nitpick comments:
In `@pkg/reconciler/providerconfig/reconciler.go`:
- Around line 165-169: Add the ProviderConfig namespace to the structured logger
context so per-namespace debugging is possible: update the log.WithValues call
in reconciler.go (the block that sets log = log.WithValues("uid", pc.GetUID(),
"version", pc.GetResourceVersion(), "name", pc.GetName())) to include
"namespace" with pc.GetNamespace(); ensure the key is exactly "namespace" and
the value uses pc.GetNamespace() so logs for Reconcile/ProviderConfig handling
(e.g., in the reconcile loop and any functions using that log) are disambiguated
when same-named resources exist in different namespaces.
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@pkg/reconciler/providerconfig/reconciler.go`:
- Around line 181-184: Add unit tests for the namespaced vs cluster-scoped
list-scoping behavior introduced around listOpts/listOpts =
append(...client.InNamespace...) in reconciler.go: create a table-driven test in
pkg/reconciler/providerconfig/reconciler_test.go that constructs
fake.ProviderConfig instances with Namespace: "test-ns" and Namespace: ""
(fake.ProviderConfig embeds metav1.ObjectMeta), calls the reconciler method that
invokes client.List (use the same function under test that builds listOpts), and
assert that when pc.GetNamespace() == "test-ns" the client.List call receives
both matchingLabels and client.InNamespace("test-ns"), and when
pc.GetNamespace() == "" the client.List call receives only matchingLabels; use
the existing fake client/test harness to inspect the List call arguments and add
two assertions (one per case) to prevent regression.
Description of your changes
Fixes crossplane/crossplane#7154
The fix adds client.InNamespace(pc.GetNamespace()) to the list options when the ProviderConfig is namespaced. ClusterProviderConfigs are unaffected and they continue to list across all namespaces.
Manual test:
crossplane xpkg buildand pushed to public repo usingcrossplane xpkg pushstatus.userscounts are scoped correctly per namespace. While ClusterProviderConfigs are not affected. Simple test case included in the issue: Namespaced ProviderConfigUsage should consider ProviderConfig namespace. crossplane#7154I have:
./nix.sh flake checkto ensure this PR is ready for review.Added or updated unit tests.Linked a PR or a docs tracking issue to document this change.Addedbackport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.