diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index b9b68b52d2c..19060e68c17 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -11,11 +11,6 @@ pkg/controller/podgc pkg/controller/replicaset pkg/controller/resourcequota pkg/controller/statefulset -pkg/kubelet/apis/podresources -pkg/kubelet/cm/devicemanager -pkg/kubelet/pluginmanager/operationexecutor -pkg/kubelet/pluginmanager/pluginwatcher -pkg/kubelet/remote pkg/probe/http pkg/registry/autoscaling/horizontalpodautoscaler/storage pkg/registry/core/namespace/storage diff --git a/pkg/kubelet/apis/podresources/client.go b/pkg/kubelet/apis/podresources/client.go index ba6eb241f1a..2f33fa441fd 100644 --- a/pkg/kubelet/apis/podresources/client.go +++ b/pkg/kubelet/apis/podresources/client.go @@ -36,7 +36,7 @@ func GetClient(socket string, connectionTimeout time.Duration, maxMsgSize int) ( ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) defer cancel() - conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) + conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) if err != nil { return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err) } diff --git a/pkg/kubelet/cm/devicemanager/device_plugin_stub.go b/pkg/kubelet/cm/devicemanager/device_plugin_stub.go index 7faaba04cdc..25feaf0fe03 100644 --- a/pkg/kubelet/cm/devicemanager/device_plugin_stub.go +++ b/pkg/kubelet/cm/devicemanager/device_plugin_stub.go @@ -162,8 +162,8 @@ func (m *Stub) Register(kubeletEndpoint, resourceName string, pluginSockDir stri defer cancel() conn, err := grpc.DialContext(ctx, kubeletEndpoint, grpc.WithInsecure(), grpc.WithBlock(), - grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("unix", addr, timeout) + grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "unix", addr) })) if err != nil { return err diff --git a/pkg/kubelet/cm/devicemanager/endpoint.go b/pkg/kubelet/cm/devicemanager/endpoint.go index 7a5994d8836..ccb01be3ffd 100644 --- a/pkg/kubelet/cm/devicemanager/endpoint.go +++ b/pkg/kubelet/cm/devicemanager/endpoint.go @@ -177,8 +177,8 @@ func dial(unixSocketPath string) (pluginapi.DevicePluginClient, *grpc.ClientConn defer cancel() c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(), - grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("unix", addr, timeout) + grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "unix", addr) }), ) diff --git a/pkg/kubelet/pluginmanager/operationexecutor/operation_generator.go b/pkg/kubelet/pluginmanager/operationexecutor/operation_generator.go index 371709a09c0..a16546601df 100644 --- a/pkg/kubelet/pluginmanager/operationexecutor/operation_generator.go +++ b/pkg/kubelet/pluginmanager/operationexecutor/operation_generator.go @@ -193,8 +193,8 @@ func dial(unixSocketPath string, timeout time.Duration) (registerapi.Registratio defer cancel() c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(), - grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("unix", addr, timeout) + grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "unix", addr) }), ) diff --git a/pkg/kubelet/pluginmanager/pluginwatcher/example_handler.go b/pkg/kubelet/pluginmanager/pluginwatcher/example_handler.go index 50ad81fff33..16dc6396922 100644 --- a/pkg/kubelet/pluginmanager/pluginwatcher/example_handler.go +++ b/pkg/kubelet/pluginmanager/pluginwatcher/example_handler.go @@ -156,8 +156,8 @@ func dial(unixSocketPath string, timeout time.Duration) (registerapi.Registratio defer cancel() c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(), - grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("unix", addr, timeout) + grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "unix", addr) }), ) diff --git a/pkg/kubelet/remote/remote_image.go b/pkg/kubelet/remote/remote_image.go index 1a482593165..fe3af1b5f7b 100644 --- a/pkg/kubelet/remote/remote_image.go +++ b/pkg/kubelet/remote/remote_image.go @@ -47,7 +47,7 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (in ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) defer cancel() - conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithDialer(dailer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) + conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dailer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) if err != nil { klog.Errorf("Connect remote image service %s failed: %v", addr, err) return nil, err diff --git a/pkg/kubelet/remote/remote_runtime.go b/pkg/kubelet/remote/remote_runtime.go index cf09dad4c12..784c17d21bc 100644 --- a/pkg/kubelet/remote/remote_runtime.go +++ b/pkg/kubelet/remote/remote_runtime.go @@ -56,7 +56,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) ( ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout) defer cancel() - conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithDialer(dailer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) + conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dailer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize))) if err != nil { klog.Errorf("Connect remote runtime %s failed: %v", addr, err) return nil, err diff --git a/pkg/kubelet/util/util_unix.go b/pkg/kubelet/util/util_unix.go index 9cca42442c9..bcd8090b616 100644 --- a/pkg/kubelet/util/util_unix.go +++ b/pkg/kubelet/util/util_unix.go @@ -19,13 +19,13 @@ limitations under the License. package util import ( + "context" "fmt" "io/ioutil" "net" "net/url" "os" "path/filepath" - "time" "golang.org/x/sys/unix" "k8s.io/klog" @@ -78,8 +78,8 @@ func CreateListener(endpoint string) (net.Listener, error) { return l, nil } -// GetAddressAndDialer returns the address parsed from the given endpoint and a dialer. -func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { +// GetAddressAndDialer returns the address parsed from the given endpoint and a context dialer. +func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error) { protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol) if err != nil { return "", nil, err @@ -91,8 +91,8 @@ func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout tim return addr, dial, nil } -func dial(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout(unixProtocol, addr, timeout) +func dial(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, unixProtocol, addr) } func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) { diff --git a/pkg/kubelet/util/util_unsupported.go b/pkg/kubelet/util/util_unsupported.go index 6e2ccb391e4..dbf86a5a43b 100644 --- a/pkg/kubelet/util/util_unsupported.go +++ b/pkg/kubelet/util/util_unsupported.go @@ -19,6 +19,7 @@ limitations under the License. package util import ( + "context" "fmt" "net" "time" @@ -29,8 +30,8 @@ func CreateListener(endpoint string) (net.Listener, error) { return nil, fmt.Errorf("CreateListener is unsupported in this build") } -// GetAddressAndDialer returns the address parsed from the given endpoint and a dialer. -func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { +// GetAddressAndDialer returns the address parsed from the given endpoint and a context dialer. +func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error) { return "", nil, fmt.Errorf("GetAddressAndDialer is unsupported in this build") } diff --git a/pkg/kubelet/util/util_windows.go b/pkg/kubelet/util/util_windows.go index 99413a8adf0..b0aec540e3e 100644 --- a/pkg/kubelet/util/util_windows.go +++ b/pkg/kubelet/util/util_windows.go @@ -19,6 +19,7 @@ limitations under the License. package util import ( + "context" "fmt" "net" "net/url" @@ -53,8 +54,8 @@ func CreateListener(endpoint string) (net.Listener, error) { } } -// GetAddressAndDialer returns the address parsed from the given endpoint and a dialer. -func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { +// GetAddressAndDialer returns the address parsed from the given endpoint and a context dialer. +func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error) { protocol, addr, err := parseEndpoint(endpoint) if err != nil { return "", nil, err @@ -71,12 +72,12 @@ func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout tim return "", nil, fmt.Errorf("only support tcp and npipe endpoint") } -func tcpDial(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout(tcpProtocol, addr, timeout) +func tcpDial(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, tcpProtocol, addr) } -func npipeDial(addr string, timeout time.Duration) (net.Conn, error) { - return winio.DialPipe(addr, &timeout) +func npipeDial(ctx context.Context, addr string) (net.Conn, error) { + return winio.DialPipeContext(ctx, addr) } func parseEndpoint(endpoint string) (string, string, error) { diff --git a/pkg/volume/csi/csi_client.go b/pkg/volume/csi/csi_client.go index 1dce2eccc4c..c99996cabfe 100644 --- a/pkg/volume/csi/csi_client.go +++ b/pkg/volume/csi/csi_client.go @@ -496,8 +496,8 @@ func newGrpcConn(addr csiAddr) (*grpc.ClientConn, error) { return grpc.Dial( string(addr), grpc.WithInsecure(), - grpc.WithDialer(func(target string, timeout time.Duration) (net.Conn, error) { - return net.Dial(network, target) + grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, network, target) }), ) }