Skip to content

Commit

Permalink
remove-image: Add optional LookupManifest to RemoveImagesOptions.
Browse files Browse the repository at this point in the history
Following flag allows user to configure RemoveImages in a manner so that
remove func becomes exclusive to removing manifests when needed and not
removing underlying referenced images.

Signed-off-by: Aditya Rajan <[email protected]>
  • Loading branch information
flouthoc committed Sep 1, 2021
1 parent 08184df commit 6f43739
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libimage/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ 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
// LookupManifest ensures that {lookupManifest: true} it passed as opt to lookupImages
// which ensures that only valid manifestList is removed from store and no referenced images.
LookupManifest 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).
Expand Down Expand Up @@ -600,13 +603,23 @@ 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 {
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
Expand Down

0 comments on commit 6f43739

Please sign in to comment.