mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-08-27 00:37:20 +00:00
fix: correct RBAC verb and WebSocket fallback for pods/exec This commit fixes three related issues that prevented exec collectors from working with minimal RBAC permissions: 1. RBAC preflight check used wrong verb for pods/exec Changed from "get" to "create" in v1beta1 and v1beta2 AccessReviewSpecs. The pods/exec subresource requires "create" to execute commands. 2. WebSocket fallback used wrong httpstream package import The fallback executor checked IsUpgradeFailure using the apimachinery httpstream package, but the roundtripper creates UpgradeFailureError using the streaming httpstream package. These are different Go types, so errors.As always returned false and fallback to SPDY never triggered. Changed import to k8s.io/streaming/pkg/httpstream. 3. Stdin mismatch caused SPDY fallback to hang PodExecOptions always set Stdin:true but StreamOptions always passed Stdin:nil. When WebSocket failed and fell back to SPDY, the server waited for stdin data that never arrived. Changed Stdin to false in PodExecOptions for exec, copy, and copy_from_host collectors.
28 lines
901 B
Go
28 lines
901 B
Go
package k8sutil
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
restclient "k8s.io/client-go/rest"
|
|
"k8s.io/client-go/tools/remotecommand"
|
|
"k8s.io/streaming/pkg/httpstream"
|
|
)
|
|
|
|
// NewFallbackExecutor creates an executor that tries WebSocket first and falls
|
|
// back to SPDY if the server does not support it. Use this in place of
|
|
// remotecommand.NewSPDYExecutor everywhere.
|
|
func NewFallbackExecutor(config *restclient.Config, u *url.URL) (remotecommand.Executor, error) {
|
|
// WebSocket upgrade requires GET per RFC 6455; SPDY uses POST.
|
|
wsExec, err := remotecommand.NewWebSocketExecutor(config, "GET", u.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
spdyExec, err := remotecommand.NewSPDYExecutor(config, "POST", u)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return remotecommand.NewFallbackExecutor(wsExec, spdyExec, func(err error) bool {
|
|
return httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err)
|
|
})
|
|
}
|