diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2018-06-04 17:31:49 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-10 11:10:11 +0000 |
commit | 1e9e530714ac0a8329dc27e38034380d81247e36 (patch) | |
tree | 6e5dd06400ca99fab4d947c3e9ec84a3559af972 /libpod/runtime_ctr.go | |
parent | cb430d58e6eb10dbac686717e822a5784f80b189 (diff) | |
download | podman-1e9e530714ac0a8329dc27e38034380d81247e36.tar.gz podman-1e9e530714ac0a8329dc27e38034380d81247e36.tar.bz2 podman-1e9e530714ac0a8329dc27e38034380d81247e36.zip |
Remove container from state before cleaning up.
Attempt to cleanup as much of the container as possible, even if one
of the cleanup stages fails.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Closes: #895
Approved by: mheon
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index bde9db764..aa49b2d51 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -238,24 +238,41 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr) } - // Clean up network namespace, cgroups, mounts - if err := c.cleanup(); err != nil { - return err - } - - // Stop the container's storage - if err := c.teardownStorage(); err != nil { - return err - } - + var cleanupErr error // Remove the container from the state if c.config.Pod != "" { if err := r.state.RemoveContainerFromPod(pod, c); err != nil { - return err + if cleanupErr == nil { + cleanupErr = err + } else { + logrus.Errorf("removing container from pod: %v", err) + } } } else { if err := r.state.RemoveContainer(c); err != nil { - return err + if cleanupErr == nil { + cleanupErr = err + } else { + logrus.Errorf("removing container: %v", err) + } + } + } + + // Clean up network namespace, cgroups, mounts + if err := c.cleanup(); err != nil { + if cleanupErr == nil { + cleanupErr = err + } else { + logrus.Errorf("cleanup network, cgroups, mounts: %v", err) + } + } + + // Stop the container's storage + if err := c.teardownStorage(); err != nil { + if cleanupErr == nil { + cleanupErr = err + } else { + logrus.Errorf("cleanup storage: %v", err) } } @@ -263,16 +280,19 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) // Only do this if we're not ContainerStateConfigured - if we are, // we haven't been created in the runtime yet if c.state.State != ContainerStateConfigured { - err = c.delete(ctx) - if err != nil { - return err + if err := c.delete(ctx); err != nil { + if cleanupErr == nil { + cleanupErr = err + } else { + logrus.Errorf("delete container: %v", err) + } } } // Set container as invalid so it can no longer be used c.valid = false - return nil + return cleanupErr } // GetContainer retrieves a container by its ID |