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: container cannot start after first start failed #1190

Merged
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
44 changes: 20 additions & 24 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,39 +657,35 @@ func (mgr *ContainerManager) createContainerdContainer(ctx context.Context, c *C
s.Process.Terminal = true
}

err = mgr.Client.CreateContainer(ctx, &ctrd.Container{
if err := mgr.Client.CreateContainer(ctx, &ctrd.Container{
ID: c.ID(),
Image: c.Image(),
Runtime: c.meta.HostConfig.Runtime,
Spec: s,
IO: io,
})
if err == nil {
c.meta.State.Status = types.StatusRunning
c.meta.State.StartedAt = time.Now().UTC().Format(utils.TimeLayout)
pid, err := mgr.Client.ContainerPID(ctx, c.ID())
if err != nil {
return errors.Wrapf(err, "failed to get PID of container: %s", c.ID())
}
c.meta.State.Pid = int64(pid)
c.meta.State.ExitCode = 0
}); err != nil {
logrus.Errorf("failed to create new containerd container: %s", err.Error())

// set Snapshot MergedDir
c.meta.Snapshotter.Data["MergedDir"] = c.meta.BaseFS
} else {
c.meta.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
c.meta.State.Error = err.Error()
c.meta.State.Pid = 0
//TODO: make exit code more correct.
c.meta.State.ExitCode = 127
// TODO(ziren): markStoppedAndRelease may failed
// we should clean resources of container when start failed
_ = mgr.markStoppedAndRelease(c, nil)
return err
}

// release io
io.Close()
mgr.IOs.Remove(c.ID())
// Create containerd container success.
c.meta.State.Status = types.StatusRunning
c.meta.State.StartedAt = time.Now().UTC().Format(utils.TimeLayout)
pid, err := mgr.Client.ContainerPID(ctx, c.ID())
if err != nil {
return errors.Wrapf(err, "failed to get PID of container %s", c.ID())
}
c.meta.State.Pid = int64(pid)
c.meta.State.ExitCode = 0

c.Write(mgr.Store)
return err
// set Snapshot MergedDir
c.meta.Snapshotter.Data["MergedDir"] = c.meta.BaseFS

return c.Write(mgr.Store)
}

// Stop stops a running container.
Expand Down
3 changes: 2 additions & 1 deletion docs/kubernetes/pouch_with_kubernetes_deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ An all-in-one kubernetes cluster with pouch runtime could be deployed by running
hack/kubernetes/allinone.sh

```
Please refer to https://github.com/alibaba/pouch/blob/master/hack/kubernetes/allinone.sh .

Please refer to [allinone](https://github.com/alibaba/pouch/blob/master/hack/kubernetes/allinone.sh) .

### Install Pouch

Expand Down