fix(shim): support non-CRI callers (BuildKit, ctr) in containerd shim#12873
Open
alan890104 wants to merge 1 commit intogoogle:masterfrom
Open
fix(shim): support non-CRI callers (BuildKit, ctr) in containerd shim#12873alan890104 wants to merge 1 commit intogoogle:masterfrom
alan890104 wants to merge 1 commit intogoogle:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Fix two issues that prevent gVisor containers from working when created through containerd's direct API (non-CRI), such as BuildKit's containerd worker or `ctr run`: 1. Sandbox detection: SpecContainerType returns ContainerTypeUnspecified for non-CRI callers that don't set the container type annotation. Previously this resulted in p.Sandbox=false, which skipped passing IO file descriptors to runsc create. Without IO, container processes receive SIGPIPE on stdout/stderr writes and exit with code 128. Fix: treat ContainerTypeUnspecified as sandbox, since non-CRI containers are always root/sandbox containers. 2. Wait error handling: For short-lived containers, the sandbox may exit before `runsc wait` retrieves the exit status, producing "sandbox no longer running and its exit status is unavailable". This error was treated as fatal (setting internalErrorCode=128) even when the container exited successfully (status=0). Fix: extract adjustWaitStatus() and when status is 0, log the error as a warning but preserve the exit status. Includes unit tests for both fixes: - TestSandboxDetection: 7 cases covering all container type variants - TestAdjustWaitStatus: 7 cases covering all status/error combinations Fixes google#12198 Tested: BuildKit containerd worker with gVisor on GCE e2-standard-4, containerd v1.7.29, runsc release-20260330.0. Six consecutive RUN steps (echo, ls, cat, apk add curl) all pass with exit code 0.
nybidari
approved these changes
Apr 6, 2026
copybara-service bot
pushed a commit
that referenced
this pull request
Apr 6, 2026
## Summary Fix two issues that prevent gVisor containers from working when created through containerd's direct API (non-CRI), such as BuildKit's containerd worker or `ctr run`. ### 1. Sandbox detection for non-CRI callers `SpecContainerType` returns `ContainerTypeUnspecified` for non-CRI callers that don't set the container type annotation (`io.kubernetes.cri.container-type`). Previously this resulted in `p.Sandbox=false`, which skipped passing IO file descriptors to `runsc create`. Without IO, container processes receive SIGPIPE on stdout/stderr writes and exit with code 128. **Fix:** treat `ContainerTypeUnspecified` as sandbox, since non-CRI containers are always root/sandbox containers. ### 2. Wait error handling for short-lived containers For short-lived containers, the sandbox may exit before `runsc wait` retrieves the exit status, producing `"sandbox no longer running and its exit status is unavailable"`. This error was treated as fatal (setting `internalErrorCode=128`) even when the container exited successfully (`status=0`). **Fix:** extract `adjustWaitStatus()` function — when status is 0, log the error as a warning but preserve the exit status. ## Test plan - [x] `TestSandboxDetection` — 9 cases covering all container type variants including no-annotation (BuildKit/ctr), containerd sandbox/container, CRI-O sandbox/container, unknown values, dual annotations - [x] `TestAdjustWaitStatus` — 9 cases covering status=0 success, non-zero exit, signal exit (137), benign sandbox error with status=0, non-zero with error, negative status, exit 255 - [x] E2E: BuildKit containerd worker with gVisor on GCE e2-standard-4, containerd v1.7.29, runsc release-20260330.0. Eight consecutive RUN steps (echo, ls, resolv.conf, apk add curl jq + curl HTTPS, exit code, multi-line script, id, uname) all pass with exit code 0. Fixes #12198 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12873 from alan890104:minimal-fix c5fdfd4 PiperOrigin-RevId: 895531992
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix two issues that prevent gVisor containers from working when created through containerd's direct API (non-CRI), such as BuildKit's containerd worker or
ctr run.1. Sandbox detection for non-CRI callers
SpecContainerTypereturnsContainerTypeUnspecifiedfor non-CRI callers that don't set the container type annotation (io.kubernetes.cri.container-type). Previously this resulted inp.Sandbox=false, which skipped passing IO file descriptors torunsc create. Without IO, container processes receive SIGPIPE on stdout/stderr writes and exit with code 128.Fix: treat
ContainerTypeUnspecifiedas sandbox, since non-CRI containers are always root/sandbox containers.2. Wait error handling for short-lived containers
For short-lived containers, the sandbox may exit before
runsc waitretrieves the exit status, producing"sandbox no longer running and its exit status is unavailable". This error was treated as fatal (settinginternalErrorCode=128) even when the container exited successfully (status=0).Fix: extract
adjustWaitStatus()function — when status is 0, log the error as a warning but preserve the exit status.Test plan
TestSandboxDetection— 9 cases covering all container type variants including no-annotation (BuildKit/ctr), containerd sandbox/container, CRI-O sandbox/container, unknown values, dual annotationsTestAdjustWaitStatus— 9 cases covering status=0 success, non-zero exit, signal exit (137), benign sandbox error with status=0, non-zero with error, negative status, exit 255Fixes #12198