aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-09-28 07:34:12 -0400
committerGitHub <noreply@github.com>2021-09-28 07:34:12 -0400
commitf2ffb96eb317012e94258a242f6dc907acd22c40 (patch)
treede48efeabf92b80e8cc69c456f33908124630769 /libpod
parent340166876eab09d3e363647213f162864a95d270 (diff)
parenta9a54eefab34b25628906a786d6c4ca302f743b1 (diff)
downloadpodman-f2ffb96eb317012e94258a242f6dc907acd22c40.tar.gz
podman-f2ffb96eb317012e94258a242f6dc907acd22c40.tar.bz2
podman-f2ffb96eb317012e94258a242f6dc907acd22c40.zip
Merge pull request #11737 from vrothberg/fix-11472
image prune: support removing external containers
Diffstat (limited to 'libpod')
-rw-r--r--libpod/runtime_img.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 66cf7a4d5..1915a5c4d 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -48,6 +48,27 @@ func (r *Runtime) RemoveContainersForImageCallback(ctx context.Context) libimage
}
}
+// IsExternalContainerCallback returns a callback that be used in `libimage` to
+// figure out whether a given container is an external one. A container is
+// considered external if it is not present in libpod's database.
+func (r *Runtime) IsExternalContainerCallback(_ context.Context) libimage.IsExternalContainerFunc {
+ // NOTE: pruning external containers is subject to race conditions
+ // (e.g., when a container gets removed). To address this and similar
+ // races, pruning had to happen inside c/storage. Containers has to be
+ // labelled with "podman/libpod" along with callbacks similar to
+ // libimage.
+ return func(idOrName string) (bool, error) {
+ _, err := r.LookupContainer(idOrName)
+ if err == nil {
+ return false, nil
+ }
+ if errors.Is(err, define.ErrNoSuchCtr) {
+ return true, nil
+ }
+ return false, nil
+ }
+}
+
// newBuildEvent creates a new event based on completion of a built image
func (r *Runtime) newImageBuildCompleteEvent(idOrName string) {
e := events.NewEvent(events.Build)