-
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
bugfix: only list container stats which are created by cri #2273
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2273 +/- ##
==========================================
+ Coverage 66.82% 66.82% +<.01%
==========================================
Files 208 209 +1
Lines 16937 16963 +26
==========================================
+ Hits 11318 11336 +18
- Misses 4262 4268 +6
- Partials 1357 1359 +2
|
cri/v1alpha1/cri.go
Outdated
@@ -822,7 +822,7 @@ func (c *CriManager) ContainerStats(ctx context.Context, r *runtime.ContainerSta | |||
func (c *CriManager) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (*runtime.ListContainerStatsResponse, error) { | |||
opts := &mgr.ContainerListOption{All: true} | |||
filter := func(c *mgr.Container) bool { | |||
return true | |||
return c.Config.Labels[containerTypeLabelKey] == containerTypeLabelContainer |
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.
only check labels here?
aac0a06
to
e394e13
Compare
805664c
to
3372df1
Compare
@@ -822,6 +822,19 @@ func (c *CriManager) ContainerStats(ctx context.Context, r *runtime.ContainerSta | |||
func (c *CriManager) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (*runtime.ListContainerStatsResponse, error) { | |||
opts := &mgr.ContainerListOption{All: true} | |||
filter := func(c *mgr.Container) bool { | |||
if c.Config.Labels[containerTypeLabelKey] != containerTypeLabelContainer { | |||
return false | |||
} |
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
cri/v1alpha2/cri_utils.go
Outdated
@@ -814,6 +814,20 @@ func filterCRIContainers(containers []*runtime.Container, filter *runtime.Contai | |||
return filtered | |||
} | |||
|
|||
// matchLabelSelector returns true if labels cover selector. | |||
func matchLabelSelector(selector, labels map[string]string) bool { |
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 function is uncoupled with runtime
, maybe create a directory like utils
under the cri directory for more public utility methods and move this funtion over. WDYT?
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.
Yes, we could do it in another PR and move all the public utility methods to there.
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.
@YaoZengzeng please put it in this PR. 😄 can you do this?
0baaf7b
to
d1262fc
Compare
76dbb51
to
b85861a
Compare
Signed-off-by: YaoZengzeng <[email protected]>
b85861a
to
ee3640c
Compare
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.
LGTM
Signed-off-by: YaoZengzeng [email protected]
Ⅰ. Describe what this PR did
When CRI manager list container stats, filter the container which is not created by CRI.
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
No
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews