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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-02-08 17:55:18 +05:30 committed by mergify[bot]
parent cfb6abc067
commit ee0576278f
3 changed files with 29 additions and 12 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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)