From c477cda59fdbdd9c2ca0dffad1e971e7cf6b5d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 23 Jan 2023 10:00:00 +0100 Subject: [PATCH] c8d/list: Support dangling filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- daemon/containerd/image_list.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/daemon/containerd/image_list.go b/daemon/containerd/image_list.go index 7e37178cd1..edaf13c2a2 100644 --- a/daemon/containerd/image_list.go +++ b/daemon/containerd/image_list.go @@ -18,7 +18,7 @@ import ( ) var acceptedImageFilterTags = map[string]bool{ - "dangling": false, // TODO(thaJeztah): implement "dangling" filter: see https://github.com/moby/moby/issues/43846 + "dangling": true, "label": true, "before": true, "since": true, @@ -256,6 +256,17 @@ func (i *ImageService) setupFilters(ctx context.Context, imageFilters filters.Ar return imageFilters.MatchKVList("label", image.Labels) }) } + + if imageFilters.Contains("dangling") { + danglingValue, err := imageFilters.GetBoolOrDefault("dangling", false) + if err != nil { + return nil, err + } + fltrs = append(fltrs, func(image images.Image) bool { + return danglingValue == isDanglingImage(image) + }) + } + return func(image images.Image) bool { for _, filter := range fltrs { if !filter(image) {