From 20bceb787da96741cb61e04b176fe7827c8b7070 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 17 May 2018 09:37:53 -0400 Subject: Use container cleanup() functions when removing Instead of manually calling the individual functions that cleanup uses to tear down a container's resources, just call the cleanup function to make sure that cleanup only needs to happen in one place. Signed-off-by: Matthew Heon Closes: #790 Approved by: rhatdan --- libpod/container_internal.go | 2 +- libpod/oci.go | 2 +- libpod/runtime_ctr.go | 9 ++------- libpod/runtime_pod.go | 4 ++-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index b1420aa55..39a665bb1 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -765,7 +765,7 @@ func (c *Container) cleanupCgroups() error { func (c *Container) cleanupNetwork() error { // Stop the container's network namespace (if it has one) if err := c.runtime.teardownNetNS(c); err != nil { - logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err) + logrus.Errorf("unable to cleanup network for container %s: %q", c.ID(), err) } c.state.NetNS = nil diff --git a/libpod/oci.go b/libpod/oci.go index 4dbf5526d..22519acbd 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -465,7 +465,7 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container) error { } statusCode, err := strconv.Atoi(string(statusCodeStr)) if err != nil { - return errors.Wrapf(err, "error convertaing exit status code for container %s to int", + return errors.Wrapf(err, "error converting exit status code for container %s to int", ctr.ID()) } ctr.state.ExitCode = int32(statusCode) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 981f745b4..0f992822a 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -219,13 +219,8 @@ func (r *Runtime) removeContainer(c *Container, force bool) error { return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr) } - // Tear down the container's cgroups (if they exist) - if err := c.cleanupCgroups(); err != nil { - return err - } - - // Stop the container's network namespace (if it has one) - if err := r.teardownNetNS(c); err != nil { + // Clean up network namespace, cgroups, mounts + if err := c.cleanup(); err != nil { return err } diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go index 44910b180..257b980a2 100644 --- a/libpod/runtime_pod.go +++ b/libpod/runtime_pod.go @@ -160,8 +160,8 @@ func (r *Runtime) RemovePod(p *Pod, removeCtrs, force bool) error { // We can remove containers even if they have dependencies now // As we have guaranteed their dependencies are in the pod for _, ctr := range ctrs { - // Stop network NS - if err := r.teardownNetNS(ctr); err != nil { + // Clean up network namespace, cgroups, mounts + if err := ctr.cleanup(); err != nil { return err } -- cgit v1.2.3-54-g00ecf