diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2021-12-16 14:53:51 +0100 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2021-12-17 13:23:11 +0100 |
commit | 12d762f8ee288164cdb1a8390520d88c4c5eb1bc (patch) | |
tree | d242e04d147bca9fef7ecec9f4a318f49cb33148 /libpod/runtime_img.go | |
parent | 91e55e263e860af24f176c5e62405a54ef7356de (diff) | |
download | podman-12d762f8ee288164cdb1a8390520d88c4c5eb1bc.tar.gz podman-12d762f8ee288164cdb1a8390520d88c4c5eb1bc.tar.bz2 podman-12d762f8ee288164cdb1a8390520d88c4c5eb1bc.zip |
image rm: allow for force-remove infra images
Force removal of images will also remove associated containers.
Historically, infra containers have been excluded resulting in
rather annoying errors, for instance, when running `rmi -af`.
Since there is not reasons to exclude infra containers, allow for
removing the entire pod when an infra image is force removed.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/runtime_img.go')
-rw-r--r-- | libpod/runtime_img.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 52ac0d4d7..bf0fc4585 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -36,10 +36,21 @@ func (r *Runtime) RemoveContainersForImageCallback(ctx context.Context) libimage return err } for _, ctr := range ctrs { - if ctr.config.RootfsImageID == imageID { - var timeout *uint + if ctr.config.RootfsImageID != imageID { + continue + } + var timeout *uint + if ctr.config.IsInfra { + pod, err := r.state.Pod(ctr.config.Pod) + if err != nil { + return errors.Wrapf(err, "container %s is in pod %s, but pod cannot be retrieved", ctr.ID(), pod.ID()) + } + if err := r.removePod(ctx, pod, true, true, timeout); err != nil { + return errors.Wrapf(err, "removing image %s: container %s using image could not be removed", imageID, ctr.ID()) + } + } else { if err := r.removeContainer(ctx, ctr, true, false, false, timeout); err != nil { - return errors.Wrapf(err, "error removing image %s: container %s using image could not be removed", imageID, ctr.ID()) + return errors.Wrapf(err, "removing image %s: container %s using image could not be removed", imageID, ctr.ID()) } } } |