Skip to content

kubectl-ate: keep client-go unhandled-error reports off stderr#540

Open
Yiqing Wang (YQ-Wang) wants to merge 1 commit into
agent-substrate:mainfrom
YQ-Wang:fix/issue-26-client-error-output
Open

kubectl-ate: keep client-go unhandled-error reports off stderr#540
Yiqing Wang (YQ-Wang) wants to merge 1 commit into
agent-substrate:mainfrom
YQ-Wang:fix/issue-26-client-error-output

Conversation

@YQ-Wang

@YQ-Wang Yiqing Wang (YQ-Wang) commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #26

  • Tests pass
  • Appropriate changes to documentation are included in the PR

Summary

A successful kubectl ate create actor can print this:

E0520 15:40:33.154830 3507355 portforward.go:502] "Unhandled Error" err="error copying from local connection to remote stream: ... read: connection reset by peer"

The user never asked for port-forwarding — it is an implementation detail of this plugin — so a message naming portforward.go is not something they can act on.

client-go reports problems it cannot return to a caller through utilruntime.HandleError, whose default handler writes to stderr. This replaces that handler for kubectl-ate: those reports are dropped by default and printed under a new --verbose flag. klog is deliberately left alone, so warnings a user can act on directly — a missing kubeconfig, an exec credential plugin that failed to refresh — keep reaching the terminal. That is enough because every port-forward error that reaches a user goes through HandleError, while the package's direct klog calls are all V(4) or higher.

#539 proposes removing the localhost hop that produces this particular reset. That is a ~200 line transport change for one message, though, and the next HandleError call inside client-go would read just as strangely. Handling it here covers the class and leaves #539 to be weighed on its own merits.

Notes for reviewers

  • Reflector and informer errors travel through the same channel. kubectl-ate makes one-shot RPCs today, so nothing actionable is lost, but a watch-based command should revisit this.
  • The flag is --verbose rather than --v=N because -v is already cobra's --version shorthand here, and this does not wire klog verbosity. Happy to match that or the server binaries' --log-level if you prefer.

Validation

go test -race -count=5 ./cmd/kubectl-ate/... and the hack/verify scripts pass, with no changes to go.mod or vendor/modules.txt. New tests assert the exact text from #26 produces no output by default and is printed under --verbose, and the flag is documented in the CLI README.

The reset in #26 is timing-dependent and did not reproduce on macOS in 1,500 invocations against a kind cluster, so I forced the same code path by pointing the forwarder at a port with nothing listening. On main:

E0725 02:52:41.650594 63626 portforward.go:522] "Unhandled Error" err="an error occurred forwarding 54823 -> 9999: ... connect: connection refused" logger="UnhandledError"
Error: failed to list atespaces: rpc error: code = Unavailable ...

With this change only the second line is printed, and --verbose restores the first. A klog.Warning raised with the quiet handler installed still reaches stderr, and normal commands and error paths are identical to main.

@google-cla

google-cla Bot commented Jul 25, 2026

Copy link
Copy Markdown

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.

client-go reports problems it cannot return to a caller through
utilruntime.HandleError. Its default handler writes them to the user's terminal
naming the client-go file that failed, for example:

  E0520 15:40:33.154830 3507355 portforward.go:502] "Unhandled Error" err="..."

Someone running `kubectl ate create actor` cannot act on that, and the
port-forwarding it refers to is an implementation detail of this plugin.

Route that channel through the CLI: dropped by default, printed under --verbose.
klog is left alone so that warnings a user can act on, such as a missing
kubeconfig or an exec credential plugin that failed to refresh, still reach them.

Fixes agent-substrate#26
@YQ-Wang
Yiqing Wang (YQ-Wang) force-pushed the fix/issue-26-client-error-output branch from c5fabcb to 7ed1c66 Compare July 25, 2026 09:29
@YQ-Wang Yiqing Wang (YQ-Wang) changed the title kubectl-ate: keep Kubernetes client diagnostics off stderr kubectl-ate: keep client-go unhandled-error reports off stderr Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sporadic error copying from local connection to remote stream ... connection reset by peer"

1 participant