From ee0576278f113ddca7e1296c9bf7fe8ec695fb59 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 8 Feb 2021 17:55:18 +0530 Subject: [PATCH] cleanup: move servers to a new struct For future enhancments like adding more servers. Moving the list of servers to a new structure. Signed-off-by: Madhu Rajanna --- internal/cephfs/driver.go | 7 ++++++- internal/csi-common/server.go | 27 +++++++++++++++++---------- internal/rbd/driver.go | 7 ++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/cephfs/driver.go b/internal/cephfs/driver.go index 288f4911d..2523cf46e 100644 --- a/internal/cephfs/driver.go +++ b/internal/cephfs/driver.go @@ -152,7 +152,12 @@ func (fs *Driver) Run(conf *util.Config) { } server := csicommon.NewNonBlockingGRPCServer() - server.Start(conf.Endpoint, conf.HistogramOption, fs.is, fs.cs, fs.ns, conf.EnableGRPCMetrics) + srv := csicommon.Servers{ + IS: fs.is, + CS: fs.cs, + NS: fs.ns, + } + server.Start(conf.Endpoint, conf.HistogramOption, srv, conf.EnableGRPCMetrics) if conf.EnableGRPCMetrics { util.WarningLogMsg("EnableGRPCMetrics is deprecated") go util.StartMetricsServer(conf) diff --git a/internal/csi-common/server.go b/internal/csi-common/server.go index b35852a32..1ef6d0a4e 100644 --- a/internal/csi-common/server.go +++ b/internal/csi-common/server.go @@ -36,7 +36,7 @@ import ( // NonBlockingGRPCServer defines Non blocking GRPC server interfaces. type NonBlockingGRPCServer interface { // Start services at the endpoint - Start(endpoint, hstOptions string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, metrics bool) + Start(endpoint, hstOptions string, srv Servers, metrics bool) // Waits for the service to stop Wait() // Stops the service gracefully @@ -45,6 +45,13 @@ type NonBlockingGRPCServer interface { ForceStop() } +// Servers holds the list of servers. +type Servers struct { + IS csi.IdentityServer + CS csi.ControllerServer + NS csi.NodeServer +} + // NewNonBlockingGRPCServer return non-blocking GRPC. func NewNonBlockingGRPCServer() NonBlockingGRPCServer { return &nonBlockingGRPCServer{} @@ -57,9 +64,9 @@ type nonBlockingGRPCServer struct { } // Start start service on endpoint. -func (s *nonBlockingGRPCServer) Start(endpoint, hstOptions string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, metrics bool) { +func (s *nonBlockingGRPCServer) Start(endpoint, hstOptions string, srv Servers, metrics bool) { s.wg.Add(1) - go s.serve(endpoint, hstOptions, ids, cs, ns, metrics) + go s.serve(endpoint, hstOptions, srv, metrics) } // Wait blocks until the WaitGroup counter. @@ -77,7 +84,7 @@ func (s *nonBlockingGRPCServer) ForceStop() { s.server.Stop() } -func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, metrics bool) { +func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, srv Servers, metrics bool) { proto, addr, err := parseEndpoint(endpoint) if err != nil { klog.Fatal(err.Error()) @@ -106,14 +113,14 @@ func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, ids csi.Ident server := grpc.NewServer(opts...) s.server = server - if ids != nil { - csi.RegisterIdentityServer(server, ids) + if srv.IS != nil { + csi.RegisterIdentityServer(server, srv.IS) } - if cs != nil { - csi.RegisterControllerServer(server, cs) + if srv.CS != nil { + csi.RegisterControllerServer(server, srv.CS) } - if ns != nil { - csi.RegisterNodeServer(server, ns) + if srv.NS != nil { + csi.RegisterNodeServer(server, srv.NS) } util.DefaultLog("Listening for connections on address: %#v", listener.Addr()) if metrics { diff --git a/internal/rbd/driver.go b/internal/rbd/driver.go index d4a36f6cd..fe0927e83 100644 --- a/internal/rbd/driver.go +++ b/internal/rbd/driver.go @@ -168,7 +168,12 @@ func (r *Driver) Run(conf *util.Config) { } s := csicommon.NewNonBlockingGRPCServer() - s.Start(conf.Endpoint, conf.HistogramOption, r.ids, r.cs, r.ns, conf.EnableGRPCMetrics) + srv := csicommon.Servers{ + IS: r.ids, + CS: r.cs, + NS: r.ns, + } + s.Start(conf.Endpoint, conf.HistogramOption, srv, conf.EnableGRPCMetrics) if conf.EnableGRPCMetrics { util.WarningLogMsg("EnableGRPCMetrics is deprecated") go util.StartMetricsServer(conf)