Skip to content

Commit 20bceb7

Browse files
mheonrh-atomic-bot
authored andcommitted
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 <[email protected]> Closes: #790 Approved by: rhatdan
1 parent 92a9f3a commit 20bceb7

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

libpod/container_internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ func (c *Container) cleanupCgroups() error {
765765
func (c *Container) cleanupNetwork() error {
766766
// Stop the container's network namespace (if it has one)
767767
if err := c.runtime.teardownNetNS(c); err != nil {
768-
logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
768+
logrus.Errorf("unable to cleanup network for container %s: %q", c.ID(), err)
769769
}
770770

771771
c.state.NetNS = nil

libpod/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
465465
}
466466
statusCode, err := strconv.Atoi(string(statusCodeStr))
467467
if err != nil {
468-
return errors.Wrapf(err, "error convertaing exit status code for container %s to int",
468+
return errors.Wrapf(err, "error converting exit status code for container %s to int",
469469
ctr.ID())
470470
}
471471
ctr.state.ExitCode = int32(statusCode)

libpod/runtime_ctr.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,8 @@ func (r *Runtime) removeContainer(c *Container, force bool) error {
219219
return errors.Wrapf(ErrCtrExists, "container %s has dependent containers which must be removed before it: %s", c.ID(), depsStr)
220220
}
221221

222-
// Tear down the container's cgroups (if they exist)
223-
if err := c.cleanupCgroups(); err != nil {
224-
return err
225-
}
226-
227-
// Stop the container's network namespace (if it has one)
228-
if err := r.teardownNetNS(c); err != nil {
222+
// Clean up network namespace, cgroups, mounts
223+
if err := c.cleanup(); err != nil {
229224
return err
230225
}
231226

libpod/runtime_pod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ func (r *Runtime) RemovePod(p *Pod, removeCtrs, force bool) error {
160160
// We can remove containers even if they have dependencies now
161161
// As we have guaranteed their dependencies are in the pod
162162
for _, ctr := range ctrs {
163-
// Stop network NS
164-
if err := r.teardownNetNS(ctr); err != nil {
163+
// Clean up network namespace, cgroups, mounts
164+
if err := ctr.cleanup(); err != nil {
165165
return err
166166
}
167167

0 commit comments

Comments
 (0)