mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-17 18:29:30 +00:00
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:
parent
cfb6abc067
commit
ee0576278f
@ -152,7 +152,12 @@ func (fs *Driver) Run(conf *util.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server := csicommon.NewNonBlockingGRPCServer()
|
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 {
|
if conf.EnableGRPCMetrics {
|
||||||
util.WarningLogMsg("EnableGRPCMetrics is deprecated")
|
util.WarningLogMsg("EnableGRPCMetrics is deprecated")
|
||||||
go util.StartMetricsServer(conf)
|
go util.StartMetricsServer(conf)
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
// NonBlockingGRPCServer defines Non blocking GRPC server interfaces.
|
// NonBlockingGRPCServer defines Non blocking GRPC server interfaces.
|
||||||
type NonBlockingGRPCServer interface {
|
type NonBlockingGRPCServer interface {
|
||||||
// Start services at the endpoint
|
// 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
|
// Waits for the service to stop
|
||||||
Wait()
|
Wait()
|
||||||
// Stops the service gracefully
|
// Stops the service gracefully
|
||||||
@ -45,6 +45,13 @@ type NonBlockingGRPCServer interface {
|
|||||||
ForceStop()
|
ForceStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Servers holds the list of servers.
|
||||||
|
type Servers struct {
|
||||||
|
IS csi.IdentityServer
|
||||||
|
CS csi.ControllerServer
|
||||||
|
NS csi.NodeServer
|
||||||
|
}
|
||||||
|
|
||||||
// NewNonBlockingGRPCServer return non-blocking GRPC.
|
// NewNonBlockingGRPCServer return non-blocking GRPC.
|
||||||
func NewNonBlockingGRPCServer() NonBlockingGRPCServer {
|
func NewNonBlockingGRPCServer() NonBlockingGRPCServer {
|
||||||
return &nonBlockingGRPCServer{}
|
return &nonBlockingGRPCServer{}
|
||||||
@ -57,9 +64,9 @@ type nonBlockingGRPCServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start start service on endpoint.
|
// 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)
|
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.
|
// Wait blocks until the WaitGroup counter.
|
||||||
@ -77,7 +84,7 @@ func (s *nonBlockingGRPCServer) ForceStop() {
|
|||||||
s.server.Stop()
|
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)
|
proto, addr, err := parseEndpoint(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Fatal(err.Error())
|
klog.Fatal(err.Error())
|
||||||
@ -106,14 +113,14 @@ func (s *nonBlockingGRPCServer) serve(endpoint, hstOptions string, ids csi.Ident
|
|||||||
server := grpc.NewServer(opts...)
|
server := grpc.NewServer(opts...)
|
||||||
s.server = server
|
s.server = server
|
||||||
|
|
||||||
if ids != nil {
|
if srv.IS != nil {
|
||||||
csi.RegisterIdentityServer(server, ids)
|
csi.RegisterIdentityServer(server, srv.IS)
|
||||||
}
|
}
|
||||||
if cs != nil {
|
if srv.CS != nil {
|
||||||
csi.RegisterControllerServer(server, cs)
|
csi.RegisterControllerServer(server, srv.CS)
|
||||||
}
|
}
|
||||||
if ns != nil {
|
if srv.NS != nil {
|
||||||
csi.RegisterNodeServer(server, ns)
|
csi.RegisterNodeServer(server, srv.NS)
|
||||||
}
|
}
|
||||||
util.DefaultLog("Listening for connections on address: %#v", listener.Addr())
|
util.DefaultLog("Listening for connections on address: %#v", listener.Addr())
|
||||||
if metrics {
|
if metrics {
|
||||||
|
@ -168,7 +168,12 @@ func (r *Driver) Run(conf *util.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := csicommon.NewNonBlockingGRPCServer()
|
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 {
|
if conf.EnableGRPCMetrics {
|
||||||
util.WarningLogMsg("EnableGRPCMetrics is deprecated")
|
util.WarningLogMsg("EnableGRPCMetrics is deprecated")
|
||||||
go util.StartMetricsServer(conf)
|
go util.StartMetricsServer(conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user