Skip to content

fix: panic with kubectl when timestamps are enabled (#7947)#10034

Open
kdeloachbayer wants to merge 1 commit intoGoogleContainerTools:mainfrom
kdeloachbayer:kd/fix-kubectl-timestamps
Open

fix: panic with kubectl when timestamps are enabled (#7947)#10034
kdeloachbayer wants to merge 1 commit intoGoogleContainerTools:mainfrom
kdeloachbayer:kd/fix-kubectl-timestamps

Conversation

@kdeloachbayer
Copy link
Copy Markdown

@kdeloachbayer kdeloachbayer commented Mar 31, 2026

Summary

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.PrefixWriter1 writing N bytes to its buffer and then discarding N+len(timestamp) bytes, causing a panic.

Relevant textio.PrefixWriter source code (ref:
https://github.com/segmentio/textio/blob/master/prefix.go#L54-L55):

    c, err = w.writeLine(chunk)
    w.discard(c)

Follow-up Work

The segmentio/textio package 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 where textio calls Write twice (once for the prefix, once for the log line) which results in this output: [timestamp][prefix][timestamp][log line].

Fixes: #7947

Footnotes

  1. Used by pkg/skaffold/deploy/kubectl/kubectl.go

@kdeloachbayer kdeloachbayer requested a review from a team as a code owner March 31, 2026 16:35
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread pkg/skaffold/output/output.go Outdated
…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
@kdeloachbayer kdeloachbayer force-pushed the kd/fix-kubectl-timestamps branch from 2303193 to a55eb17 Compare April 1, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky behaviour with SKAFFOLD_TIMESTAMPS="true"

1 participant