Skip to content

feat: containerd is a rootstock plugin, orchd-rootstock-containerd - #79

Merged
adiled merged 4 commits into
mainfrom
rootstock-containerd
Nov 9, 2026
Merged

adiled merged 4 commits into
mainfrom
rootstock-containerd

Conversation

@adiled

@adiled adiled commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Closes #7. The containerd runtime returns as a contract-1 plugin in Zig, with the PR's design: one foreground run per tree that drives containerd's gRPC API itself.

The run leaf

  1. Clear anything left from a previous run.
  2. Pull through Transfer, which also unpacks into overlayfs.
  3. Images.Get, then Content.Read for index → manifest → config; fold the layers' diff_ids into the chainID.
  4. Snapshots.Prepare with that chainID as parent.
  5. Containers.Create with an OCI spec: host network namespace, masked and read-only paths, the service's limits.
  6. Tasks.Create with FIFOs for stdout/stderr, then Start and Wait.
  7. On SIGTERM or SIGINT, the wait is abandoned. Teardown kills the task, waits up to 8 s, then SIGKILL, and deletes the task, container and snapshot on a fresh connection. A timed-out wait leaves its connection mid-stream, hence the fresh one.

New since the Rust PR

  • The container's stdout and stderr come back through FIFOs, so they land in orchd's logs. The Rust version dropped them.
  • runc's no_pivot_root is opt-in with ORCHD_CONTAINERD_NO_PIVOT_ROOT=1. It's needed for initramfs roots (an applz VM) but is the weaker choice on a normal host, where the PR forced it.
  • check calls containerd's Version RPC rather than just looking for the socket.

The wire, built here

  • HTTP/2 is nghttp2 v1.71.0, compiled from its release tarball by our own build.zig (26 C files, its header translated with addTranslateC). No foreign build script runs, and it links statically into the musl Linux binaries.
  • gRPC on top is ours: request headers, 5-byte message framing, grpc-status/grpc-message from trailers, the containerd-namespace header. Calls take an interrupt flag and a timeout.
  • Protobuf is hand-written for the dozen messages, with field numbers from containerd's .proto files.

Tests

  • 23 unit tests. The gRPC client runs against a gRPC server built on nghttp2's server API, over a real unix socket: unary, server-streaming, grpc-status errors, interrupt and timeout.
  • Live on containerd 2.4.2 (arm64, inside an applz VM, no_pivot_root): check returned the version; run pulled alpine and started it (ctr showed RUNNING); the container's output and a host bind mount came through; SIGTERM exited 143 and left no task, container or snapshot.
  • CI (containerd.yml, Ubuntu runner, amd64, pivot_root): orchd grow --rootstock containerd on orchdi, ctr shows it RUNNING, the output reaches the keeper's log, fell leaves nothing behind.

Note: an early commit on this branch accidentally included nghttp2's unpacked source under zig-pkg/. It's removed and ignored, and this PR is squash-merged, so main never carries it.

The long-hung containerd runtime (#7) comes back as a contract-1 plugin in
Zig. One foreground run per tree drives containerd's gRPC API itself: pull
through Transfer, read the image through Content, prepare the snapshot,
create the container and its task, wait, and on SIGTERM kill, wait and
delete task, container and snapshot.

gRPC rides on nghttp2, compiled from its release by our own build.zig, with
the protobuf for the dozen messages written by hand. The container's stdout
and stderr come back through FIFOs, so they land in orchd's logs. runc's
no_pivot_root is opt-in (ORCHD_CONTAINERD_NO_PIVOT_ROOT=1) for initramfs
roots such as an applz VM.
zig 0.17 unpacks dependencies into zig-pkg/ beside build.zig.zon, and the
plugin's .gitignore did not say so.
adiled added a commit that referenced this pull request Nov 9, 2026
On teardown the keeper sends SIGTERM to the tree's **process group**,
but it waited only for its **direct child**, the `/bin/sh -c start`
shell. The shell dies at once, while the process that actually does the
work may still be cleaning up. So the keeper and `fell` returned early,
leaving the cleanup orphaned.

Found by #79's CI: `fell` returned in 0.2 s while the containerd run
leaf was still deleting its task, so the "nothing left" check saw the
task.

The keeper now waits until the whole group is gone (`kill(-pgid, 0)`
fails), still within the stop timeout, after which it SIGKILLs the group
as before.

**Repro** (scratch, macOS): a tree of `sh -c 'trap "sleep 1; touch
cleaned; exit 0" TERM; while :; do sleep 0.1; done'; true`. The trailing
`; true` keeps the shell from exec'ing the child.

| | keeper exits after TERM | cleanup done when it exits |
|---|---|---|
| main | 0.26 s | no (finished later, orphaned) |
| this | 1.14 s | yes, nothing left |
Five seconds for the task to stop on SIGTERM, then SIGKILL and two more,
so killing, deleting and removing finish within the keeper's default ten.
@adiled
adiled merged commit 474b5e8 into main Nov 9, 2026
5 checks passed
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.

1 participant