summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-08 13:35:43 -0500
committerGitHub <noreply@github.com>2018-02-08 13:35:43 -0500
commit5529143877778ef8bcdd05179e279bb7d662b431 (patch)
tree6f95d2a9c3832b1e00f04d30045d11f0fb37425f
parent2a58bdc89d5646de62b358622275a25a8bb09a3f (diff)
parent3921f10a729054c23296f392b0f271c1ac5e5770 (diff)
downloadpodman-5529143877778ef8bcdd05179e279bb7d662b431.tar.gz
podman-5529143877778ef8bcdd05179e279bb7d662b431.tar.bz2
podman-5529143877778ef8bcdd05179e279bb7d662b431.zip
Merge pull request #302 from rhatdan/cleanup
cleanup network stack as well as storage when container shuts down.
-rw-r--r--cmd/podman/run.go2
-rw-r--r--cmd/podman/start.go4
-rw-r--r--libpod/container_api.go11
-rw-r--r--libpod/container_internal.go13
4 files changed, 27 insertions, 3 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 97f60cdbf..2f3468fd2 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -145,5 +145,5 @@ func runCmd(c *cli.Context) error {
if createConfig.Rm {
return runtime.RemoveContainer(ctr, true)
}
- return ctr.CleanupStorage()
+ return ctr.Cleanup()
}
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 0dad5e237..18e8f7766 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -138,6 +138,10 @@ func startCmd(c *cli.Context) error {
} else {
exitCode = int(ecode)
}
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = ctr.Cleanup()
}
return lastError
}
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 3693ab78b..72df60eb8 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -694,8 +694,9 @@ func (c *Container) Wait() (int32, error) {
return exitCode, nil
}
-// CleanupStorage unmounts all mount points in container and cleans up container storage
-func (c *Container) CleanupStorage() error {
+// Cleanup unmounts all mount points in container and cleans up container storage
+// It also cleans up the network stack
+func (c *Container) Cleanup() error {
if !c.locked {
c.lock.Lock()
defer c.lock.Unlock()
@@ -703,6 +704,12 @@ func (c *Container) CleanupStorage() error {
return err
}
}
+
+ // Stop the container's network namespace (if it has one)
+ if err := c.cleanupNetwork(); err != nil {
+ logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
+ }
+
return c.cleanupStorage()
}
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 77e456fe1..d434630a3 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -365,6 +365,19 @@ func (c *Container) mountStorage() (err error) {
return c.save()
}
+// cleanupNetwork unmounts and cleans up the container's network
+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)
+ }
+
+ c.state.NetNS = nil
+ c.state.SubnetMask = ""
+ c.state.IPAddress = ""
+ return c.save()
+}
+
// cleanupStorage unmounts and cleans up the container's root filesystem
func (c *Container) cleanupStorage() error {
if !c.state.Mounted {