Skip to content

fix: set namespace on ResourceSelector when using matchLabels - #615

Closed
pujitha24 wants to merge 1 commit into
crossplane-contrib:mainfrom
pujitha24:auto/issue-600
Closed

fix: set namespace on ResourceSelector when using matchLabels#615
pujitha24 wants to merge 1 commit into
crossplane-contrib:mainfrom
pujitha24:auto/issue-600

Conversation

@pujitha24

Copy link
Copy Markdown
Contributor

Description of your changes

ExtraResourcesRequirement.ToResourceSelector() returned early right after building the matchLabels selector, before the code that copies Namespace onto the resulting fnv1.ResourceSelector ran. An ExtraResources requirement combining matchLabels with a namespace therefore silently lost its namespace scoping: the selector matched labelled resources across all namespaces instead of only the requested one. Requirements using matchName were unaffected, since the namespace-setting code lived after the matchName branch.

This restructures the if/else in ToResourceSelector so the namespace-setting block runs regardless of whether the selector was built from matchName or matchLabels.

Covered by a new extraresources_test.go with a table-driven test, TestExtraResourcesRequirementToResourceSelector, covering matchLabels with a namespace, matchLabels without a namespace, and matchName with a namespace. Confirmed the new test fails against the pre-fix code (missing namespace in the matchLabels+namespace case) and passes after the fix.

Fixes #600

I have:


AI assistance: this change was drafted with Claude Code.

Motivation:
ExtraResourcesRequirement.ToResourceSelector() returned early right
after building the matchLabels selector, before the code that copies
Namespace onto the resulting fnv1.ResourceSelector ran. An
ExtraResources requirement combining matchLabels with a namespace
therefore silently lost its namespace scoping: the selector matched
labelled resources across all namespaces instead of only the
requested one. Requirements using matchName were unaffected, since
the namespace-setting code lived after the matchName branch.

Approach:
Restructure the if/else in ToResourceSelector so the namespace-setting
block runs regardless of whether the selector was built from matchName
or matchLabels.

Validation:
Added extraresources_test.go with a table-driven test,
TestExtraResourcesRequirementToResourceSelector, covering matchLabels
with a namespace, matchLabels without a namespace, and matchName with
a namespace. Confirmed the new test fails against the pre-fix code
(missing namespace in the matchLabels+namespace case) and passes
after the fix. Ran:

  go build ./...
  go vet ./...
  go test ./...

All commands passed.

Report: crossplane-contrib#600
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@bobh66

bobh66 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Isn't this a duplicate of #612 ?

@pujitha24

Copy link
Copy Markdown
Contributor Author

You're right, this duplicates #612 — I opened that one first for the same root cause (issue #597/#600 are the same bug). Closing this in favor of #612.

@pujitha24 pujitha24 closed this Aug 11, 2026
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.

ExtraResources namespace is ignored when using matchLabels

2 participants