Skip to content

executor: warn when rootless drops resource limits - #7288

Open
MalteMagnussen wants to merge 2 commits into
moby:masterfrom
MalteMagnussen:rootless-resources-warning
Open

MalteMagnussen wants to merge 2 commits into
moby:masterfrom
MalteMagnussen:rootless-resources-warning

Conversation

@MalteMagnussen

Copy link
Copy Markdown

Rootless executors drop per-step resource limits (ToRootless clears Resources and CgroupsPath), but the daemon still advertises exec.meta.linux.resources, so --resource silently does nothing. See #7287.

This logs a warning and adds a build warning to the step when it asks for limits that a rootless executor (runc or containerd) ignores.

Safe for existing users: limits are dropped exactly as before. The only change is the warning on rootless steps that set limits.

Tested in an Ubuntu 26.04 VM with rootful Docker via hack/test: a new unit test and the new testLinuxResourcesIgnoredWarning pass on oci, oci-rootless, containerd and containerd-rootless, and testLinuxResources still passes.

Note

This PR was made with Claude Code. I mainly want to put a spotlight on #7287 and would love to see a fix released, so resources works in rootless setups where cgroup v2 is available. I can't defend the design choices here, since Claude made them as a follow-up after my laptop froze during a build that had resource limits set. Feel free to close this if you'd rather fix it another way.

The rootless runc and containerd executors remove the cgroup settings
from the spec, so per-step resource limits (memory, cpu-quota, cpuset
and so on) have no effect there. The daemon still advertises
exec.meta.linux.resources, so clients send limits and get no error or
warning.

Log a warning and add a build warning to the step whenever it asks for
limits that a rootless executor ignores. The limits are still dropped,
so the build result does not change.

Signed-off-by: Malte Hviid-Magnussen <malte.hviid-magnussen@group.one>
@AkihiroSuda

Copy link
Copy Markdown
Member

This user has not yet uploaded their public signing key.

GPG signature cannot be verified

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused warning-only change preserves existing execution behavior, includes test coverage, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Makes ignored resource limits visible on rootless BuildKit steps, addressing the silent behavior reported in #7287 without changing limit enforcement.

Changes:

  • Adds daemon-log and per-step build warnings when limits are ignored.
  • Integrates warnings into both rootless executors.
  • Adds unit and integration coverage.
File Description
executor/​runcexecutor/​executor.go Emits warnings for rootless runc steps.
executor/​resources_warning.go Adds shared warning logic and resource detection.
executor/​resources_warning_test.go Tests warning emission and suppression.
executor/​containerdexecutor/​executor_unix.go Emits warnings for rootless containerd steps.
client/​client_test.go Registers the integration test.
client/​client_exec_test.go Tests rootless warnings and rootful silence.

Review effort: Balanced

@MalteMagnussen

Copy link
Copy Markdown
Author

Thanks, I hadn't added my SSH signing key to GitHub. Done now, the commits show as verified.

Comment thread executor/resources_warning.go Outdated
if res == nil {
return false
}
return res.Memory != 0 || res.MemorySwap != 0 ||

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.

nit: could use reflect to avoid listing all the struct field names

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 9cbdc93. I used ProtoReflect().Range instead of reflect, since it only visits fields that are set and skips the generated message's internal fields.

hasLinuxResources listed every field of pb.LinuxResources, so a field
added later would be missed. Use ProtoReflect().Range, which visits the
fields that are set.

Signed-off-by: Malte Hviid-Magnussen <malte.hviid-magnussen@group.one>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants