Skip to content

Commit c80660b

Browse files
committed
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 <[email protected]>
1 parent b51177b commit c80660b

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

docs/config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ version = 2
106106
# This only works for runtime type "io.containerd.runtime.v1.linux".
107107
no_pivot = false
108108

109+
# discard_unpacked_layers allows GC to remove layers from the content store after
110+
# successfully unpacking these layers to the snapshotter.
111+
discard_unpacked_layers = false
112+
109113
# default_runtime_name is the default runtime name to use.
110114
default_runtime_name = "runc"
111115

pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ type ContainerdConfig struct {
8080
// related information) to snapshotters. These annotations are required by
8181
// stargz snapshotter (https://github.com/containerd/stargz-snapshotter).
8282
DisableSnapshotAnnotations bool `toml:"disable_snapshot_annotations" json:"disableSnapshotAnnotations"`
83+
84+
// DiscardUnpackedLayers is a boolean flag to specify whether to allow GC to
85+
// remove layers from the content store after successfully unpacking these
86+
// layers to the snapshotter.
87+
DiscardUnpackedLayers bool `toml:"discard_unpacked_layers" json:"discardUnpackedLayers"`
8388
}
8489

8590
// CniConfig contains toml config related to cni

pkg/server/image_pull.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
127127
containerd.WithImageHandlerWrapper(appendInfoHandlerWrapper(ref)))
128128
}
129129

130+
if c.config.ContainerdConfig.DiscardUnpackedLayers {
131+
// Allows GC to clean layers up from the content store after unpacking
132+
pullOpts = append(pullOpts,
133+
containerd.WithChildLabelMap(containerdimages.ChildGCLabelsFilterLayers))
134+
}
135+
130136
image, err := c.client.Pull(ctx, ref, pullOpts...)
131137
if err != nil {
132138
return nil, errors.Wrapf(err, "failed to pull and unpack image %q", ref)

0 commit comments

Comments
 (0)