-
Notifications
You must be signed in to change notification settings - Fork 406
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
Fix handling of 'has' selectors #473
Merged
Merged
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ var ( | |
webSelector = selector(`app=web`) | ||
notWebSelector = selector(`app!=web`) | ||
nopSelector = selector(`foo!=bark`) | ||
|
||
hasSelector = selector(`app`) | ||
notHasSelector = selector(`!app`) | ||
) | ||
|
||
const ( | ||
|
@@ -44,6 +47,11 @@ metadata: | |
# comments should be preserved | ||
app: db | ||
name: rss-db | ||
` | ||
podNoLabel = `apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: rss-site | ||
` | ||
podList = `apiVersion: v1 | ||
kind: List | ||
|
@@ -89,6 +97,21 @@ items: | |
labels: | ||
app: db | ||
name: rss-db | ||
` | ||
podListNoLabel = `apiVersion: v1 | ||
kind: List | ||
metadata: | ||
resourceVersion: "" | ||
selfLink: "" | ||
items: | ||
- apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: rss-site | ||
- apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: rss-db | ||
` | ||
) | ||
|
||
|
@@ -116,6 +139,28 @@ func TestMatchesSelector(t *testing.T) { | |
selector: nopSelector, | ||
output: dbPod, | ||
matches: true, | ||
}, { | ||
desc: "single object with has selector", | ||
input: webPod, | ||
selector: hasSelector, | ||
output: webPod, | ||
matches: true, | ||
}, { | ||
desc: "single object with not-has selector", | ||
input: webPod, | ||
selector: notHasSelector, | ||
matches: false, | ||
}, { | ||
desc: "single non-labeled object with has selector", | ||
input: podNoLabel, | ||
selector: hasSelector, | ||
matches: false, | ||
}, { | ||
desc: "single non-labeled object with not-has selector", | ||
input: podNoLabel, | ||
selector: notHasSelector, | ||
output: podNoLabel, | ||
matches: true, | ||
}, { | ||
desc: "selector matching elements of list object", | ||
input: podList, | ||
|
@@ -128,22 +173,28 @@ func TestMatchesSelector(t *testing.T) { | |
selector: notWebSelector, | ||
output: dbPodList, | ||
matches: true, | ||
}, { | ||
desc: "has selector matching no non-labeled element of list object", | ||
input: podListNoLabel, | ||
selector: hasSelector, | ||
matches: false, | ||
}, { | ||
desc: "not-has selector matching all non-labeled elements of list object", | ||
input: podListNoLabel, | ||
selector: notHasSelector, | ||
output: podListNoLabel, | ||
matches: true, | ||
}, { | ||
desc: "selector matching all elements of list object", | ||
input: podList, | ||
selector: labels.Everything(), | ||
output: podList, | ||
matches: true, | ||
}, { | ||
desc: "selector matching no elements of list object", | ||
desc: "selector matching no element of list object", | ||
input: podList, | ||
selector: labels.Nothing(), | ||
matches: false, | ||
}, { | ||
desc: "null node", | ||
input: "!!null", | ||
selector: labels.Everything(), | ||
matches: false, | ||
Comment on lines
-142
to
-146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment for the reason for this removal. |
||
}} | ||
|
||
for _, test := range tests { | ||
|
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.
The only case where
docKind()
returns an emptykind
string without error is when the node is a!!null
node.I'm not sure under what circumstances such node is passed to
MatchesSelector()
, but I had to short-circuit here becauseobjMatchesSelector()
doesn't understand what a!!null
node is.I'm happy to remove this check on
kind
and add a check for!!null
toobjMatchesSelector()
instead, in case someone feels strongly about it.