fix: set namespace on ResourceSelector when using matchLabels - #615
Closed
pujitha24 wants to merge 1 commit into
Closed
fix: set namespace on ResourceSelector when using matchLabels#615pujitha24 wants to merge 1 commit into
pujitha24 wants to merge 1 commit into
Conversation
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>
pujitha24
requested review from
adamwg,
bobh66,
ezgidemirel,
phisco,
sergenyalcin,
turkenf and
ulucinar
as code owners
August 11, 2026 07:41
Collaborator
|
Isn't this a duplicate of #612 ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
ExtraResourcesRequirement.ToResourceSelector()returned early right after building the matchLabels selector, before the code that copiesNamespaceonto the resultingfnv1.ResourceSelectorran. 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
ToResourceSelectorso the namespace-setting block runs regardless of whether the selector was built from matchName or matchLabels.Covered by a new
extraresources_test.gowith 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.