notify readiness when registered plugins are ready

Signed-off-by: Henry Wang <henwang@amazon.com>
This commit is contained in:
Henry Wang
2023-05-26 03:07:40 +00:00
parent ed7c0ebe28
commit 4bfcac85fa
6 changed files with 42 additions and 16 deletions

View File

@@ -218,6 +218,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
initContext.Events = events
initContext.Address = config.GRPC.Address
initContext.TTRPCAddress = config.TTRPC.Address
initContext.RegisterReadiness = s.RegisterReadiness
// load the plugin specific configuration if it is provided
if p.Config != nil {
@@ -293,6 +294,7 @@ type Server struct {
tcpServer *grpc.Server
config *srvconfig.Config
plugins []*plugin.Plugin
ready sync.WaitGroup
}
// ServeGRPC provides the containerd grpc APIs on the provided listener
@@ -370,6 +372,17 @@ func (s *Server) Stop() {
}
}
func (s *Server) RegisterReadiness() func() {
s.ready.Add(1)
return func() {
s.ready.Done()
}
}
func (s *Server) Wait() {
s.ready.Wait()
}
// LoadPlugins loads all plugins into containerd and generates an ordered graph
// of all plugins.
func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Registration, error) {