Skip to content

Conversation

@jakubramut
Copy link

@jakubramut jakubramut commented Jan 23, 2026

Description of your changes

Adds an optional Kind field to EnqueueRequestForProviderConfig that allows controllers to filter ProviderConfigUsage events by the referenced ProviderConfig kind.

Why this is needed:
When a provider has multiple ProviderConfig types (e.g., namespaced ProviderConfig and cluster-scoped ClusterProviderConfig) that share the same ProviderConfigUsage resource, both controllers receive all events. This causes the wrong controller to attempt lookups and log spurious errors like:
cannot get ProviderConfig... ProviderConfig.azuread.m.upbound.io \"name\" not found
even when the resource correctly references a ClusterProviderConfig.

How it works

  • If Kind is empty - no changes (backward compatible)
  • If Kind is set - only matching events
  • Cluster-scoped kinds omit namespace from the reconcile request

How I tested
Based on https://github.com/crossplane-contrib/provider-upjet-azuread using a go.mod replace

  1. Applied resources as in [Bug]: Incorrect attempt to look up ProviderConfig crossplane-contrib/provider-upjet-azuread#267
  2. Before: Debug logs showing failed ProviderConfig lookups
  3. After: No more invalid logs, controllers only process their respective kinds

Related provider PR will follow once this change is released.

Fixes: crossplane-contrib/provider-upjet-azuread#267

I have:

  • Read and followed Crossplane's contribution process.
  • Run earthly +reviewable to ensure this PR is ready for review.
    No, but I run:
    go test ./pkg/resource -run TestAddProviderConfig
    go vet ./pkg/resource
    golangci-lint run ./pkg/resource
    
  • Added or updated unit tests.
  • Linked a PR or a docs tracking issue to document this change.
  • [] Added backport release-x.y labels to auto-backport this PR.
    Cannot do it, but ready do be added.

Need help with this checklist? See the cheat sheet.

Allows controllers to filter ProviderConfigUsage events by Kind, preventing incorrect lookups when multiple ProviderConfig types share the same usage resource.

Signed-off-by: Jakub Ramut <ramut.jakub@gmail.com>
@jakubramut jakubramut requested a review from a team as a code owner January 23, 2026 13:02
@jakubramut jakubramut requested a review from jbw976 January 23, 2026 13:02
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds a Kind field to EnqueueRequestForProviderConfig and converts addProviderConfig into an instance method. Implements Kind-based filtering and cluster-aware enqueueing: if the ProviderConfig kind is cluster-scoped (Kind starts with "Cluster") the queued reconcile.Request omits Namespace; otherwise it includes Namespace. Tests updated to cover these cases.

Changes

Cohort / File(s) Summary
Handler Logic Updates
pkg/resource/enqueue_handlers.go
Adds public Kind string to EnqueueRequestForProviderConfig; converts package addProviderConfig to func (e *EnqueueRequestForProviderConfig) addProviderConfig(obj runtime.Object, queue adder); implements Kind-based filtering and cluster-scoped branch (omit Namespace when Kind starts with "Cluster"); adds strings import.
Handler Tests
pkg/resource/enqueue_handlers_test.go
Tests refactored to instantiate handler and call handler.addProviderConfig(...); renames and adds cases to validate TypedProviderConfigUsage path, cluster-scoped omission of Namespace, matching/non-matching Kind filtering, and defaulting empty ref.Kind to ProviderConfig.
Formatting
pkg/resource/resource_test.go
Minor whitespace alignment change in a test object literal (cosmetic).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Obj as Resource object
participant Handler as EnqueueRequestForProviderConfig
participant Queue as workqueue.Adder
participant Req as reconcile.Request
Obj->>Handler: event (Create/Update/Delete/Generic)
Handler->>Handler: parse ProviderConfigRef (name, kind)
alt ref.Kind empty
Handler->>Handler: default kind = "ProviderConfig"
end
alt kind starts with "Cluster"
Handler->>Queue: Add(Req{Name: ref.Name})
else
Handler->>Queue: Add(Req{Namespace: obj.ProviderConfigRef.Namespace, Name: ref.Name})
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and descriptively summarizes the main change: adding a Kind filter to EnqueueRequestForProviderConfig, which is the core objective of the PR.
Description check ✅ Passed The description is well-related to the changeset, explaining the motivation, implementation approach, testing, and how it addresses the linked issue.
Linked Issues check ✅ Passed The PR successfully implements the core requirement from issue #267: filtering ProviderConfigUsage events by Kind to prevent spurious lookups of the wrong ProviderConfig type.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing Kind filtering for EnqueueRequestForProviderConfig; test updates and minor formatting changes are within scope.
Breaking Changes ✅ Passed The PR does not introduce breaking changes to the public API. The new optional Kind field in EnqueueRequestForProviderConfig is backward compatible, and only internal implementation details were refactored.

✏️ 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@pkg/resource/enqueue_handlers.go`:
- Around line 73-82: Default an empty ProviderConfigReference kind to
"ProviderConfig" before applying the kind filter and cluster-scope detection:
after obtaining ref via pcr.GetProviderConfigReference() set a localKind =
ref.Kind (or "ProviderConfig" when ref.Kind == "") and then use that localKind
for the comparison against e.Kind and for the strings.HasPrefix(..., "Cluster")
check so events aren't dropped when ref.Kind is omitted; update the comparisons
around e.Kind, strings.HasPrefix(ref.Kind, "Cluster"), and the reconcile.Request
construction to reference the normalized localKind.

… filtering is enabled.

Signed-off-by: Jakub Ramut <ramut.jakub@gmail.com>
@jakubramut jakubramut force-pushed the enqueue-providerconfig-kind-filter branch from 30c83be to b5dfb20 Compare January 23, 2026 13:31
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]: Incorrect attempt to look up ProviderConfig

1 participant