-
Notifications
You must be signed in to change notification settings - Fork 949
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
bugfix: only list container stats which are created by cri #2273
Merged
fuweid
merged 1 commit into
AliyunContainerService:master
from
YaoZengzeng:filter-stats
Sep 30, 2018
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package utils | ||
|
||
// Move the public utility methods which are used by both v1alpha1 | ||
// and v1alpha2 here to reduce the code duplication. | ||
|
||
// MatchLabelSelector returns true if labels cover selector. | ||
func MatchLabelSelector(selector, labels map[string]string) bool { | ||
for k, v := range selector { | ||
if val, ok := labels[k]; ok { | ||
if v != val { | ||
return false | ||
} | ||
} else { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_MatchLabelSelector(t *testing.T) { | ||
type args struct { | ||
selector map[string]string | ||
labels map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "Normal Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Uncovered Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Unmatched Test", | ||
args: args{ | ||
selector: map[string]string{ | ||
"a1": "b0", | ||
"a2": "b2", | ||
}, | ||
labels: map[string]string{ | ||
"a1": "b1", | ||
"a2": "b2", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := MatchLabelSelector(tt.args.selector, tt.args.labels); got != tt.want { | ||
t.Errorf("matchLabelSelector() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
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.
Maybe add a blank here to distinguish between filtering created by CRI Manager and filtering by request and it's beeter to write comments. WDTY?
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.
Updated