Add new ctr option for discarding unpacked layers
Add a new ctr cli option, allowing the garbage collector to discard any unpacked layers after importing an image. This new option is incompatible with the no-unpack ctr import option. Signed-off-by: James Jenkins <James.Jenkins@ibm.com>
This commit is contained in:
16
import.go
16
import.go
@@ -38,6 +38,7 @@ type importOpts struct {
|
||||
allPlatforms bool
|
||||
platformMatcher platforms.MatchComparer
|
||||
compress bool
|
||||
discardLayers bool
|
||||
}
|
||||
|
||||
// ImportOpt allows the caller to specify import specific options
|
||||
@@ -105,6 +106,15 @@ func WithImportCompression() ImportOpt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithDiscardUnpackedLayers allows the garbage collector to clean up
|
||||
// layers from content store after unpacking.
|
||||
func WithDiscardUnpackedLayers(discard bool) ImportOpt {
|
||||
return func(c *importOpts) error {
|
||||
c.discardLayers = discard
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Import imports an image from a Tar stream using reader.
|
||||
// Caller needs to specify importer. Future version may use oci.v1 as the default.
|
||||
// Note that unreferenced blobs may be imported to the content store as well.
|
||||
@@ -195,7 +205,11 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
|
||||
}
|
||||
|
||||
handler = images.FilterPlatforms(handler, platformMatcher)
|
||||
handler = images.SetChildrenLabels(cs, handler)
|
||||
if iopts.discardLayers {
|
||||
handler = images.SetChildrenMappedLabels(cs, handler, images.ChildGCLabelsFilterLayers)
|
||||
} else {
|
||||
handler = images.SetChildrenLabels(cs, handler)
|
||||
}
|
||||
if err := images.WalkNotEmpty(ctx, handler, index); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user