c8d/list: Support dangling filter

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-01-23 10:00:00 +01:00
parent de90b5e9ad
commit c477cda59f
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A

View file

@ -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) {