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

refactor: make code more encapsulate and logic simple #1540

Merged

Conversation

allencloud
Copy link
Collaborator

@allencloud allencloud commented Jun 15, 2018

Signed-off-by: Allen Sun allensun.shl@alibaba-inc.com

Ⅰ. Describe what this PR did

This pull request did these things:

  1. encapsulate more code blocks into a single function to add more readability;
  2. add more information setting in SetStatusExited
  3. avoid to set status stopped in markExitedAndRelease;
  4. avoid to set status stopped in Remove action.

Ⅱ. Does this pull request fix one issue?

none

Ⅲ. Describe how you did it

none

Ⅳ. Describe how to verify it

none

Ⅴ. Special notes for reviews

none

@codecov-io
Copy link

codecov-io commented Jun 15, 2018

Codecov Report

Merging #1540 into master will increase coverage by 23.58%.
The diff coverage is 64.07%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1540       +/-   ##
===========================================
+ Coverage    17.7%   41.29%   +23.58%     
===========================================
  Files         214      257       +43     
  Lines       14367    16988     +2621     
===========================================
+ Hits         2544     7015     +4471     
+ Misses      11660     9101     -2559     
- Partials      163      872      +709
Impacted Files Coverage Δ
daemon/mgr/container_state.go 83.09% <100%> (+83.09%) ⬆️
daemon/mgr/container_types.go 76.11% <50%> (+41.19%) ⬆️
daemon/mgr/container.go 50.6% <62.76%> (+50.6%) ⬆️
cri/stream/portforward/portforward.go 0% <0%> (ø)
storage/volume/driver/driver.go 47.93% <0%> (ø)
cri/criservice.go 13.33% <0%> (ø)
cri/stream/errors.go 0% <0%> (ø)
daemon/daemon.go 56.25% <0%> (ø)
internal/generator.go 100% <0%> (ø)
storage/quota/quota.go 12.61% <0%> (ø)
... and 116 more

@allencloud
Copy link
Collaborator Author

Please help to review this pull request. @HusterWan @Letty5411
I have test this pull request with shell script:

#!/bin/sh
set -x
set -e
while true ; do
	containerName=ziren
	pouch run -d --name $containerName busybox
	pouch restart -t 1  $containerName
	pouch rm -f $containerName
	pouch ps -a
	sleep 2
done

And it works fine with no legacy container exists on the local machine. Please help to check and review this.

But there is still a log in pouchd's log:

ERRO[2018-06-15T21:14:50.426102097+08:00] failed to delete container, container id: 2ccab21e69e2437e4acbb6d374f144818c7e93e2130c930c0cf25f5d8cd4a9f1: container "2ccab21e69e2437e4acbb6d374f144818c7e93e2130c930c0cf25f5d8cd4a9f1" in namespace "default": not found

I think this is normal, since it is totally right from user's perspective.

if err != nil && !errtypes.IsNotfound(err) {
return errors.Wrapf(err, "failed to destroy container %s", c.ID)
return errors.Wrapf(err, "failed to destroy container %s when restarting", c.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

%s/restarting/remove ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated, thanks.

@Letty5411
Copy link
Contributor

LGTM

@allencloud allencloud force-pushed the refactor-container branch from 0cc66df to 743c2f4 Compare June 19, 2018 02:40
}
// Remove io and network config may occur error, so we should update
// container's status on disk as soon as possible.
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if Write failed, we can do nothing to recover, just record my confuse.

if err := m.RawError(); err != nil {
fmt.Fprintf(io.Stdout, "%v\n", err)
}
io := mgr.IOs.Get(id)
Copy link
Contributor

@HusterWan HusterWan Jun 19, 2018

Choose a reason for hiding this comment

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

change the codes below to releaseContainerIOs ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not think we could do such change. since in the middle of the function, there is a fmt.Fprintf(io.Stdout, "%v\n", err)

@allencloud allencloud force-pushed the refactor-container branch 3 times, most recently from d429700 to cb93ee2 Compare June 19, 2018 05:00
@HusterWan
Copy link
Contributor

I have no more opinion about this PR, so when the ci pass, i will merge it.

LGTM

@allencloud allencloud force-pushed the refactor-container branch 4 times, most recently from 6e2b2f5 to 91e22c3 Compare June 19, 2018 06:27
Signed-off-by: Allen Sun <allensun.shl@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants