@@ -83,16 +83,30 @@ func (d *Dialer) DialContextWithAddr(ctx context.Context, addr string) (net.Conn
83
83
}
84
84
85
85
// DialContext creates proxied port-forwarded connections.
86
- // ctx is currently unused, but fulfils the type signature used by GRPC.
87
- func (d * Dialer ) DialContext (_ context.Context , _ string , addr string ) (net.Conn , error ) {
86
+ func (d * Dialer ) DialContext (ctx context.Context , _ string , addr string ) (net.Conn , error ) {
87
+ // Check if context is already cancelled or timed out
88
+ select {
89
+ case <- ctx .Done ():
90
+ return nil , errors .Wrap (ctx .Err (), "context cancelled before establishing connection" )
91
+ default :
92
+ }
93
+
88
94
req := d .clientset .CoreV1 ().RESTClient ().
89
95
Post ().
90
96
Resource (d .proxy .Kind ).
91
97
Namespace (d .proxy .Namespace ).
92
98
Name (addr ).
93
99
SubResource ("portforward" )
94
100
95
- dialer := spdy .NewDialer (d .upgrader , & http.Client {Transport : d .proxyTransport }, "POST" , req .URL ())
101
+ httpClient := & http.Client {
102
+ Transport : d .proxyTransport ,
103
+ }
104
+
105
+ if deadline , ok := ctx .Deadline (); ok {
106
+ httpClient .Timeout = time .Until (deadline )
107
+ }
108
+
109
+ dialer := spdy .NewDialer (d .upgrader , httpClient , "POST" , req .URL ())
96
110
97
111
// Create a new connection from the dialer.
98
112
//
0 commit comments