Cleanup OCI runtime before storage

Some runtimes (e.g. Kata containers) seem to object to having us
unmount storage before the container is removed from the runtime.
This is an easy fix (change the order of operations in cleanup)
and seems to make more sense than the way we were doing things.

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2020-05-14 09:39:41 -04:00
parent 3c58e4fc76
commit 83a1e2e5d2
1 changed files with 12 additions and 9 deletions

View File

@ -1562,6 +1562,18 @@ func (c *Container) cleanup(ctx context.Context) error {
lastError = errors.Wrapf(err, "error removing container %s network", c.ID())
}
// 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 removing container %s from OCI runtime: %v", c.ID(), err)
} else {
lastError = err
}
}
// Unmount storage
if err := c.cleanupStorage(); err != nil {
if lastError != nil {
@ -1571,15 +1583,6 @@ func (c *Container) cleanup(ctx context.Context) error {
}
}
// Remove the container from the runtime, if necessary
if err := c.cleanupRuntime(ctx); err != nil {
if lastError != nil {
logrus.Errorf("Error removing container %s from OCI runtime: %v", c.ID(), err)
} else {
lastError = err
}
}
return lastError
}