Repository navigation
core/runtime/v2: Preserve protobuf shim response bytes - #13801
Conversation
Shim start output was trimmed before protobuf decoding. Because arbitrary protobuf fields may legitimately end with whitespace bytes, including `\n`, trimming could corrupt metadata or capabilities and cause decoding to fail. Pass the raw command output to `parseStartResponse` and attempt protobuf decoding before modifying the response. Whitespace trimming now applies only to legacy JSON and plain-address responses. Signed-off-by: Paweł Gronowski <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes shim start response parsing in core/runtime/v2 to avoid corrupting protobuf-encoded BootstrapResult data by trimming whitespace before protobuf decoding. It ensures protobuf decoding is attempted on the raw shim stdout output, while whitespace trimming is retained only for legacy (plain-string / JSON) responses.
Changes:
- Pass raw
shim startstdout bytes intoparseStartResponse(stop trimming at the call site). - Apply
bytes.TrimSpaceonly in the legacy fallback path after protobuf unmarshal fails. - Extend tests to cover protobuf responses whose serialized bytes legitimately end with whitespace (e.g.,
\n).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/runtime/v2/shim.go | Moves whitespace trimming to the legacy fallback path so protobuf unmarshalling sees unmodified bytes. |
| core/runtime/v2/binary.go | Stops trimming shim stdout before parsing, preserving raw response bytes for protobuf decoding. |
| core/runtime/v2/shim_test.go | Adds coverage for protobuf responses ending with whitespace and adapts test inputs to raw []byte responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err != nil { | ||
| return nil, fmt.Errorf("%s: %w", out, err) | ||
| } | ||
| response := bytes.TrimSpace(out) |
There was a problem hiding this comment.
Looks indeed that this was added when it was just plain text output, and kept in dba6f9d
| log.G(ctx).WithError(err).Error("copy shim log") | ||
| } | ||
| }() | ||
| out, err := cmd.CombinedOutput() |
There was a problem hiding this comment.
We should also look at this; now that the output is more strict (less forgiving than plain text), we should consider only parsing StdOut, and capture StdErr separately for the error case (probably)
|
/cherry-pick release/2.3 |
|
@mxpv: new pull request created: #13803 DetailsIn response to this:
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. |
Shim start output was trimmed before protobuf decoding. Because arbitrary protobuf fields may legitimately end with whitespace bytes, including
\n, trimming could corrupt metadata or capabilities and cause decoding to fail.Pass the raw command output to
parseStartResponseand attempt protobuf decoding before modifying the response.Whitespace trimming now applies only to legacy JSON and plain-address responses.