blob: 8a7e79be751a105845241ae1011067497e82cac2 [file] [log] [blame]
Lorenz Brun95190ce2025-01-28 13:07:00 +00001From 82e2653680c00d388ab40f9aa98abcbd6644d059 Mon Sep 17 00:00:00 2001
2From: Lorenz Brun <lorenz@monogon.tech>
3Date: Tue, 28 Jan 2025 12:54:09 +0100
4Subject: [PATCH] Use custom dialer in websocket transport
5
6The WebSocket transport currently does not use custom dialer functions
7specified in the rest.Config transport config. This breaks all streaming
8functions when a custom Dial function is used.
9
10The underlying library supports custom dial functions, pipe them through
11properly.
12
13Signed-off-by: Lorenz Brun <lorenz@monogon.tech>
14---
15 .../k8s.io/client-go/transport/websocket/roundtripper.go | 8 ++++++++
16 1 file changed, 8 insertions(+)
17
18diff --git a/transport/websocket/roundtripper.go b/transport/websocket/roundtripper.go
19index 924518e8bbd..0b9521cf37b 100644
20--- a/transport/websocket/roundtripper.go
21+++ b/transport/websocket/roundtripper.go
22@@ -17,10 +17,12 @@ limitations under the License.
23 package websocket
24
25 import (
26+ "context"
27 "crypto/tls"
28 "errors"
29 "fmt"
30 "io"
31+ "net"
32 "net/http"
33 "net/url"
34 "strings"
35@@ -74,6 +76,10 @@ type RoundTripper struct {
36 // If Proxy is nil or returns a nil *URL, no proxy is used.
37 Proxier func(req *http.Request) (*url.URL, error)
38
39+ // Dial specifies a function to use to dial TCP connections.
40+ // If not specified, net.Dial is used.
41+ Dial func(ctx context.Context, network, address string) (net.Conn, error)
42+
43 // Conn holds the WebSocket connection after a round trip.
44 Conn *gwebsocket.Conn
45 }
46@@ -111,6 +117,7 @@ func (rt *RoundTripper) RoundTrip(request *http.Request) (retResp *http.Response
47 delete(request.Header, wsstream.WebSocketProtocolHeader)
48
49 dialer := gwebsocket.Dialer{
50+ NetDialContext: rt.Dial,
51 Proxy: rt.Proxier,
52 TLSClientConfig: rt.TLSConfig,
53 Subprotocols: protocolVersions,
54@@ -195,6 +202,7 @@ func RoundTripperFor(config *restclient.Config) (http.RoundTripper, ConnectionHo
55 }
56
57 upgradeRoundTripper := &RoundTripper{
58+ Dial: config.Dial,
59 TLSConfig: tlsConfig,
60 Proxier: proxy,
61 }
62--
632.47.0
64