diff --git a/libimage/runtime.go b/libimage/runtime.go index 7d3fbf3f2..502d748d8 100644 --- a/libimage/runtime.go +++ b/libimage/runtime.go @@ -541,6 +541,14 @@ type RemoveImagesOptions struct { // using a removed image. Use RemoveContainerFunc for a custom logic. // If set, all child images will be removed as well. Force bool + // If set, do not look for items/instances in the manifest list that + // match the current platform but return the manifest list as is. + // only check for manifest list, return ErrNotAManifestList if not found. + LookupManifest bool + // If matching images resolves to a manifest list, return manifest list + // instead of resolving to image instance, if manifest list is not found + // try resolving image. + ManifestList bool // RemoveContainerFunc allows for a custom logic for removing // containers using a specific image. By default, all containers in // the local containers storage will be removed (if Force is set). @@ -600,13 +608,26 @@ func (r *Runtime) RemoveImages(ctx context.Context, names []string, options *Rem toDelete := []string{} // Look up images in the local containers storage and fill out // toDelete and the deleteMap. + + // prepare lookupOptions + var lookupOptions *LookupImageOptions + if options.LookupManifest { + // LookupManifest configured as true make sure we only remove manifests and no referenced images. + lookupoptions = &lookupimageoptions{lookupmanifest: true} + } else if options.ManifestList { + // Try finding manifest list if not found fallback to images. + lookupoptions = &lookupimageoptions{ManifestList: true} + } else { + lookupOptions = &LookupImageOptions{returnManifestIfNoInstance: true} + } + switch { case len(names) > 0: // Look up the images one-by-one. That allows for removing // images that have been looked up successfully while reporting // lookup errors at the end. for _, name := range names { - img, resolvedName, err := r.LookupImage(name, &LookupImageOptions{returnManifestIfNoInstance: true}) + img, resolvedName, err := r.LookupImage(name, lookupOptions) if err != nil { appendError(err) continue