Skip to content

cri: size a container's rootfs snapshot from its annotations - #14070

Open
fivetime wants to merge 1 commit into
containerd:mainfrom
fivetime:cri-container-snapshot-labels
Open

fivetime wants to merge 1 commit into
containerd:mainfrom
fivetime:cri-container-snapshot-labels

Conversation

@fivetime

@fivetime fivetime commented Aug 31, 2026 •

Copy link
Copy Markdown

The sandbox snapshot inherits containerd.io/snapshot/* labels from the sandbox annotations (podsandbox.sandbox_run), but the container's rootfs snapshot takes nothing from the container annotations, so the writable layer cannot be sized per container.

On Windows the CRI API carries WindowsContainerResources.rootfs_size_in_bytes and containerd translates it into a snapshot label. There is no Linux equivalent in the CRI API, so an annotation is the only channel available.

This takes containerd.io/snapshot/max-size from the container annotations and passes it to the snapshotter, ahead of the platform specific options. Only that label is taken, rather than every containerd.io/snapshot/ annotation as the sandbox does (as suggested in review): the other labels under the prefix are containerd's own, and the user namespace ID mappings in particular are set by snapshotterOpts only when a user namespace is requested, so an inherited mapping would otherwise reach the snapshotter unchallenged for a container that has none.

Verified on the erofs snapshotter (default_size = '512M'), three containers in one pod:

container annotation df -h / dd bs=1M count=64 labels on the active snapshot
limited max-size: "33554432" 26.0M ENOSPC after 25 MiB, exit 1 max-size only
remapped max-size + uidmapping/gidmapping (no user namespace requested) 26.0M, rootfs still 0:0 — max-size only
plain none 487.2M 64 MiB written, exit 0 none

Copilot AI lite review requested due to automatic review settings August 31, 2026 02:43
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Aug 31, 2026

Copilot AI 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.

Pull request overview

Propagates CRI per-container snapshot configuration to snapshotters by inheriting containerd.io/snapshot/* labels from container annotations when preparing the container rootfs snapshot, matching the existing pod sandbox snapshot behavior.

Changes:

  • Introduce snapshotOpts() to prepend inherited snapshot labels (from container annotations) ahead of platform-specific snapshot options.
  • Switch container creation to use snapshotOpts() instead of calling platform-specific snapshotterOpts() directly.
  • Add unit tests validating label inheritance/filtering behavior for container snapshot options.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/cri/server/container_create.go Adds snapshotOpts() and uses it during container snapshot preparation to inherit snapshot labels from annotations.
internal/cri/server/container_create_test.go Adds tests for snapshotOpts() to ensure only snapshot-label annotations are propagated.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/cri/server/container_create.go Resolved
fivetime added a commit to fivetime/openstack-zun that referenced this pull request Aug 31, 2026
CriDriver reported no disk quota support, so `disk` was refused on every
CRI node and, with nothing asking for one, a container's writable layer
had no bound at all: one tenant could fill the node's disk.

containerd can enforce it per container, but only through the erofs
snapshotter, which sizes the writable layer by allocating a fixed-size
filesystem image for it. It reads the size from the
containerd.io/snapshot/max-size snapshot label, and that label reaches a
CRI container as an annotation.

Report support by asking the runtime which snapshotter it prepares this
node's rootfs with, rather than by a setting an operator would have to
keep in step with containerd. The snapshotter is chosen per runtime
handler -- containerd ships kata-fc on devmapper beside handlers left on
overlayfs -- so the question is asked for the handler this node is
configured to use, and CRI Status carries the runtime's own config, the
same source _available_runtimes() already reads.

Anything that is not erofs, including a handler falling through to a
default Status does not report, reads as no quota. That keeps the
existing refusal for those nodes, which is the honest answer: a `disk`
accepted and then not applied is worse than one turned down, because
nothing tells the tenant.

Requires containerd to pass the annotation through to the container
snapshot, which today it does only for the sandbox
(containerd/containerd#14070).

@hsiangkao hsiangkao left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it looks good? or, we could apply the similar approach as Windows to expose the only containerd.io/snapshot/max-size here to the container's rootfs snapshot.
/cc @containerd/committers

The sandbox snapshot inherits `containerd.io/snapshot/*` labels from the
sandbox annotations (see podsandbox.sandbox_run), but the container's
rootfs snapshot takes nothing from the container annotations, so the
writable layer cannot be sized per container.

On Windows the CRI API carries WindowsContainerResources.rootfs_size_in_bytes
and containerd translates it into a snapshot label. There is no Linux
equivalent in the CRI API, so an annotation is the only channel available.

Take containerd.io/snapshot/max-size from the container annotations and pass
it to the snapshotter, ahead of the platform specific options. Only that
label is taken, rather than every containerd.io/snapshot/ annotation as the
sandbox does: the other labels under the prefix are containerd's own, and
the user namespace ID mappings in particular are set by snapshotterOpts only
when a user namespace is requested, so an inherited mapping would otherwise
reach the snapshotter unchallenged for a container that has none.

With the erofs snapshotter, a container annotated with
containerd.io/snapshot/max-size=33554432 gets a 32MiB writable layer and
writes past it fail with ENOSPC, while an unannotated container in the same
pod still gets the snapshotter's configured default.

Signed-off-by: Simon Zhou <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 14, 2026 07:46
@fivetime
fivetime force-pushed the cri-container-snapshot-labels branch from 87d07c2 to 73b1c9c Compare September 14, 2026 07:46
@fivetime

Copy link
Copy Markdown
Author

Thanks @hsiangkao — agreed, and I think the narrower form is the safer one rather than just the smaller one. Inheriting the whole containerd.io/snapshot/ prefix lets a container annotation set labels the CRI plugin manages itself: on Linux snapshotterOpts returns nothing when no user namespace is requested, so an annotated containerd.io/snapshot/uidmapping would reach the snapshotter's Prepare unchanged.

Pushed a new revision that takes only containerd.io/snapshot/max-size, mirroring the Windows rootfs.sizebytes path, with a test that other containerd.io/snapshot/ annotations (uidmapping, gidmapping, snapshot.ref, overlay.upperdir) are not inherited. Re-verified on erofs: a max-size-annotated container gets the 32 MiB writable layer and hits ENOSPC, one annotated with uidmapping but no user namespace keeps a 0:0 rootfs and only max-size on its snapshot, and an unannotated one keeps the 512 MiB default. Commit message and PR description updated to match.

Sorry for invalidating the approval — PTAL.

@fivetime fivetime changed the title cri: inherit snapshot labels from container annotations cri: size a container's rootfs snapshot from its annotations Sep 14, 2026

Copilot AI 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.

🟡 Changes recommended

Filtered container annotations must be forwarded to satisfy the stated snapshot-label inheritance contract.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +1212 to +1216
if size, ok := config.GetAnnotations()[snapshots.LabelSnapshotMaxSize]; ok {
opts = append(opts, snapshots.WithLabels(map[string]string{
snapshots.LabelSnapshotMaxSize: size,
}))
}
fivetime added a commit to fivetime/containerd that referenced this pull request Sep 14, 2026
The CRI nodes run a containerd built from this fork's main, because the
erofs writable-layer size and the containerd.io/snapshot/max-size label
exist only on upstream main, in no release yet, and the CRI change that
carries the label (containerd#14070) is not merged. Every push
to main now builds linux/amd64 and linux/arm64 with upstream's release
Dockerfile and publishes a prerelease tagged with the upstream version,
the date and the commit, so a node is pinned to an exact build and
`containerd --version` names it.

Co-authored-by: Claude Fable 5.1 <[email protected]>
fivetime added a commit to fivetime/containerd that referenced this pull request Sep 14, 2026
The CRI nodes run a containerd built from this fork's main, because the
erofs writable-layer size and the containerd.io/snapshot/max-size label
exist only on upstream main, in no release yet, and the CRI change that
carries the label (containerd#14070) is not merged. Every push
to main now builds linux/amd64 and linux/arm64 with upstream's release
Dockerfile and publishes a prerelease tagged with the upstream version,
the date and the commit, so a node is pinned to an exact build and
`containerd --version` names it.

Co-authored-by: Claude Fable 5.1 <[email protected]>
fivetime added a commit to fivetime/containerd that referenced this pull request Sep 14, 2026
The CRI nodes run a containerd built from this fork's main, because the
erofs writable-layer size and the containerd.io/snapshot/max-size label
exist only on upstream main, in no release yet, and the CRI change that
carries the label (containerd#14070) is not merged. Every push
to main now builds linux/amd64 and linux/arm64 with upstream's release
Dockerfile and publishes a prerelease tagged with the upstream version,
the date and the commit, so a node is pinned to an exact build and
`containerd --version` names it.

Co-authored-by: Claude Fable 5.1 <[email protected]>
fivetime added a commit to fivetime/containerd that referenced this pull request Sep 14, 2026
The CRI nodes run a containerd built from this fork's main, because the
erofs writable-layer size and the containerd.io/snapshot/max-size label
exist only on upstream main, in no release yet, and the CRI change that
carries the label (containerd#14070) is not merged.

Built daily and on every push to main with upstream's release Dockerfile
for linux/amd64 and linux/arm64, published as one prerelease per day
tagged main.<yyyymmdd>: a second build the same day replaces the day's
release, a day on which main did not move is skipped, and the last 30 are
kept. `containerd --version` reports the tag and the commit.

Co-authored-by: Claude Fable 5.1 <[email protected]>
pandaWall added a commit to pandaWall/containerd that referenced this pull request Oct 10, 2026
layerSnapshotLabels() strips containerd.io/snapshot/uidmapping and
.../gidmapping from image manifest annotations because snapshotters
act on them during Prepare (containerd#13855). Complete the enumeration with
.../max-size, added in containerd#13520: the erofs snapshotter honors it
unclamped when sizing the writable layer of an active snapshot
(writableSize -> X-containerd.mkfs.size -> truncate + mkfs.ext4),
and an image manifest is not a trusted source for that host-side
resource decision.
The sanctioned setters of max-size are CRI clients, via
PodSandboxConfig annotations on the sandbox path (to be extended to
container annotations in containerd#14070); those are untouched.

Today the in-tree erofs differ locates the layer directory through
the mount list without materializing the writable image (MountsToLayer),
so no current code path turns an image-supplied max-size into a real allocation —
this is defense-in-depth completing containerd#13855's enumeration before any consumer of unpack-time layer mounts does.

Signed-off-by: pandaWall <[email protected]>
pandaWall added a commit to pandaWall/containerd that referenced this pull request Oct 10, 2026
layerSnapshotLabels() strips containerd.io/snapshot/uidmapping and
.../gidmapping from image manifest annotations because snapshotters
act on them during Prepare (containerd#13855). Complete the enumeration with
.../max-size, added in containerd#13520: the erofs snapshotter honors it
unclamped when sizing the writable layer of an active snapshot
(writableSize -> X-containerd.mkfs.size -> truncate + mkfs.ext4),
and an image manifest is not a trusted source for that host-side
resource decision.
The sanctioned setters of max-size are CRI clients, via
PodSandboxConfig annotations on the sandbox path (to be extended to
container annotations in containerd#14070); those are untouched.

Today the in-tree erofs differ locates the layer directory through
the mount list without materializing the writable image (MountsToLayer),
so no current code path turns an image-supplied max-size into a real allocation —
this is defense-in-depth completing containerd#13855's enumeration before any consumer of unpack-time layer mounts does.

Signed-off-by: pandaWall <[email protected]>
fivetime pushed a commit to fivetime/containerd that referenced this pull request Oct 27, 2026
The branch carries 73b1c9c, the same change as 9c24548 already on
main (containerd#14070); the merge changes no file.
@kubernetes-prow

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

This branch has not been deployed

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

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants