fix: panic with kubectl when timestamps are enabled (#7947)#10034
Open
kdeloachbayer wants to merge 1 commit intoGoogleContainerTools:mainfrom
Open
fix: panic with kubectl when timestamps are enabled (#7947)#10034kdeloachbayer wants to merge 1 commit intoGoogleContainerTools:mainfrom
kdeloachbayer wants to merge 1 commit intoGoogleContainerTools:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the skaffoldWriter.Write method to ensure that the returned number of bytes written matches the length of the input payload, excluding any prepended timestamps. This change addresses an inconsistency where the returned value could exceed the input length. The test suite was updated to verify this behavior. Feedback was provided to handle empty input writes to prevent stray timestamps and to use more idiomatic Go patterns for string writing.
…ools#7947) Fixes a bug where using the `--timestamps` flag with `kubectl` deploy panics with: > error:panic: runtime error: slice bounds out of range With timestamps enabled, `skaffoldWriter.Write` includes the length of the timestamp in its return value. But `Writer` implementations should return the number of bytes _consumed_, not written. This results in `textio.PrefixWriter`[^1] writing `N` bytes to its buffer and then discarding `N+len(timestamp)` bytes, causing a panic. [^1]: Used by `pkg/skaffold/deploy/kubectl/kubectl.go` Relevant `textio.PrefixWriter` source code (ref: https://github.com/segmentio/textio/blob/master/prefix.go#L54-L55): ```go c, err = w.writeLine(chunk) w.discard(c) ``` Fixes: GoogleContainerTools#7947
2303193 to
a55eb17
Compare
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
Fixes a bug where using the
--timestampsflag withkubectl deploypanics with:With timestamps enabled,
skaffoldWriter.Writeincludes the length of the timestamp in its return value. ButWriterimplementations should return the number of bytes consumed, not written. This results intextio.PrefixWriter1 writingNbytes to its buffer and then discardingN+len(timestamp)bytes, causing a panic.Relevant
textio.PrefixWritersource code (ref:https://github.com/segmentio/textio/blob/master/prefix.go#L54-L55):
Follow-up Work
The
segmentio/textiopackage is currently in maintenance mode. Considering it's only used in 1 file, just to append a prefix to output logs, it may be worth removing altogether. That would fix another cosmetic issue wheretextiocallsWritetwice (once for the prefix, once for the log line) which results in this output:[timestamp][prefix][timestamp][log line].Fixes: #7947
Footnotes
Used by
pkg/skaffold/deploy/kubectl/kubectl.go↩