diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-10-20 13:20:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 13:20:12 +0000 |
commit | eba281c3e0e69533427d3eb5c66c60b5ca038c1b (patch) | |
tree | 5a12ebc1a7c40f8967f1225b2ec730ea29d8f433 | |
parent | 97f051f65769fed32b3c497b3f484667400c66a9 (diff) | |
parent | 4f7a431daf97f33a40609bd4823ed92ab8aa9ca4 (diff) | |
download | podman-eba281c3e0e69533427d3eb5c66c60b5ca038c1b.tar.gz podman-eba281c3e0e69533427d3eb5c66c60b5ca038c1b.tar.bz2 podman-eba281c3e0e69533427d3eb5c66c60b5ca038c1b.zip |
Merge pull request #11851 from cdoern/podRm
Pod Rm Infra Handling Improvements
-rw-r--r-- | docs/source/markdown/podman-pod-rm.1.md | 2 | ||||
-rw-r--r-- | libpod/container_internal.go | 2 | ||||
-rw-r--r-- | libpod/runtime_pod_linux.go | 3 | ||||
-rw-r--r-- | test/e2e/pod_rm_test.go | 17 |
4 files changed, 20 insertions, 4 deletions
diff --git a/docs/source/markdown/podman-pod-rm.1.md b/docs/source/markdown/podman-pod-rm.1.md index eac40ef62..fc834a69c 100644 --- a/docs/source/markdown/podman-pod-rm.1.md +++ b/docs/source/markdown/podman-pod-rm.1.md @@ -7,7 +7,7 @@ podman\-pod\-rm - Remove one or more stopped pods and containers **podman pod rm** [*options*] *pod* ## DESCRIPTION -**podman pod rm** will remove one or more stopped pods and their containers from the host. The pod name or ID can be used. The \-f option stops all containers and then removes them before removing the pod. +**podman pod rm** will remove one or more stopped pods and their containers from the host. The pod name or ID can be used. The \-f option stops all containers and then removes them before removing the pod. If all containers added by the user are in an exited state, the pod will be removed. ## OPTIONS diff --git a/libpod/container_internal.go b/libpod/container_internal.go index bfed94990..43f5398a2 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -2103,7 +2103,7 @@ func (c *Container) checkReadyForRemoval() error { return errors.Wrapf(define.ErrCtrStateInvalid, "container %s is in invalid state", c.ID()) } - if c.ensureState(define.ContainerStateRunning, define.ContainerStatePaused) { + if c.ensureState(define.ContainerStateRunning, define.ContainerStatePaused) && !c.IsInfra() { return errors.Wrapf(define.ErrCtrStateInvalid, "cannot remove container %s as it is %s - running or paused containers cannot be removed without force", c.ID(), c.state.State.String()) } diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go index 9c6f1539f..9bd6d5e78 100644 --- a/libpod/runtime_pod_linux.go +++ b/libpod/runtime_pod_linux.go @@ -177,10 +177,9 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, if err != nil { return err } - numCtrs := len(ctrs) - // If the only container in the pod is the pause container, remove the pod and container unconditionally. + // If the only running container in the pod is the pause container, remove the pod and container unconditionally. pauseCtrID := p.state.InfraContainerID if numCtrs == 1 && ctrs[0].ID() == pauseCtrID { removeCtrs = true diff --git a/test/e2e/pod_rm_test.go b/test/e2e/pod_rm_test.go index 6a8ac72fb..7dc3dfa7f 100644 --- a/test/e2e/pod_rm_test.go +++ b/test/e2e/pod_rm_test.go @@ -301,4 +301,21 @@ var _ = Describe("Podman pod rm", func() { Expect(session).Should(Exit(0)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) }) + + It("podman pod rm with exited containers", func() { + _, ec, podid := podmanTest.CreatePod(nil) + Expect(ec).To(Equal(0)) + + session := podmanTest.Podman([]string{"run", "--pod", podid, ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + + session = podmanTest.Podman([]string{"run", "--pod", podid, ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + + result := podmanTest.Podman([]string{"pod", "rm", podid}) + result.WaitWithDefaultTimeout() + Expect(result).Should(Exit(0)) + }) }) |