From 958ed1db8a336101e15b1faf991d10e5f7fa7e01 Mon Sep 17 00:00:00 2001 From: adrianc Date: Wed, 24 Jul 2024 13:22:32 +0300 Subject: [PATCH] remove waiting for grpc server to be ready WithBlock() dial option is deprecated, recommendation is to let the caller handle failures with retry see[1] this change is needed to sort out lint issues in ci. [1] https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#especially-bad-using-deprecated-dialoptions Signed-off-by: adrianc --- pkg/resources/server.go | 31 +++---------------------------- pkg/resources/testing.go | 6 +++--- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/pkg/resources/server.go b/pkg/resources/server.go index 4891f0941..5951d0cd9 100644 --- a/pkg/resources/server.go +++ b/pkg/resources/server.go @@ -49,9 +49,8 @@ type resourceServer struct { } const ( - rsWatchInterval = 5 * time.Second - serverStartTimeout = 5 * time.Second - unix = "unix" + rsWatchInterval = 5 * time.Second + unix = "unix" ) // NewResourceServer returns an instance of ResourceServer @@ -265,6 +264,7 @@ func (rs *resourceServer) Start() error { } pluginapi.RegisterDevicePluginServer(rs.grpcServer, rs) + // start serving from grpcServer go func() { err := rs.grpcServer.Serve(lis) if err != nil { @@ -272,31 +272,6 @@ func (rs *resourceServer) Start() error { } }() - conn, err := grpc.NewClient( - unix+":"+rs.sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) - if err != nil { - glog.Errorf("error. unable to create grpc client for test connection with %s gRPC server: %v", resourceName, err) - return err - } - - // Wait for server to start by launching a blocking connection - connChan := make(chan interface{}, 1) - go func() { - conn.Connect() - connChan <- true - }() - - ctx, cancel := context.WithTimeout(context.TODO(), serverStartTimeout) - defer cancel() - select { - case <-ctx.Done(): - glog.Errorf("error. unable to establish test connection with %s gRPC server: %v", resourceName, err) - conn.Close() - return err - case <-connChan: - glog.Infof("%s device plugin endpoint started serving", resourceName) - } - rs.triggerUpdate() if !rs.pluginWatch { diff --git a/pkg/resources/testing.go b/pkg/resources/testing.go index 3763baa6a..c36222469 100644 --- a/pkg/resources/testing.go +++ b/pkg/resources/testing.go @@ -46,7 +46,7 @@ func createFakeRegistrationServer( func (s *fakeRegistrationServer) dial() (registerapi.RegistrationClient, *grpc.ClientConn, error) { sockPath := path.Join(s.sockDir, s.pluginEndpoint) c, err := grpc.NewClient( - "unix:"+sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + "unix:"+sockPath, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, nil, fmt.Errorf("failed to dial socket %s, err: %v", sockPath, err) @@ -57,7 +57,7 @@ func (s *fakeRegistrationServer) dial() (registerapi.RegistrationClient, *grpc.C func (s *fakeRegistrationServer) getInfo( ctx context.Context, client registerapi.RegistrationClient) (*registerapi.PluginInfo, error) { - infoResp, err := client.GetInfo(ctx, ®isterapi.InfoRequest{}) + infoResp, err := client.GetInfo(ctx, ®isterapi.InfoRequest{}, grpc.WaitForReady(true)) if err != nil { return infoResp, fmt.Errorf("failed to get plugin info using RPC GetInfo, err: %v", err) } @@ -75,7 +75,7 @@ func (s *fakeRegistrationServer) notifyPlugin( Error: errStr, } - if _, err := client.NotifyRegistrationStatus(ctx, status); err != nil { + if _, err := client.NotifyRegistrationStatus(ctx, status, grpc.WaitForReady(true)); err != nil { return errors.Wrap(err, errStr) }