From f24fc62d02173cd1196eca4374f2872de845edaa Mon Sep 17 00:00:00 2001 From: xuehaipeng <69886171+xuehaipeng@users.noreply.github.com> Date: Fri, 22 Jul 2022 11:38:16 +0800 Subject: [PATCH] fix: deprecated grpc dial option (#1380) * fix: deprecated grpc dial option Signed-off-by: xuehaipeng * fix: deprecated grpc dial option Signed-off-by: xuehaipeng --- .../image-cri-shim/pkg/shim/client/clinet.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/staging/src/github.com/labring/image-cri-shim/pkg/shim/client/clinet.go b/staging/src/github.com/labring/image-cri-shim/pkg/shim/client/clinet.go index bebdd8d76..f42d7dbe5 100644 --- a/staging/src/github.com/labring/image-cri-shim/pkg/shim/client/clinet.go +++ b/staging/src/github.com/labring/image-cri-shim/pkg/shim/client/clinet.go @@ -16,6 +16,7 @@ package client import ( + "context" "fmt" "net" "os" @@ -26,6 +27,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/credentials/insecure" api "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) @@ -155,11 +157,16 @@ func (c *client) connect(kind, socket string, options ConnectOptions) (*grpc.Cli } dialOpts := []grpc.DialOption{ - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), grpc.FailOnNonTempDialError(true), - grpc.WithDialer(func(socket string, timeout time.Duration) (net.Conn, error) { - conn, err := net.DialTimeout("unix", socket, timeout) + grpc.WithContextDialer(func(ctx context.Context, socket string) (net.Conn, error) { + var conn net.Conn + if deadLine, ok := ctx.Deadline(); ok { + conn, err = net.DialTimeout("unix", socket, time.Until(deadLine)) + } else { + conn, err = net.Dial("unix", socket) + } if err != nil { return conn, err }