Commit 9c847fc4 authored by vikaschoudhary16's avatar vikaschoudhary16

Call Dial in blocking mode

parent ffd5fca9
...@@ -86,14 +86,11 @@ func (m *Stub) Start() error { ...@@ -86,14 +86,11 @@ func (m *Stub) Start() error {
pluginapi.RegisterDevicePluginServer(m.server, m) pluginapi.RegisterDevicePluginServer(m.server, m)
go m.server.Serve(sock) go m.server.Serve(sock)
// Wait till grpc server is ready. _, conn, err := dial(m.socket)
for i := 0; i < 10; i++ { if err != nil {
services := m.server.GetServiceInfo() return err
if len(services) > 0 {
break
}
time.Sleep(1 * time.Second)
} }
conn.Close()
log.Println("Starting to serve on", m.socket) log.Println("Starting to serve on", m.socket)
return nil return nil
...@@ -109,7 +106,8 @@ func (m *Stub) Stop() error { ...@@ -109,7 +106,8 @@ func (m *Stub) Stop() error {
// Register registers the device plugin for the given resourceName with Kubelet. // Register registers the device plugin for the given resourceName with Kubelet.
func (m *Stub) Register(kubeletEndpoint, resourceName string) error { 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) { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout) return net.DialTimeout("unix", addr, timeout)
})) }))
......
...@@ -186,9 +186,10 @@ func (e *endpointImpl) stop() { ...@@ -186,9 +186,10 @@ func (e *endpointImpl) stop() {
e.clientConn.Close() 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) { 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) { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout) return net.DialTimeout("unix", addr, timeout)
}), }),
......
...@@ -497,9 +497,6 @@ type TestResource struct { ...@@ -497,9 +497,6 @@ type TestResource struct {
func TestPodContainerDeviceAllocation(t *testing.T) { func TestPodContainerDeviceAllocation(t *testing.T) {
flag.Set("alsologtostderr", fmt.Sprintf("%t", true)) flag.Set("alsologtostderr", fmt.Sprintf("%t", true))
var logLevel string
flag.StringVar(&logLevel, "logLevel", "4", "test")
flag.Lookup("v").Value.Set(logLevel)
res1 := TestResource{ res1 := TestResource{
resourceName: "domain1.com/resource1", resourceName: "domain1.com/resource1",
resourceQuantity: *resource.NewQuantity(int64(2), resource.DecimalSI), resourceQuantity: *resource.NewQuantity(int64(2), resource.DecimalSI),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment