From 353557f63866fcfae9d4e4867e7db53d76381a84 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Mon, 4 Mar 2019 15:17:04 +0200 Subject: [PATCH] Keep retry registering node controller with RegistryServer Instead of exiting with error, driver has to wait and retry 'node controller' registration till the registry server up and registration get succeed. FIXES: #182 Signed-off-by: Amarnath Valluri --- pkg/pmem-csi-driver/pmem-csi-driver.go | 44 ++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/pkg/pmem-csi-driver/pmem-csi-driver.go b/pkg/pmem-csi-driver/pmem-csi-driver.go index eceee980fd..328fe2ab7e 100644 --- a/pkg/pmem-csi-driver/pmem-csi-driver.go +++ b/pkg/pmem-csi-driver/pmem-csi-driver.go @@ -177,9 +177,8 @@ func (pmemd *pmemDriver) Run() error { return err } } - if err := pmemd.registerNodeController(); err != nil { - return err - } + go pmemd.registerNodeController() + } else /* if pmemd.cfg.Mode == Unified */ { if err := s.Start(pmemd.cfg.Endpoint, pmemd.serverTLSConfig, ids, cs, ns); err != nil { return err @@ -193,34 +192,39 @@ func (pmemd *pmemDriver) Run() error { return nil } -func (pmemd *pmemDriver) registerNodeController() error { - fmt.Printf("Connecting to Registry at : %s\n", pmemd.cfg.RegistryEndpoint) +func (pmemd *pmemDriver) registerNodeController() { var err error var conn *grpc.ClientConn + req := registry.RegisterControllerRequest{ + NodeId: pmemd.cfg.NodeID, + Endpoint: pmemd.cfg.ControllerEndpoint, + } + for { + glog.Infof("Connecting to registry server at: %s\n", pmemd.cfg.RegistryEndpoint) conn, err = pmemgrpc.Connect(pmemd.cfg.RegistryEndpoint, pmemd.clientTLSConfig, connectionTimeout) if err == nil { - glog.Info("Connected to RegistryServer!!!") break } /* TODO: Retry loop */ - glog.Infof("Failed to connect RegistryServer : %s, retrying after 10 seconds...", err.Error()) - time.Sleep(10 * time.Second) + glog.Infof("Failed to connect registry server: %s, retrying after %v seconds...", err.Error(), retryTimeout.Seconds()) + time.Sleep(retryTimeout) } - client := registry.NewRegistryClient(conn) - req := registry.RegisterControllerRequest{ - NodeId: pmemd.cfg.NodeID, - Endpoint: pmemd.cfg.ControllerEndpoint, - } - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - defer cancel() - - if _, err = client.RegisterController(ctx, &req); err != nil { - return fmt.Errorf("Fail to register with server at '%s' : %s", pmemd.cfg.RegistryEndpoint, err.Error()) + for { + client := registry.NewRegistryClient(conn) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + + glog.Info("Registering controller...") + if _, err = client.RegisterController(ctx, &req); err != nil { + glog.Infof("Failed to register: %s, retrying after %v seconds...", err.Error(), retryTimeout.Seconds()) + time.Sleep(retryTimeout) + } else { + break + } } - - return nil + glog.Info("Registration success!!!") } func newDeviceManager(dmType string) (pmdmanager.PmemDeviceManager, error) {