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

Cleanup OCI runtime before storage #6229

Merged
merged 2 commits into from
May 14, 2020
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
19 changes: 11 additions & 8 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,21 +1562,24 @@ func (c *Container) cleanup(ctx context.Context) error {
lastError = errors.Wrapf(err, "error removing container %s network", c.ID())
}

// Unmount storage
if err := c.cleanupStorage(); err != nil {
// Remove the container from the runtime, if necessary.
// Do this *before* unmounting storage - some runtimes (e.g. Kata)
// apparently object to having storage removed while the container still
// exists.
if err := c.cleanupRuntime(ctx); err != nil {
if lastError != nil {
logrus.Errorf("Error unmounting container %s storage: %v", c.ID(), err)
logrus.Errorf("Error removing container %s from OCI runtime: %v", c.ID(), err)
} else {
lastError = errors.Wrapf(err, "error unmounting container %s storage", c.ID())
lastError = err
}
}

// Remove the container from the runtime, if necessary
if err := c.cleanupRuntime(ctx); err != nil {
// Unmount storage
if err := c.cleanupStorage(); err != nil {
if lastError != nil {
logrus.Errorf("Error removing container %s from OCI runtime: %v", c.ID(), err)
logrus.Errorf("Error unmounting container %s storage: %v", c.ID(), err)
} else {
lastError = err
lastError = errors.Wrapf(err, "error unmounting container %s storage", c.ID())
}
}

Expand Down
19 changes: 12 additions & 7 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,25 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
}
}

var cleanupErr error

// Clean up network namespace, cgroups, mounts.
// Do this before we set ContainerStateRemoving, to ensure that we can
// actually remove from the OCI runtime.
if err := c.cleanup(ctx); err != nil {
cleanupErr = errors.Wrapf(err, "error cleaning up container %s", c.ID())
}

// Set ContainerStateRemoving
c.state.State = define.ContainerStateRemoving

if err := c.save(); err != nil {
if cleanupErr != nil {
logrus.Errorf(err.Error())
}
return errors.Wrapf(err, "unable to set container %s removing state in database", c.ID())
}

var cleanupErr error

// Clean up network namespace, cgroups, mounts
if err := c.cleanup(ctx); err != nil {
cleanupErr = errors.Wrapf(err, "error cleaning up container %s", c.ID())
}

// Stop the container's storage
if err := c.teardownStorage(); err != nil {
if cleanupErr == nil {
Expand Down