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

bugfix: pull image before run and upgrade #1419

Merged
merged 2 commits into from
May 29, 2018

Conversation

wrfly
Copy link
Contributor

@wrfly wrfly commented May 26, 2018

fix #1379

and remove the duplicate image tag in logs

@pouchrobot pouchrobot added kind/bug This is bug report for project size/L labels May 26, 2018
@pouchrobot
Copy link
Collaborator

We found this is your first time to contribute to Pouch, @wrfly
👏 We really appreciate it.
Just remind that you have read the contribution guide: https://github.com/alibaba/pouch/blob/master/CONTRIBUTING.md
If you didn't, you should do that first. If done, welcome again and please enjoy hacking! 🍻

@codecov-io
Copy link

codecov-io commented May 26, 2018

Codecov Report

Merging #1419 into master will decrease coverage by 5.05%.
The diff coverage is 3.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1419      +/-   ##
==========================================
- Coverage   38.77%   33.71%   -5.06%     
==========================================
  Files         250      254       +4     
  Lines       16629    18759    +2130     
==========================================
- Hits         6448     6325     -123     
- Misses       9355    11610    +2255     
+ Partials      826      824       -2
Impacted Files Coverage Δ
client/request.go 57.14% <0%> (-1.4%) ⬇️
cli/pull.go 0% <0%> (ø) ⬆️
cli/run.go 0% <0%> (ø) ⬆️
cli/upgrade.go 0% <0%> (ø) ⬆️
apis/server/image_bridge.go 72.46% <100%> (ø) ⬆️
cri/v1alpha1/cri_utils.go 0% <0%> (-29.32%) ⬇️
cri/v1alpha2/cri_utils.go 0% <0%> (-28.42%) ⬇️
ctrd/image.go 59.64% <0%> (-25.63%) ⬇️
ctrd/watch.go 53.33% <0%> (-24.8%) ⬇️
daemon/mgr/image.go 49.67% <0%> (-19.42%) ⬇️
... and 19 more

cli/pull.go Outdated
}
namedRef = reference.TrimTagForDigest(reference.WithDefaultTagIfMissing(namedRef))

// the error comes from daemon/mgr/image_store.go
Copy link
Contributor

@fuweid fuweid May 28, 2018

Choose a reason for hiding this comment

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

Hi, @wrfly , I think we can use assert to check the error is RespError or not. If the statusCode is 404, we can continue to pull the image. It seems that it's better than using string match. WDYT?

BTW, we cannot use the errtypes to check the error is notFound or other type since this error comes from the http or rpc call, which has been marshaled and unmarshaled during the network. But we have the code for the status error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, assert is better, I just use it in testing before. I'll change it later.

Copy link
Contributor Author

@wrfly wrfly May 28, 2018

Choose a reason for hiding this comment

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

但是返回的 inspectError 就是一个单纯的error呀,没有 statusCode, CommonAPIClient 把 resp.StatusCode 吃掉了

// ImageInspect requests daemon to inspect an image.
func (client *APIClient) ImageInspect(ctx context.Context, name string) (types.ImageInfo, error) {
	image := types.ImageInfo{}

	resp, err := client.get(ctx, "/images/"+name+"/json", nil, nil)
	if err != nil {
		return image, err
	}

	defer ensureCloseReader(resp)
	err = decodeBody(&image, resp.Body)
	return image, err
}

所以现在的想法是用assert来判断返回的error里面有没有 not found 字样(很ugly)

然后,不明白调用APIClient的时候返回的是 {"message": "xxxxxx"} 这样的一种error形式, 也许可以用 {"code": xxx, "message": "xxx"},不然一个单纯的 error 只能用字符串匹配了。。

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @wrfly , please check the client.get method and it will return RespError.

you can use the following statement to check the error:

if eErr, ok := err.(client.RespError); ok {
     // we need to add StatusCode method. 
     if e.Err.StatusCode() != 404 {
     }
}

Does it make senses to you?

@wrfly please try to use English. :) Try your best

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, understood.

I thought it's ugly to convert errors around at first, but I saw moby use it too. It's my problem that I haven't see this usage before.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. So please update your code 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

cli/pull.go Outdated
}
}

namedRef, err := reference.Parse(image)
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 can put the parse job after the inspect call. The error check doesn't need to involve the reference check if we use the status code to check error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't understand you. 可以用中文的😂

Copy link
Contributor

Choose a reason for hiding this comment

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

I means the put the reference.Parse statement after the 404 check.

wrfly added 2 commits May 28, 2018 22:53
Signed-off-by: wrfly <mr.wrfly@gmail.com>
@fuweid
Copy link
Contributor

fuweid commented May 29, 2018

LGTM @wrfly great job. 👍

@fuweid
Copy link
Contributor

fuweid commented May 29, 2018

@wrfly Could you please to rebase your commits into one commit? Thanks

@allencloud
Copy link
Collaborator

Actually I think we could help to squash this when merging. @fuweid
Although this may be a little bit not user-friendly.

@allencloud allencloud merged commit 62055bb into AliyunContainerService:master May 29, 2018
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/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[question] It seems that pouch won't pull the image automatically when run a container?
5 participants