Use Dial with context

Kubernetes-commit: 5e8e570dbda6ed89af9bc2e0a05e3d94bfdfcb61
This commit is contained in:
Mikhail Mazurskiy 2018-05-19 08:14:37 +10:00 committed by Kubernetes Publisher
parent 2a0903c3de
commit 5b356b15a2
2 changed files with 7 additions and 5 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package config package config
import ( import (
"context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -147,9 +148,10 @@ func (cm *ClientManager) HookClient(h *v1beta1.Webhook) (*rest.RESTClient, error
delegateDialer := cfg.Dial delegateDialer := cfg.Dial
if delegateDialer == nil { if delegateDialer == nil {
delegateDialer = net.Dial var d net.Dialer
delegateDialer = d.DialContext
} }
cfg.Dial = func(network, addr string) (net.Conn, error) { cfg.Dial = func(ctx context.Context, network, addr string) (net.Conn, error) {
if addr == host { if addr == host {
u, err := cm.serviceResolver.ResolveEndpoint(svc.Namespace, svc.Name) u, err := cm.serviceResolver.ResolveEndpoint(svc.Namespace, svc.Name)
if err != nil { if err != nil {
@ -157,7 +159,7 @@ func (cm *ClientManager) HookClient(h *v1beta1.Webhook) (*rest.RESTClient, error
} }
addr = u.Host addr = u.Host
} }
return delegateDialer(network, addr) return delegateDialer(ctx, network, addr)
} }
return complete(cfg) return complete(cfg)

View File

@ -69,10 +69,10 @@ func newTransportForETCD2(certFile, keyFile, caFile string) (*http.Transport, er
// TODO: Determine if transport needs optimization // TODO: Determine if transport needs optimization
tr := utilnet.SetTransportDefaults(&http.Transport{ tr := utilnet.SetTransportDefaults(&http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{ DialContext: (&net.Dialer{
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
}).Dial, }).DialContext,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
MaxIdleConnsPerHost: 500, MaxIdleConnsPerHost: 500,
TLSClientConfig: cfg, TLSClientConfig: cfg,