Skip to content

Commit

Permalink
fix: drop unpacked layers from containerd image store
Browse files Browse the repository at this point in the history
See containerd/cri#1543

Fixes #4274

Fix is applied on two levels:

* for Talos-initiated pulls, update API call
* for Kubernetes-initiated pulls, update CRI plugin config

Comparison of `/var` usage before/after, as reported by
`talosctl mounts` (in GiB):

|              | before | after |
|--------------|:------:|------:|
| controlplane |  1.98  |  1.74 |
| worker       |  1.17  |  1.01 |

It's hard to measure effect on pulls to system containerd, like
`installer` image, as it's ephemeral, but it should also reduce space
usage in `tmpfs`.

Also fixes output of `talosctl mounts`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Dec 6, 2021
1 parent 1fc4361 commit 8f3e1a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions hack/cri-containerd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ format = "json"

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
discard_unpacked_layers = true
9 changes: 8 additions & 1 deletion internal/pkg/containers/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/talos-systems/go-retry/retry"

containerdrunner "github.com/talos-systems/talos/internal/app/machined/pkg/system/runner/containerd"
Expand Down Expand Up @@ -71,7 +72,13 @@ func Pull(ctx context.Context, reg config.Registries, client *containerd.Client,
resolver := NewResolver(reg)

err = retry.Exponential(PullTimeout, retry.WithUnits(PullRetryInterval), retry.WithErrorLogging(true)).Retry(func() error {
if img, err = client.Pull(ctx, ref, containerd.WithPullUnpack, containerd.WithResolver(resolver)); err != nil {
if img, err = client.Pull(
ctx,
ref,
containerd.WithPullUnpack,
containerd.WithResolver(resolver),
containerd.WithChildLabelMap(images.ChildGCLabelsFilterLayers),
); err != nil {
err = fmt.Errorf("failed to pull image %q: %w", ref, err)

if errdefs.IsNotFound(err) || errdefs.IsCanceled(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func RenderMounts(resp *machine.MountsResponse, output io.Writer, remotePeer *pe
if defaultNode != "" {
format = "%s\t" + format

args = append([]interface{}{node}, args)
args = append([]interface{}{node}, args...)
}

fmt.Fprintf(w, format, args...)
Expand Down

0 comments on commit 8f3e1a4

Please sign in to comment.