Repository navigation
Skip the archives whose images containerd already has (MK8S-475) - #69
riadelhajjaji-scality wants to merge 9 commits into
Conversation
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
6b5dde3 to
620a930
Compare
1c91b28 to
620a930
Compare
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`.
…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.
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.
…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.
…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.
eeabb3d to
0527b97
Compare
…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
left a comment
There was a problem hiding this comment.
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 onmain, 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?
| make_raw_docker_archive "$CACHE/tag.tar" \ | ||
| '[{"Config":"config.json","RepoTags":["registry.example/pause:3.10 sha256:00"],"Layers":[]}]' |
There was a problem hiding this comment.
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).
Component
rpm, docs
Problem
Every 10 minutes, the
containerd-image-preloadtimer 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 causeslow fdatasyncwarnings. 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:
ctr -n k8s.io images checklists thename digestpairs containerd holdscompleteand 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.tar --seekreads onlyindex.json, andjqturns it intoname digestpairs.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: jqandtar, both in the EL8/EL9 base repos.Test
script.bats(skip, missing/other digest/incomplete/not unpacked, fallbacks,images checkexiting non-zero with a full table, summary counts) and 1 inpackage.bats.make -C rpm testpasses on EL8 and EL9 (58/58).mainctr images rm busyboxNot yet run: containerd 1.6/1.7 on EL8/EL9, as the ticket asks. This is to confirm that
images checkreports the same digest asindex.jsonthere, and to measure containerd's own I/O.Out of scope
IOSchedulingClass=idle).RandomizedDelaySec: an up-to-date node now writes nothing, so there is little left to spread out..pathunit), and pinning cached images against kubelet GC.README.md,DESIGN.md,rpm/README.md.Relates-to: MK8S-475