Merge pull request #46911 from vvoland/c8d-prune-dangling-default

c8d/prune: Default `dangling` to true, familiarize untagged images
This commit is contained in:
Sebastiaan van Stijn 2023-12-08 18:54:29 +01:00 committed by GitHub
commit 312fbb6d41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -341,3 +341,14 @@ func (i *ImageService) getAllImagesWithRepository(ctx context.Context, ref refer
nameFilter := "^" + regexp.QuoteMeta(ref.Name()) + ":" + reference.TagRegexp.String() + "$"
return i.client.ImageService().List(ctx, "name~="+strconv.Quote(nameFilter))
}
func imageFamiliarName(img containerdimages.Image) string {
if isDanglingImage(img) {
return img.Target.Digest.String()
}
if ref, err := reference.ParseNamed(img.Name); err == nil {
return reference.FamiliarString(ref)
}
return img.Name
}

View file

@ -42,7 +42,7 @@ func (i *ImageService) ImagesPrune(ctx context.Context, fltrs filters.Args) (*ty
return nil, err
}
danglingOnly, err := fltrs.GetBoolOrDefault("dangling", false)
danglingOnly, err := fltrs.GetBoolOrDefault("dangling", true)
if err != nil {
return nil, err
}
@ -184,7 +184,7 @@ func (i *ImageService) pruneUnused(ctx context.Context, filterFunc imageFilterFu
report.ImagesDeleted = append(report.ImagesDeleted,
image.DeleteResponse{
Untagged: img.Name,
Untagged: imageFamiliarName(img),
},
)