mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
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 ```
This commit is contained in:
commit
ee2e11a0d4
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user