Fix: Empty selector default to match nothing (#37)#76
Merged
damsallem merged 1 commit intocriteo:mainfrom Jan 12, 2026
Merged
Conversation
geobeau
requested changes
Dec 22, 2025
Contributor
geobeau
left a comment
There was a problem hiding this comment.
Looks good, thank you for contributing.
I just have the feeling that relying on Empty() is nicer so let me know if there is a specific reason for it, otherwise I would just use selector.Empty() when possible
1c426b2 to
0b1a3df
Compare
geobeau
approved these changes
Dec 30, 2025
Contributor
|
LGTM, Just waiting for @damsallem validation to merge it |
damsallem
approved these changes
Jan 12, 2026
Contributor
|
Thanks a lot for your contribution. Before validating I took some times to validate all our production in term of usage of these selector to make sure nothing was broken. |
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.
Fixes #37
Problem
When using label selectors in disruption budgets, the current implementation treats empty selectors as matching all resources. This behavior is unintuitive and potentially dangerous, as users would expect an empty selector to match nothing rather than everything.
The issue occurs because the code was checking
selector.Empty()after converting the label selector, which in Kubernetes semantics means "match all resources" rather than "match no resources".Root Cause
The problematic pattern was present in multiple locations:
When a
LabelSelectorhas noMatchLabelsand noMatchExpressions, the converted selector would match all resources when passed to Kubernetes API calls, leading to unintended behavior.Solution
This PR implements explicit checks before selector conversion to ensure empty selectors return empty result sets, preventing them from matching any resources. The check pattern applied is:
Changes
Core Logic Changes
pkg/resolver/resolver.go
GetNodesFromNamespacedPodSelector(): Added empty selector checkGetNodesFromNamespacedPVCSelector(): Added empty selector checkGetNodeFromNodeSelector(): Added empty selector checkapi/v1alpha1/applicationdisruptionbudget_types.go
SelectorMatchesObject(): Added empty selector checks for both PodSelector and PVCSelector casesapi/v1alpha1/nodedisruptionbudget_types.go
SelectorMatchesObject(): Added empty selector check for NodeSelector caseTest Coverage
Added comprehensive test cases to verify the fix:
ApplicationDisruptionBudget tests
NodeDisruptionBudget tests
All tests verify that:
Testing
go vetandgo buildImpact
This change modifies the default behavior of empty selectors from "match all" to "match nothing". While this is technically a breaking change in behavior, it fixes an unintuitive and potentially dangerous default.
The impact is limited to:
Existing budgets with properly defined selectors are unaffected.
Backward Compatibility
Users who relied on empty selectors matching all resources will need to update their configurations. However, this scenario is unlikely as:
The new behavior aligns with the principle of least surprise and is safer by default.
Checklist
go fmtgo vet