From 804ee8c42e56ce135d8cbbcd7ab3770aca104d26 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 7 May 2025 14:51:18 +0200 Subject: [PATCH] client-go remotecommand: avoid "unexpected error" log when there is no error Normal execution always started to trigger this after adding more logging in the E2E framework's exec_util.go: I0506 21:23:56.781188 6341 exec_util.go:201] unexpected error trying to use websockets for pod exec: That the "should fall back" implementation gets called when there is no error and thus no reason to even consider falling back is odd. Now the execute implementation checks for nil first. This is the same approach taken also in the portforward code: https://github.com/kubernetes/kubernetes/blob/b35c5c0a301d326fdfa353943fca077778544ac6/staging/src/k8s.io/client-go/tools/portforward/fallback_dialer.go#L52 Kubernetes-commit: 35870c480d64a8ae35c0e5839cc40b0115b7328a --- tools/remotecommand/fallback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/remotecommand/fallback.go b/tools/remotecommand/fallback.go index 78620d33..50332308 100644 --- a/tools/remotecommand/fallback.go +++ b/tools/remotecommand/fallback.go @@ -52,7 +52,7 @@ func (f *FallbackExecutor) Stream(options StreamOptions) error { // initial primary call to upgrade to a websocket connection fails. func (f *FallbackExecutor) StreamWithContext(ctx context.Context, options StreamOptions) error { err := f.primary.StreamWithContext(ctx, options) - if f.shouldFallback(err) { + if err != nil && f.shouldFallback(err) { klog.V(4).Infof("RemoteCommand fallback: %v", err) return f.secondary.StreamWithContext(ctx, options) }