Skip to content

Commit

Permalink
feat: support portforwarding over websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
lsjostro committed Sep 24, 2024
1 parent 2492402 commit dec1e15
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/dao/port_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/httpstream"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/portforward"
Expand Down Expand Up @@ -176,6 +177,16 @@ func (p *PortForwarder) forwardPorts(method string, url *url.URL, addr, portMap
}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport, Timeout: defaultTimeout}, method, url)

tunnelingDialer, err := portforward.NewSPDYOverWebsocketDialer(url, cfg)
if err != nil {
return nil, err
}

// First attempt tunneling (websocket) dialer, then fallback to spdy dialer.
dialer = portforward.NewFallbackDialer(tunnelingDialer, dialer, func(err error) bool {
return httpstream.IsUpgradeFailure(err) || httpstream.IsHTTPSProxyError(err)
})

return portforward.NewOnAddresses(dialer, []string{addr}, []string{portMap}, p.stopChan, p.readyChan, p.Out, p.ErrOut)
}

Expand Down

0 comments on commit dec1e15

Please sign in to comment.