diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2022-01-12 15:33:00 +0100 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2022-01-13 17:08:31 +0100 |
commit | a4cef543504600db95453aa863b97ed82c833d41 (patch) | |
tree | a48d511c9a677f3a2b1f5f84769910baea53f6fe /libpod | |
parent | ab7228b3c27719e447de4dffe9b3fd7f67d6f346 (diff) | |
download | podman-a4cef543504600db95453aa863b97ed82c833d41.tar.gz podman-a4cef543504600db95453aa863b97ed82c833d41.tar.bz2 podman-a4cef543504600db95453aa863b97ed82c833d41.zip |
podman container rm: remove pod
Support removing the entire pod when --depend is used on an infra
container. --all now implies --depend to properly support removing all
containers and not error out when hitting infra containers.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/runtime_ctr.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 53ccb9139..66e0c29a9 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -915,9 +915,30 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol return id, cleanupErr } -// RemoveDepend removes all dependencies for a container +// RemoveDepend removes all dependencies for a container. +// If the container is an infra container, the entire pod gets removed. func (r *Runtime) RemoveDepend(ctx context.Context, rmCtr *Container, force bool, removeVolume bool, timeout *uint) ([]*reports.RmReport, error) { + logrus.Debugf("Removing container %s and all dependent containers", rmCtr.ID()) rmReports := make([]*reports.RmReport, 0) + if rmCtr.IsInfra() { + pod, err := r.GetPod(rmCtr.PodID()) + if err != nil { + return nil, err + } + logrus.Debugf("Removing pod %s: depends on infra container %s", pod.ID(), rmCtr.ID()) + podContainerIDS, err := pod.AllContainersByID() + if err != nil { + return nil, err + } + if err := r.RemovePod(ctx, pod, true, force, timeout); err != nil { + return nil, err + } + for _, cID := range podContainerIDS { + rmReports = append(rmReports, &reports.RmReport{Id: cID}) + } + return rmReports, nil + } + deps, err := r.state.ContainerInUse(rmCtr) if err != nil { if err == define.ErrCtrRemoved { @@ -940,9 +961,9 @@ func (r *Runtime) RemoveDepend(ctx context.Context, rmCtr *Container, force bool } rmReports = append(rmReports, reports...) } + report := reports.RmReport{Id: rmCtr.ID()} report.Err = r.removeContainer(ctx, rmCtr, force, removeVolume, false, timeout) - return append(rmReports, &report), nil } |