@@ -50,6 +50,7 @@ import (
5050 "github.com/pkg/errors"
5151 bolt "go.etcd.io/bbolt"
5252 "google.golang.org/grpc"
53+ "google.golang.org/grpc/credentials"
5354)
5455
5556// CreateTopLevelDirectories creates the top-level root and state directories.
@@ -81,7 +82,6 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
8182 if err != nil {
8283 return nil , err
8384 }
84-
8585 serverOpts := []grpc.ServerOption {
8686 grpc .UnaryInterceptor (grpc_prometheus .UnaryServerInterceptor ),
8787 grpc .StreamInterceptor (grpc_prometheus .StreamServerInterceptor ),
@@ -96,12 +96,26 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
9696 if err != nil {
9797 return nil , err
9898 }
99- grpcServer := grpc .NewServer (serverOpts ... )
99+ tcpServerOpts := serverOpts
100+ if config .GRPC .TCPTLSCert != "" {
101+ log .G (ctx ).Info ("setting up tls on tcp GRPC services..." )
102+ creds , err := credentials .NewServerTLSFromFile (config .GRPC .TCPTLSCert , config .GRPC .TCPTLSKey )
103+ if err != nil {
104+ return nil , err
105+ }
106+ tcpServerOpts = append (tcpServerOpts , grpc .Creds (creds ))
107+ }
100108 var (
109+ grpcServer = grpc .NewServer (serverOpts ... )
110+ hrpc = grpc .NewServer (tcpServerOpts ... )
111+
101112 grpcServices []plugin.Service
113+ tcpServices []plugin.TCPService
102114 ttrpcServices []plugin.TTRPCService
103- s = & Server {
115+
116+ s = & Server {
104117 grpcServer : grpcServer ,
118+ hrpc : hrpc ,
105119 ttrpcServer : ttrpcServer ,
106120 events : exchange .NewExchange (),
107121 config : config ,
@@ -151,6 +165,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
151165 if src , ok := instance .(plugin.TTRPCService ); ok {
152166 ttrpcServices = append (ttrpcServices , src )
153167 }
168+ if service , ok := instance .(plugin.TCPService ); ok {
169+ tcpServices = append (tcpServices , service )
170+ }
171+
154172 s .plugins = append (s .plugins , result )
155173 }
156174 // register services after all plugins have been initialized
@@ -164,13 +182,19 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
164182 return nil , err
165183 }
166184 }
185+ for _ , service := range tcpServices {
186+ if err := service .RegisterTCP (hrpc ); err != nil {
187+ return nil , err
188+ }
189+ }
167190 return s , nil
168191}
169192
170193// Server is the containerd main daemon
171194type Server struct {
172195 grpcServer * grpc.Server
173196 ttrpcServer * ttrpc.Server
197+ hrpc * grpc.Server
174198 events * exchange.Exchange
175199 config * srvconfig.Config
176200 plugins []* plugin.Plugin
@@ -201,6 +225,12 @@ func (s *Server) ServeMetrics(l net.Listener) error {
201225 return trapClosedConnErr (http .Serve (l , m ))
202226}
203227
228+ // ServeTCP allows services to serve over tcp
229+ func (s * Server ) ServeTCP (l net.Listener ) error {
230+ grpc_prometheus .Register (s .hrpc )
231+ return trapClosedConnErr (s .hrpc .Serve (l ))
232+ }
233+
204234// ServeDebug provides a debug endpoint
205235func (s * Server ) ServeDebug (l net.Listener ) error {
206236 // don't use the default http server mux to make sure nothing gets registered
0 commit comments