-
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
feature: support images filter flag #2410
feature: support images filter flag #2410
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2410 +/- ##
=========================================
Coverage ? 68.91%
=========================================
Files ? 276
Lines ? 18287
Branches ? 0
=========================================
Hits ? 12602
Misses ? 4255
Partials ? 1430
|
CI fails with code check. Please take a look. @ZYecho Thanks. |
9487210
to
29c8c67
Compare
@allencloud fixed it, also cc @Ace-Tang @fuweid request for review. |
apis/filters/parse.go
Outdated
@@ -150,3 +157,33 @@ func FromParam(p string) (Args, error) { | |||
} | |||
return args, nil | |||
} | |||
|
|||
//FromFilterOpts parse key=value to Args string from cli opts |
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 we can add some test cases for this new function, WDYT ? @ZYecho
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.
good idea, I add a testcase to cover this.
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 we add space between //
and FromFilterOpts
?
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.
done
f3bc3fe
to
39e74c0
Compare
apis/filters/parse.go
Outdated
func (args Args) Validate(accepted map[string]bool) error { | ||
for name := range args.fields { | ||
if !accepted[name] { | ||
return errors.New("Invalid filter " + name) |
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 we avoid to start with a capital letter in the error string? The reason is here https://github.com/golang/go/wiki/Errors#errors
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 add accepted filter name ? make user more clearly
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 add accepted filter name ? make user more clearly
Is there a need to do here? I find that other validate func in pouch also not do this, maybe We can do this by adding docs or cli usage? wdyt? @Ace-Tang
apis/filters/parse.go
Outdated
@@ -150,3 +157,33 @@ func FromParam(p string) (Args, error) { | |||
} | |||
return args, nil | |||
} | |||
|
|||
//FromFilterOpts parse key=value to Args string from cli opts |
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 we add space between //
and FromFilterOpts
?
apis/filters/parse.go
Outdated
return nil | ||
} | ||
|
||
//FamiliarMatch decide the ref match the pattern or not |
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 we add space between //
and FromFilterOpts
?
daemon/mgr/image.go
Outdated
beforeImages := filter.Get("before") | ||
if len(beforeImages) > 0 { | ||
// use the last one if multi before images was assigned | ||
beforeFilter, err = mgr.GetImage(ctx, beforeImages[len(beforeImages)-1]) |
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.
how can we make the beforeImages
is sorted?
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.
To be honest, I'm curious about the logic dealing with multi-since or multi-before, I think we can not guess the user want to the first one or the last one, use the last input or throw err if multi-since or multi-before? wdyt? @fuweid
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.
so, could we limit the multi-since/multi-before here? Since there is no reason for this requirement.
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.
@fuweid I test the same scenario in moby, have the same problem. I think the single-since/since-before is reasonable, while multi is undefined. So in here, I want to throw err if len > 1, 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.
agree
daemon/mgr/image.go
Outdated
if filter.Contains("reference") { | ||
var found bool | ||
for _, ref := range mgr.localStore.GetReferences(img.ID) { | ||
for _, pattern := range filter.Get("reference") { |
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 we retrieve filter.Get("reference")
before? I think the Get
will allocate new memory each loop.
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.
seems much condition here
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.
what is the condition?
apis/filters/parse.go
Outdated
func (args Args) Validate(accepted map[string]bool) error { | ||
for name := range args.fields { | ||
if !accepted[name] { | ||
return errors.New("Invalid filter " + name) |
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 add accepted filter name ? make user more clearly
daemon/mgr/image.go
Outdated
if filter.Contains("reference") { | ||
var found bool | ||
for _, ref := range mgr.localStore.GetReferences(img.ID) { | ||
for _, pattern := range filter.Get("reference") { |
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.
seems much condition here
2139681
to
d9027ce
Compare
test/cli_images_test.go
Outdated
|
||
//Test invalid filter | ||
invalidRes := command.PouchRun("images", "-f", "after="+busyboxImage) | ||
c.Assert(invalidRes.Stderr(), check.Equals, "Error: failed to get image list: {\"message\":\"Invalid filter after\"}\n\n") |
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 case is failed
/home/travis/gopath/src/github.com/alibaba/pouch/test/cli_images_test.go:114:
c.Assert(invalidRes.Stderr(), check.Equals, "Error: failed to get image list: {\"message\":\"Invalid filter after\"}\n\n")
... obtained string = "" +
... "Error: failed to get image list: {\"message\":\"invalid filter after\"}\n" +
... "\n"
... expected string = "" +
... "Error: failed to get image list: {\"message\":\"Invalid filter after\"}\n" +
... "\n"
I was thinking that we can do this in api level test and only check the status. The message is out of control.
But the status should be stable. 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.
agree, update it later.
55b6f30
to
a636407
Compare
@fuweid all mentioned have fixed. PTAL, thanks. |
daemon/mgr/image.go
Outdated
|
||
// refuse undefined behavior | ||
if len(beforeImages) > 1 || len(sinceImages) > 1 { | ||
return nil, pkgerrors.Wrapf(errtypes.ErrInvalidParam, "can't use since or before filter more than one") |
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 we split the error into two part? I think it can make the error more clear.
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.
done.
test/api_image_list_test.go
Outdated
c.Assert(reflect.DeepEqual(got[0].RepoTags, []string{repoTag}), check.Equals, true) | ||
c.Assert(reflect.DeepEqual(got[0].RepoDigests, []string{repoDigest}), check.Equals, true) | ||
|
||
// check invalid filter |
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 we split it into other test case function? I think it is too long.
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.
done.
a636407
to
3411c45
Compare
client/image_list_test.go
Outdated
@@ -12,14 +12,15 @@ import ( | |||
|
|||
"github.com/alibaba/pouch/apis/types" | |||
|
|||
"github.com/alibaba/pouch/apis/filters" |
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.
put this line in the second part, thanks @ZYecho
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.
thanks, update.
Signed-off-by: zhangyue <[email protected]>
3411c45
to
3248c28
Compare
lgtm |
LGTM, thanks for your works @ZYecho |
Signed-off-by: zhangyue [email protected]
Ⅰ. Describe what this PR did
add filter flag support for
pouch images
, support three filters: since/before/referenceⅡ. Does this pull request fix one issue?
Related to #2405
fix #2371
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
add api testcase and cli testcase.
Ⅳ. Describe how to verify it
pouch images
pouch images -f reference=registry.hub.docker.com/library/busybox:*
pouch images -f after=registry.hub.docker.com/library/busybox:1.28
Got
Error: failed to get image list: {"message":"Invalid filter after"}
pouch images -f before=registry.hub.docker.com/library/hello-world:linux
Ⅴ. Special notes for reviews
Use the same filter package as
pouch events