From 2c7f97d5a782d35efc195baf7a7ca9016ca05409 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Sun, 23 Sep 2018 18:04:29 -0400 Subject: Add ContainerStateExited and OCI delete() in cleanup() To work better with Kata containers, we need to delete() from the OCI runtime as a part of cleanup, to ensure resources aren't retained longer than they need to be. To enable this, we need to add a new state to containers, ContainerStateExited. Containers transition from ContainerStateStopped to ContainerStateExited via cleanupRuntime which is invoked as part of cleanup(). A container in the Exited state is identical to Stopped, except it has been removed from the OCI runtime and thus will be handled differently when initializing the container. Signed-off-by: Matthew Heon --- libpod/runtime_ctr.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libpod/runtime_ctr.go') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 6c487e367..b8a8b6c20 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -311,7 +311,7 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) c.valid = false // Clean up network namespace, cgroups, mounts - if err := c.cleanup(); err != nil { + if err := c.cleanup(ctx); err != nil { if cleanupErr == nil { cleanupErr = err } else { @@ -335,7 +335,8 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) // Delete the container // 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 { + if c.state.State != ContainerStateConfigured && + c.state.State != ContainerStateExited { if err := c.delete(ctx); err != nil { if cleanupErr == nil { cleanupErr = err -- cgit v1.2.3-54-g00ecf From 29dbab64407d11f314b894c37deb4419faeefc56 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 24 Sep 2018 09:53:08 -0400 Subject: Address review comments and fix ps output Signed-off-by: Matthew Heon --- cmd/podman/ps.go | 2 ++ libpod/runtime_ctr.go | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'libpod/runtime_ctr.go') diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index d36c929e8..e53afe1bf 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -548,6 +548,8 @@ func getTemplateOutput(psParams []psJSONParams, opts shared.PsOptions) ([]psTemp labels := formatLabels(psParam.Labels) switch psParam.Status { + case libpod.ContainerStateExited.String(): + fallthrough case libpod.ContainerStateStopped.String(): exitedSince := units.HumanDuration(time.Since(psParam.ExitedAt)) status = fmt.Sprintf("Exited (%d) %s ago", psParam.ExitCode, exitedSince) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index b8a8b6c20..0fe896e5f 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -332,9 +332,9 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) label.ReleaseLabel(c.ProcessLabel()) r.reserveLabels() } - // Delete the container - // Only do this if we're not ContainerStateConfigured - if we are, - // we haven't been created in the runtime yet + // Delete the container. + // Not needed in Configured and Exited states, where the container + // doesn't exist in the runtime if c.state.State != ContainerStateConfigured && c.state.State != ContainerStateExited { if err := c.delete(ctx); err != nil { -- cgit v1.2.3-54-g00ecf From 39d7c869ea9291352e836f3c170d9bd801f9c35c Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 2 Oct 2018 12:07:23 -0400 Subject: Fix bug with exited state and container remove Signed-off-by: Matthew Heon --- libpod/runtime_ctr.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libpod/runtime_ctr.go') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 0fe896e5f..4256a84a0 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -262,7 +262,8 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool) } } else if !(c.state.State == ContainerStateConfigured || c.state.State == ContainerStateCreated || - c.state.State == ContainerStateStopped) { + c.state.State == ContainerStateStopped || + c.state.State == ContainerStateExited) { return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is %s - running or paused containers cannot be removed", c.ID(), c.state.State.String()) } -- cgit v1.2.3-54-g00ecf