-
Notifications
You must be signed in to change notification settings - Fork 947
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: pull should return 404 when image not exists #2914
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2914 +/- ##
==========================================
- Coverage 68.23% 68.14% -0.09%
==========================================
Files 291 291
Lines 18328 18337 +9
==========================================
- Hits 12506 12496 -10
- Misses 4368 4377 +9
- Partials 1454 1464 +10
|
PTAL @fuweid thanks a lot. |
@@ -58,7 +58,7 @@ func (s *Server) pullImage(ctx context.Context, rw http.ResponseWriter, req *htt | |||
// Error information has be sent to client, so no need call resp.Write | |||
if err := s.ImageMgr.PullImage(ctx, image, &authConfig, newWriteFlusher(rw)); err != nil { | |||
logrus.Errorf("failed to pull image %s: %v", image, err) | |||
return nil | |||
return err |
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.
well. if we write something into response, the http code will be 200 which can never be changed.
so we use jsonstream to return error. the client needs to parse the json stream to get error.
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.
when you pull the No. 5 layer and get something wrong like connection refuse, your change is not helpful. it always be 200, not 500
test/api_image_create_test.go
Outdated
|
||
resp, err := request.Post("/images/create", query) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 500) |
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.
we need to parse the json stream here
@fuweid PTAL |
40d3ec2
to
77c60f6
Compare
test/api_image_create_test.go
Outdated
|
||
resp, err := request.Post("/images/create", query) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 500) |
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.
is it 400? not 500?
if err != nil { | ||
return nil, fmt.Errorf("failed to get a containerd grpc client: %v", err) | ||
return nil, "", err |
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.
I think we should check the status and make sure that it is 404
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.
when resolveImage return err, means that it can't find available ref to use.
5501241
to
93c4e50
Compare
@@ -166,7 +165,8 @@ func (c *Client) getResolver(ctx context.Context, authConfig *types.AuthConfig, | |||
} | |||
|
|||
if availableRef == "" { | |||
return nil, "", fmt.Errorf("there is no available image reference after trying %+q", refs) | |||
logrus.Errorf("there is no available image reference after trying %+q", refs) | |||
return nil, "", errtypes.ErrNotfound |
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.
prefer errors.Wrapf(errtypes.ErrNotfound, "there is no available image reference after trying %+q", refs)
here
util function just directly return error, log or not should be decided by upper.
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.
I change to logrus.warnf
, add an another log in upperand. But I think errtypes.ErrNotfound
is enough here, user didn't care about how you find a available ref, just tell them not found.
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.
make sense
could you show me the UX when pulling a not-exist image? What is the error message display in terminal after doing |
|
1b9816f
to
5299cfa
Compare
failed test try to pull |
Signed-off-by: zhangyue <zy675793960@yeah.net>
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: zhangyue zy675793960@yeah.net
Ⅰ. Describe what this PR did
fix bugs in #2913, when error happens, we should not write anything to Writer, if you write anything, then we will get resp code 200.
In this pr, add a
resolveImage
interface to check the ref is exists or not, if not, will return err.Ⅱ. Does this pull request fix one issue?
fix bugs in #2913
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
takes on #2913
Ⅳ. Describe how to verify it
wait for CI
Ⅴ. Special notes for reviews
when image pull No.5 layer error, the error msg still in json stream, this pr doesn't handle this case.