From c80660b82b1df9965c2e399fa61a62c088e152a6 Mon Sep 17 00:00:00 2001 From: ktock Date: Mon, 27 Jul 2020 10:59:21 +0900 Subject: [PATCH] Allow GC to discard content after successful pull and unpack This commit adds a config flag for allowing GC to clean layer contents up after unpacking these contents completed, which leads to deduplication of layer contents between the snapshotter and the contnet store. Signed-off-by: Kohei Tokunaga --- docs/config.md | 4 ++++ pkg/config/config.go | 5 +++++ pkg/server/image_pull.go | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/docs/config.md b/docs/config.md index e9a32435a..b489e79d3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -106,6 +106,10 @@ version = 2 # This only works for runtime type "io.containerd.runtime.v1.linux". no_pivot = false + # discard_unpacked_layers allows GC to remove layers from the content store after + # successfully unpacking these layers to the snapshotter. + discard_unpacked_layers = false + # default_runtime_name is the default runtime name to use. default_runtime_name = "runc" diff --git a/pkg/config/config.go b/pkg/config/config.go index 7cfb6d51f..a0c86fa76 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -80,6 +80,11 @@ type ContainerdConfig struct { // related information) to snapshotters. These annotations are required by // stargz snapshotter (https://github.com/containerd/stargz-snapshotter). DisableSnapshotAnnotations bool `toml:"disable_snapshot_annotations" json:"disableSnapshotAnnotations"` + + // DiscardUnpackedLayers is a boolean flag to specify whether to allow GC to + // remove layers from the content store after successfully unpacking these + // layers to the snapshotter. + DiscardUnpackedLayers bool `toml:"discard_unpacked_layers" json:"discardUnpackedLayers"` } // CniConfig contains toml config related to cni diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go index b7a1181ff..7407edd29 100644 --- a/pkg/server/image_pull.go +++ b/pkg/server/image_pull.go @@ -127,6 +127,12 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest) containerd.WithImageHandlerWrapper(appendInfoHandlerWrapper(ref))) } + if c.config.ContainerdConfig.DiscardUnpackedLayers { + // Allows GC to clean layers up from the content store after unpacking + pullOpts = append(pullOpts, + containerd.WithChildLabelMap(containerdimages.ChildGCLabelsFilterLayers)) + } + image, err := c.client.Pull(ctx, ref, pullOpts...) if err != nil { return nil, errors.Wrapf(err, "failed to pull and unpack image %q", ref)