Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions controlplane/kubeadm/internal/proxy/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/httpstream"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/portforward"
"k8s.io/client-go/transport/spdy"
Expand Down Expand Up @@ -108,6 +109,16 @@ func (d *Dialer) DialContext(ctx context.Context, _ string, addr string) (net.Co

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

// Configure websocket dialer and keep spdy as fallback
Copy link
Member

Choose a reason for hiding this comment

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

Change looks easy enough. Any ideas on how I can validate if this is correct? (e.g. is there some prior art somewhere else?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did via using tilt.

I added a breakpoint here for KCP accordingly to check if it uses websocket or does the fallback.

For v1.34: it did not do the fallback and successfully used websockets (verified via the dial method)

For v1.30 it did use the fallback / old code SPDY

Copy link
Member

Choose a reason for hiding this comment

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

// Note: websockets are enabled per default starting with kubernetes 1.31.
tunnelingDialer, err := portforward.NewSPDYOverWebsocketDialer(req.URL(), d.proxy.KubeConfig)
if err != nil {
return nil, errors.Wrap(err, "error creating websocket tunneling dialer")
}
dialer = portforward.NewFallbackDialer(tunnelingDialer, dialer, func(err error) bool {
return httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err)
})

// Create a new connection from the dialer.
//
// Warning: Any early return should close this connection, otherwise we're going to leak them.
Expand Down