Skip to content
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

Merged
merged 1 commit into from
Jun 27, 2019

Conversation

ZYecho
Copy link
Contributor

@ZYecho ZYecho commented Jun 18, 2019

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.

@pouchrobot pouchrobot added kind/bug This is bug report for project size/S labels Jun 18, 2019
@codecov
Copy link

codecov bot commented Jun 18, 2019

Codecov Report

Merging #2914 into master will decrease coverage by 0.08%.
The diff coverage is 85%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#criv1alpha2_test 34.79% <45%> (-0.04%) ⬇️
#integration_test_0 35.92% <85%> (-0.15%) ⬇️
#integration_test_1 35.57% <45%> (+0.07%) ⬆️
#integration_test_2 35.95% <45%> (-0.08%) ⬇️
#integration_test_3 35.61% <85%> (-0.03%) ⬇️
#node_e2e_test 34.15% <75%> (-0.21%) ⬇️
#unittest 27.97% <0%> (-0.02%) ⬇️
Impacted Files Coverage Δ
ctrd/utils.go 76.12% <100%> (+0.15%) ⬆️
daemon/mgr/image.go 58.83% <100%> (-2.54%) ⬇️
apis/server/image_bridge.go 78.03% <66.66%> (-0.44%) ⬇️
ctrd/image.go 67.76% <80%> (+0.23%) ⬆️
cri/ocicni/netns.go 58.1% <0%> (-2.71%) ⬇️
ctrd/container.go 51.62% <0%> (-2.68%) ⬇️
cri/ocicni/cni_manager.go 61.32% <0%> (-0.95%) ⬇️
cri/v1alpha2/cri.go 63.53% <0%> (-0.51%) ⬇️
daemon/mgr/container.go 59.93% <0%> (-0.42%) ⬇️
... and 5 more

@allencloud
Copy link
Collaborator

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
Copy link
Contributor

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.

Copy link
Contributor

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


resp, err := request.Post("/images/create", query)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
Copy link
Contributor

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

@pouchrobot pouchrobot added size/M and removed size/S labels Jun 19, 2019
@ZYecho ZYecho changed the title fix: pull should return err and not write msg fix: pull should return 500 when image not exists Jun 19, 2019
@ZYecho
Copy link
Contributor Author

ZYecho commented Jun 19, 2019

@fuweid PTAL

@ZYecho ZYecho force-pushed the fix-pull-resp branch 2 times, most recently from 40d3ec2 to 77c60f6 Compare June 20, 2019 01:08

resp, err := request.Post("/images/create", query)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

@ZYecho ZYecho changed the title fix: pull should return 500 when image not exists fix: pull should return 404 when image not exists Jun 20, 2019
@ZYecho ZYecho force-pushed the fix-pull-resp branch 2 times, most recently from 5501241 to 93c4e50 Compare June 20, 2019 08:50
cri/v1alpha2/cri.go Outdated Show resolved Hide resolved
cri/v1alpha2/cri_utils.go Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

@zhuangqh
Copy link
Contributor

zhuangqh commented Jun 20, 2019

could you show me the UX when pulling a not-exist image? What is the error message display in terminal after doing pouch pull xxx. I am afraid some internal test would fail

@ZYecho
Copy link
Contributor Author

ZYecho commented Jun 20, 2019

could you show me the UX when pulling a not-exist image? What is the error message display in terminal after doing pouch pull xxx. I am afraid some internal test would fail

sudo pouch pull fsadfsdafsdaf:fsdfdsaf
Error: failed to pull image: {"message":"not found"}


@ZYecho ZYecho force-pushed the fix-pull-resp branch 2 times, most recently from 1b9816f to 5299cfa Compare June 21, 2019 01:32
@ZYecho
Copy link
Contributor Author

ZYecho commented Jun 22, 2019

failed test try to pull reg.docker.alibaba-inc.com/base/hello-world, I try to pull it use docker, also didn't download it, seems it was an inner registry?

Signed-off-by: zhangyue <zy675793960@yeah.net>
Copy link
Contributor

@zhuangqh zhuangqh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants