Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR restores backward compatibility between containerd 2.2 daemons and containerd 2.3+ containerd-shim-runc-v2 by returning the legacy JSON bootstrap response for legacy callers while preserving the protobuf BootstrapResult response for new callers.
Changes:
- Add bootstrap-protocol detection that distinguishes legacy callers from new bootstrap callers even when legacy runtime options can protobuf-unmarshal into
BootstrapParams. - For legacy callers, emit a JSON
BootstrapParamsresponse instead of protobuf. - Add unit coverage for the new
parseBootstrapParamsprotocol-detection logic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/shim/shim.go | Detect legacy bootstrap callers and switch stdout response encoding to JSON for compatibility. |
| pkg/shim/compat.go | Introduce parseBootstrapParams to distinguish legacy runtime-options payloads from new bootstrap params. |
| pkg/shim/shim_test.go | Add tests covering new-vs-legacy bootstrap payload detection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // distinguishes it from the new protocol. | ||
| params, usesBootstrapProtocol := parseBootstrapParams(input, id, namespaceFlag) | ||
| if !usesBootstrapProtocol { | ||
| // TODO: Return error once the new API is stable |
There was a problem hiding this comment.
Unrelated, but looks like this TODO is outdated?
A containerd 2.2 daemon cannot start a containerd 2.3 `containerd-shim-runc-v2`. The 2.3 shim accepts the deprecated CLI, environment, and stdin startup interface, but returns a protobuf-encoded `BootstrapResult`. Containerd 2.2 expects a JSON `BootstrapParams` response or a plain socket address. It therefore interprets the protobuf payload as the socket address and fails with an error similar to: ```text failed to create TTRPC connection: unsupported protocol: \b\x03\x12Yunix ``` Detect legacy callers by comparing the identity decoded from stdin with the identity supplied through the compatibility CLI fields. This comparison is necessary because containerd 2.2 sends runtime options as a protobuf `Any`. The `Any` fields can decode as non-empty `BootstrapParams.instance_id` and `.namespace` fields, so successful protobuf unmarshalling alone cannot distinguish the protocols. For legacy callers, return the JSON `BootstrapParams` response they expect. For new bootstrap callers, continue returning the protobuf `BootstrapResult`. The legacy JSON response preserves the expected field names, always includes the version, and excludes unsupported capabilities and metadata. Signed-off-by: Paweł Gronowski <[email protected]>
There was a problem hiding this comment.
containerd daemon already handles this logic in 2.3 and main:
func parseStartResponse(response []byte) (*bootapi.BootstrapResult, error) {
var result bootapi.BootstrapResult
if err := proto.Unmarshal(response, &result); err == nil {
return &result, nil
}
// Fallback to legacy parsing for backward compatibility with
// legacy shims that return the address as a plain string or JSON.
var params client.BootstrapParams //nolint:staticcheck // Used for backward compatibility with legacy shims
if err := json.Unmarshal(response, ¶ms); err != nil || params.Version < 2 {
// Use TTRPC for legacy shims
params.Address = string(response)
params.Protocol = "ttrpc"
params.Version = 2
}
...
return &bootapi.BootstrapResult{
Version: int32(params.Version),
Address: params.Address,
Protocol: params.Protocol,
}, nil
}Instead of adding another path on shim side, I'd suggest to backport this function to 2.2 -
containerd/core/runtime/v2/shim.go
Line 225 in e4b6730
|
Or the other way around: main and 2.3 already have fallback, so it makes sense to open this PR straight against 2.2 |
|
I haven't dug in as deep as @vvoland but it's a bit odd though if the shim handles the old API on one side, but then produces the wrong result on ten other side? |
|
New shims produce protobuf (2.3 and main). |
|
Thinking of this more: @vvoland this use case is a bit unusual. How did you end up having older containerd 2.2 daemon and newer shims 2.3 ? Is this a downgrade? |
|
The particular case which we hit this is when we embedded the containerd 2.2 in Moby but the containerd binaries (runc-shim specifically) was on 2.3. However, this also affects cases where you upgrade your containerd packages but don't restart the daemon. We've hit this in the past with the v1 -> v2 transition, like: #10984 The fix must be on the shim side so that the upgrade to latest containerd can happen from any containerd older than 2.3, not just latest 2.2 release. |
|
containerd 2.3+ is be able to parse both json and protobuf responses. The patch you're proposing requires rebuilding older shims, which defeats the purpose of clean upgrades. While backporting and upgrading the daemon would be much easier (one fallback path, only daemon needs upgrade). You upgrade the daemon and it should be able to work with any shims. |
|
I'm happy to also backport For a user willing to migrate to 2.3 from 2.2 the most sensible and common path is going from whatever 2.2.X to the latest 2.3.X. The 2.2 backport helps once the patched 2.2 daemon is running but does not cover a direct upgrade from an arbitrary 2.0–2.2 installation where the package replaces
Not really - the point here is being able to update cleanly to a first containerd 2.3 version that includes this patch from any containerd 2.0-2.2 daemon. This will work because the runc shim is packaged alongside the containerd daemon. This patch also matches the compatibility note from #12786:
|
A containerd 2.2 daemon cannot start a containerd 2.3
containerd-shim-runc-v2.The 2.3 shim accepts the deprecated CLI, environment, and stdin startup interface, but returns a protobuf-encoded
BootstrapResult. Containerd 2.2 expects a JSONBootstrapParamsresponse or a plain socket address. It therefore interprets the protobuf payload as the socket address and fails with an error similar to:Detect legacy callers by comparing the identity decoded from stdin with the identity supplied through the compatibility CLI fields. This comparison is necessary because containerd 2.2 sends runtime options as a protobuf
Any.The
Anyfields can decode as non-emptyBootstrapParams.instance_idand.namespacefields, so successful protobuf unmarshalling alone cannot distinguish the protocols.For legacy callers, return the JSON
BootstrapParamsresponse they expect.For new bootstrap callers, continue returning the protobuf
BootstrapResult.The legacy JSON response preserves the expected field names, always includes the version, and excludes unsupported capabilities and metadata.