From 9c847fc4d6d5f86ddc17e7717e9357e4b0a54caa Mon Sep 17 00:00:00 2001 From: vikaschoudhary16 Date: Tue, 16 Jan 2018 01:04:18 -0500 Subject: [PATCH] Call Dial in blocking mode --- pkg/kubelet/cm/deviceplugin/device_plugin_stub.go | 14 ++++++-------- pkg/kubelet/cm/deviceplugin/endpoint.go | 5 +++-- pkg/kubelet/cm/deviceplugin/manager_test.go | 3 --- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pkg/kubelet/cm/deviceplugin/device_plugin_stub.go b/pkg/kubelet/cm/deviceplugin/device_plugin_stub.go index 08dcd5a992f..a80f16b9d19 100644 --- a/pkg/kubelet/cm/deviceplugin/device_plugin_stub.go +++ b/pkg/kubelet/cm/deviceplugin/device_plugin_stub.go @@ -86,14 +86,11 @@ func (m *Stub) Start() error { pluginapi.RegisterDevicePluginServer(m.server, m) go m.server.Serve(sock) - // Wait till grpc server is ready. - for i := 0; i < 10; i++ { - services := m.server.GetServiceInfo() - if len(services) > 0 { - break - } - time.Sleep(1 * time.Second) + _, conn, err := dial(m.socket) + if err != nil { + return err } + conn.Close() log.Println("Starting to serve on", m.socket) return nil @@ -109,7 +106,8 @@ func (m *Stub) Stop() error { // Register registers the device plugin for the given resourceName with Kubelet. func (m *Stub) Register(kubeletEndpoint, resourceName string) error { - conn, err := grpc.Dial(kubeletEndpoint, grpc.WithInsecure(), + conn, err := grpc.Dial(kubeletEndpoint, grpc.WithInsecure(), grpc.WithBlock(), + grpc.WithTimeout(10*time.Second), grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) })) diff --git a/pkg/kubelet/cm/deviceplugin/endpoint.go b/pkg/kubelet/cm/deviceplugin/endpoint.go index 523922d9dc0..f2fd8be9896 100644 --- a/pkg/kubelet/cm/deviceplugin/endpoint.go +++ b/pkg/kubelet/cm/deviceplugin/endpoint.go @@ -186,9 +186,10 @@ func (e *endpointImpl) stop() { e.clientConn.Close() } -// dial establishes the gRPC communication with the registered device plugin. +// dial establishes the gRPC communication with the registered device plugin. https://godoc.org/google.golang.org/grpc#Dial func dial(unixSocketPath string) (pluginapi.DevicePluginClient, *grpc.ClientConn, error) { - c, err := grpc.Dial(unixSocketPath, grpc.WithInsecure(), + c, err := grpc.Dial(unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(), + grpc.WithTimeout(10*time.Second), grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) }), diff --git a/pkg/kubelet/cm/deviceplugin/manager_test.go b/pkg/kubelet/cm/deviceplugin/manager_test.go index 124f690acf7..783c2d48757 100644 --- a/pkg/kubelet/cm/deviceplugin/manager_test.go +++ b/pkg/kubelet/cm/deviceplugin/manager_test.go @@ -497,9 +497,6 @@ type TestResource struct { func TestPodContainerDeviceAllocation(t *testing.T) { flag.Set("alsologtostderr", fmt.Sprintf("%t", true)) - var logLevel string - flag.StringVar(&logLevel, "logLevel", "4", "test") - flag.Lookup("v").Value.Set(logLevel) res1 := TestResource{ resourceName: "domain1.com/resource1", resourceQuantity: *resource.NewQuantity(int64(2), resource.DecimalSI),