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 non-exist image in container create #1764

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (cc *CreateCommand) runCreate(args []string) error {

ctx := context.Background()
apiClient := cc.cli.Client()
if err := pullMissingImage(ctx, apiClient, config.Image, false); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This functionality is just implemented in the CLI side, not the API server side?
I am wondering if this is reasonable? @Ace-Tang @fuweid
Just double check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The best will be done in api server, hope someone can do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

@allencloud @Ace-Tang I don't think it should be done in the API server, because we don't know the client want to pull the missing image and it will make the API heavy. Currently, the Pull API allows the caller to do the customize like pullMissingImage. It's good enough, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you said, @fuweid , one api just do one thing, seems make sense.

return err
}

result, err := apiClient.ContainerCreate(ctx, config.ContainerConfig, config.HostConfig, config.NetworkingConfig, containerName)
if err != nil {
return fmt.Errorf("failed to create container: %v", err)
Expand Down
9 changes: 9 additions & 0 deletions test/cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,12 @@ func (suite *PouchRunSuite) TestCreateWithPidsLimit(c *check.C) {
pl := result[0].HostConfig.PidsLimit
c.Assert(int(pl), check.Equals, 10)
}

// TestCreateWithNonExistImage tests running container with image not exist.
func (suite *PouchRunSuite) TestCreateWithNonExistImage(c *check.C) {
cname := "TestCreateWithNonExistImage"
// we should use a non-used image, since containerd not remove image immediately.
image := "docker.io/library/alpine"
res := command.PouchRun("create", cname, image)
res.Assert(c, icmd.Success)
}