Skip to content

Commit 8a5244e

Browse files
author
houyuxi
committed
fix(server): replace deprecated grpc.DialContext with grpc.NewClient
1 parent d293ca2 commit 8a5244e

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

internal/server/register.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"google.golang.org/grpc"
12+
"google.golang.org/grpc/connectivity"
1213
"google.golang.org/grpc/credentials/insecure"
1314
"k8s.io/klog/v2"
1415
"k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
@@ -136,17 +137,19 @@ func (ps *PluginServer) registerKubelet() error {
136137
func (ps *PluginServer) dial(unixSocketPath string, timeout time.Duration) (*grpc.ClientConn, error) {
137138
ctx, cancel := context.WithTimeout(context.Background(), timeout)
138139
defer cancel()
139-
c, err := grpc.DialContext(ctx, unixSocketPath,
140+
c, _ := grpc.NewClient(unixSocketPath,
140141
grpc.WithTransportCredentials(insecure.NewCredentials()),
141-
grpc.WithBlock(),
142142
grpc.WithContextDialer(func(ctx2 context.Context, addr string) (net.Conn, error) {
143143
var d net.Dialer
144144
return d.DialContext(ctx2, "unix", addr)
145145
}),
146146
)
147147

148-
if err != nil {
149-
return nil, err
148+
// NewClient is non-blocking; block here to match the original WithBlock behaviour.
149+
if !c.WaitForStateChange(ctx, connectivity.Ready) {
150+
c.Close()
151+
return nil, ctx.Err()
150152
}
153+
151154
return c, nil
152155
}

0 commit comments

Comments
 (0)