-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠️ Default selectors to Nothing if it is nil for MatchingLabelsSelector
and MatchingFieldsSelector
#3279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+32
−0
Merged
⚠️ Default selectors to Nothing if it is nil for MatchingLabelsSelector
and MatchingFieldsSelector
#3279
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would a label or field selector be set if it has no value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons -
MatchingLabelsSelector
also wants to achieve a similar thing; therefore, in case of a nil label selector, it should list all the objects.MatchingLabelsSelector
the list call panics, which should not happenUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, this is the official godoc on metav1.LabelSelector
If we follow that semantic here as well null would mean match no objects
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use -
It lists all objects. What should be the way to go here?
Also
If we follow this, then I can modify the PR to use Nothing instead of Everything when
MatchingLabelsSelector
's selector is not set so it doesn't panic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why you have code that ends up with a nil selector and why that is not considered to be a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about the below changes -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a nil selector in there is incorrect usage and we can not error. We do recover panics though so it seems all right to me.
Your suggestion makes a nil selector match everything, which as mentioned earlier we do not want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't allow us to let the panic happen at the first place.
Also, IMO we should allow list all, because as per the doc string
MatchingLabelsSelector
is supposed to behave the same as LabelSelector, which it doesn't currently.By my main concern for this PR was that we should not let the panic happen, we should stop it one way or another and not let the user figure it out after trial and error. I am open to suggestions for that.
If we really don't want to list anything in case of nil Selector in
MatchingLabelsSelector
, I can uselabels.Nothing
instead ofEverything
.This will fix both of our concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which could also be fixed by changing LabelSelector rather than
MatchingLabelSelector
.I don't personally mind the panic, given our default is to recover panics and this is basically incorrect usage and we don't have a way to report that, as the listOpts can not error. I am okay changing it to
labels.Nothing()
if you want to do that, but I would veto changing it tolabels.Everything()
due to potential security implications.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main issue was nil pointer panic, I am ok with nothing also.
Update the PR, PTAL.