Skip to content

Commit 9cbc1c7

Browse files
committed
kcp: enable websocket dialer with fallback to spdy
1 parent a0090d3 commit 9cbc1c7

File tree

1 file changed

+11
-0
lines changed
  • controlplane/kubeadm/internal/proxy

1 file changed

+11
-0
lines changed

controlplane/kubeadm/internal/proxy/dial.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/pkg/errors"
2727
corev1 "k8s.io/api/core/v1"
2828
kerrors "k8s.io/apimachinery/pkg/util/errors"
29+
"k8s.io/apimachinery/pkg/util/httpstream"
2930
"k8s.io/client-go/kubernetes"
3031
"k8s.io/client-go/tools/portforward"
3132
"k8s.io/client-go/transport/spdy"
@@ -108,6 +109,16 @@ func (d *Dialer) DialContext(ctx context.Context, _ string, addr string) (net.Co
108109

109110
dialer := spdy.NewDialer(d.upgrader, httpClient, "POST", req.URL())
110111

112+
// Configure websocket dialer and keep spdy as fallback
113+
// Note: websockets are enabled per default starting with kubernetes 1.31.
114+
tunnelingDialer, err := portforward.NewSPDYOverWebsocketDialer(req.URL(), d.proxy.KubeConfig)
115+
if err != nil {
116+
return nil, errors.Wrap(err, "error creating websocket tunneling dialer")
117+
}
118+
dialer = portforward.NewFallbackDialer(tunnelingDialer, dialer, func(err error) bool {
119+
return httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err)
120+
})
121+
111122
// Create a new connection from the dialer.
112123
//
113124
// Warning: Any early return should close this connection, otherwise we're going to leak them.

0 commit comments

Comments
 (0)