Unverified Commit ee2e11a0 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #65547 from liggitt/dial-util

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Honor custom transport dialer https://github.com/kubernetes/kubernetes/pull/60012 updated API machinery code to use context dial functions by default, but we should still fall back to honor transport.Dial if set * SetOldTransportDefaults should not use the default http DialContext if a custom Dial method is already set * DialerFor should prefer DialContext, but fall back to returning a custom Dial if set before returning nil ```release-note api-machinery utility functions `SetTransportDefaults` and `DialerFor` once again respect custom Dial functions set on transports ```
parents efeb2049 51eb52cc
......@@ -91,7 +91,8 @@ func SetOldTransportDefaults(t *http.Transport) *http.Transport {
// ProxierWithNoProxyCIDR allows CIDR rules in NO_PROXY
t.Proxy = NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
}
if t.DialContext == nil {
// If no custom dialer is set, use the default context dialer
if t.DialContext == nil && t.Dial == nil {
t.DialContext = defaultTransport.DialContext
}
if t.TLSHandshakeTimeout == 0 {
......@@ -129,7 +130,18 @@ func DialerFor(transport http.RoundTripper) (DialFunc, error) {
switch transport := transport.(type) {
case *http.Transport:
return transport.DialContext, nil
// transport.DialContext takes precedence over transport.Dial
if transport.DialContext != nil {
return transport.DialContext, nil
}
// adapt transport.Dial to the DialWithContext signature
if transport.Dial != nil {
return func(ctx context.Context, net, addr string) (net.Conn, error) {
return transport.Dial(net, addr)
}, nil
}
// otherwise return nil
return nil, nil
case RoundTripperWrapper:
return DialerFor(transport.WrappedRoundTripper())
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment