Skip to content

Skip the archives whose images containerd already has (MK8S-475) - #69

Open
riadelhajjaji-scality wants to merge 9 commits into
mainfrom
improvement/MK8S-475-skip-present-images
Open

riadelhajjaji-scality wants to merge 9 commits into
mainfrom
improvement/MK8S-475-skip-present-images

Conversation

@riadelhajjaji-scality

@riadelhajjaji-scality riadelhajjaji-scality commented Nov 12, 2026 •

Copy link
Copy Markdown

Component

rpm, docs

Problem

Every 10 minutes, the containerd-image-preload timer re-imports every archive of the cache, even when containerd already has every image. On a lab node with 877 MB of archives, each run read 1.67 GB and wrote 1.78 GB. On a control-plane node that disk is shared with etcd, and such write bursts cause slow fdatasync warnings. The docs called this re-import "harmless"; it isn't.

Fix

The script now skips an archive when containerd already has all of its images:

  • Once per run, ctr -n k8s.io images check lists the name digest pairs containerd holds complete and unpacked. Its exit code is ignored: it is non-zero as soon as any one image fails its check, but the table is still complete.
  • For each archive, tar --seek reads only index.json, and jq turns it into name digest pairs.
  • Skip only when every pair matches. Otherwise, import as before.

Anything it cannot compare is imported: no index.json, an unnamed image, an index over 1 MiB, or containerd not answering. A wrong guess costs an extra import, never a missing image.

Rejected: hashing the archive. The hash doesn't change when containerd loses an image (GC, prune), which is what the timer is for, and it would read the whole cache every run.

Packaging: Requires: jq and tar, both in the EL8/EL9 base repos.

Test

  • bats: 15 new cases in script.bats (skip, missing/other digest/incomplete/not unpacked, fallbacks, images check exiting non-zero with a full table, summary counts) and 1 in package.bats. make -C rpm test passes on EL8 and EL9 (58/58).
  • Real containerd 2.4.2, 74.6 MB cache (busybox + nginx):
Step Result containerd writes
Cold 2 imported 274 MB
Warm, this branch 2 skipped 0 MB
Warm, main 2 re-imported 73.8 MB
After ctr images rm busybox busybox imported, nginx skipped 7.7 MB

Not yet run: containerd 1.6/1.7 on EL8/EL9, as the ticket asks. This is to confirm that images check reports the same digest as index.json there, and to measure containerd's own I/O.

Out of scope

  • Lower I/O priority for the import (IOSchedulingClass=idle).
  • RandomizedDelaySec: an up-to-date node now writes nothing, so there is little left to spread out.
  • Triggering on cache changes (.path unit), and pinning cached images against kubelet GC.

  • Docs updated: README.md, DESIGN.md, rpm/README.md.

Relates-to: MK8S-475

The timer re-imported every archive every 10 minutes, reading and
writing about twice the cache size even when containerd had it all.

The script now compares each archive's OCI index.json (names and
digests) with what `ctr images check` reports complete and unpacked,
and skips the archives that match. Anything it cannot compare is
imported as before. The package now requires jq and tar.

The timer gets RandomizedDelaySec=1min so nodes that boot together
drift apart.

Refs: MK8S-475
@riadelhajjaji-scality
riadelhajjaji-scality force-pushed the improvement/MK8S-475-skip-present-images branch from 6b5dde3 to 620a930 Compare November 18, 2026 09:21
Comment thread DESIGN.md Resolved
Comment thread rpm/sources/containerd-image-preload.sh Resolved
@riadelhajjaji-scality
riadelhajjaji-scality force-pushed the improvement/MK8S-475-skip-present-images branch from 1c91b28 to 620a930 Compare November 18, 2026 09:42
Comment thread DESIGN.md Resolved
Comment thread rpm/sources/containerd-image-preload.sh Resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
`RandomizedDelaySec=1min` was there to keep nodes whose disks sit on the
same storage from importing at the same time. Now that a run skips the
archives containerd already has, a run on a node that is up to date
only reads the archive indexes and writes nothing, so there is little
left to spread out. The delay still held back the timer's boot run by up
to a minute.

Back to the timer of main: `OnBootSec=0` and `OnUnitActiveSec=10min`.
Comment thread rpm/sources/containerd-image-preload.sh Resolved
Comment thread rpm/sources/containerd-image-preload.sh Resolved
…dy has

An archive with no index.json, as skopeo docker-archive: and docker save
before Docker 25 write, was imported at every run. containerd writes its
own manifest for such an image, so it is matched on each tag of
manifest.json, named the way containerd names it on import, and on the
digest of its image configuration, hashed from the archive and read from
containerd with `ctr content get`.

Like containerd, an archive with an index.json is still read as OCI.
Comment thread rpm/sources/containerd-image-preload.sh Resolved
Two archives can hold the same image name with different images. The
images containerd holds are listed once, before the first import, so
after the first archive moved the name, the second was still taken as
present and skipped. The name then switched between the two images at
every run.

Once an archive is imported, whether the import worked or not, its names
are no longer taken as present. A later archive holding one of them is
imported too, and the last one wins, as when nothing is skipped.
Comment thread rpm/sources/containerd-image-preload.sh Resolved
…ption

The configuration path comes from the archive's manifest.json, and GNU
tar reads an option even after the archive: `--` now keeps it a file
name. Only `--occurrence`, which then had no file name, kept such a path
from running anything.

manifest.json is also refused, and the archive imported, when a
configuration path is empty, starts with a dash or holds white space, or
when its tags are not a list of strings with no white space. An empty
path logged "bad array subscript" at every run.
Comment thread rpm/sources/containerd-image-preload.sh Resolved
Comment thread DESIGN.md Resolved
@ezekiel-alexrod
ezekiel-alexrod self-requested a review November 24, 2026 09:08
…skippable

An archive with one unnamed or untagged image, or one malformed entry,
cannot be skipped, so its names were never read, and its import forgot
none of them. A later archive holding one of those names was then
skipped while the import had moved it, and the name switched between the
two images at every run.

The names are now read on their own, leniently: every name containerd
can give an image from the archive, docker-archive tags normalized as
for the skip. An archive whose index cannot be read at all still forgets
nothing.

DESIGN.md now links to rpm/README.md for how images are matched instead
of repeating it.
@riadelhajjaji-scality
riadelhajjaji-scality force-pushed the improvement/MK8S-475-skip-present-images branch from eeabb3d to 0527b97 Compare November 24, 2026 10:33
Comment thread rpm/sources/containerd-image-preload.sh Resolved
Comment thread rpm/sources/containerd-image-preload.sh Resolved
…tainerd

A docker-archive's configuration path comes from the archive, and GNU tar
matched it as a pattern on extraction: "*" read the first member instead.
--no-wildcards keeps it literal.

With no image in k8s.io, `ctr images check` prints nothing and succeeds, so
a fresh node warned that containerd could not list its images. An empty,
successful answer now means nothing is ready.

@ezekiel-alexrod ezekiel-alexrod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the comment below, LGTM. Two nits on the PR description, it's a bit outdated now:

  • the Test section says 15 new cases in script.bats, there are 54 now (20 on main, 74 here)
  • containerd 1.6/1.7 is still under "Not yet run", but you tested 1.6.38 and 1.7.27 (see your reply on the docker-archive thread). Maybe move it to the Test section?

Comment thread rpm/test/script.bats
Comment on lines +942 to +943
make_raw_docker_archive "$CACHE/tag.tar" \
'[{"Config":"config.json","RepoTags":["registry.example/pause:3.10 sha256:00"],"Layers":[]}]'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case does not test the white space check on tags. I removed the check from the script (and all(.RepoTags[]; ...), line 108), and all the tests still pass.

Why: with this tag, the script reads registry.example/pause:3.10 as the name and sha256:00 config.json as the config path. That file does not exist, so the archive is imported anyway, with or without the check.

A tag that ends with a space shows the problem. Without the check, the script reads the name registry.example/pause:3.10 and the config config.json. Both match, so the archive is skipped. I'd add this test:

@test "a docker-archive tag with a trailing space is imported" {
    make_raw_docker_archive "$CACHE/trail.tar" \
        '[{"Config":"config.json","RepoTags":["registry.example/pause:3.10 "],"Layers":[]}]'
    run_preload
    [ "$status" -eq 0 ]
    grep -q "trail.tar" "$CTR_LOG"
}

It passes on HEAD and fails without the check (EL9).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants