notify readiness when registered plugins are ready
Signed-off-by: Henry Wang <henwang@amazon.com>
This commit is contained in:
@@ -54,6 +54,7 @@ func init() {
|
||||
}
|
||||
|
||||
func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
ready := ic.RegisterReadiness()
|
||||
ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()}
|
||||
ic.Meta.Exports = map[string]string{"CRIVersion": constants.CRIVersion}
|
||||
ctx := ic.Context
|
||||
@@ -99,7 +100,7 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := s.Run(); err != nil {
|
||||
if err := s.Run(ready); err != nil {
|
||||
log.G(ctx).WithError(err).Fatal("Failed to run CRI service")
|
||||
}
|
||||
// TODO(random-liu): Whether and how we can stop containerd.
|
||||
|
||||
@@ -63,7 +63,7 @@ type CRIService interface {
|
||||
// Closer is used by containerd to gracefully stop cri service.
|
||||
io.Closer
|
||||
|
||||
Run() error
|
||||
Run(ready func()) error
|
||||
|
||||
Register(*grpc.Server) error
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func (c *criService) RegisterTCP(s *grpc.Server) error {
|
||||
}
|
||||
|
||||
// Run starts the CRI service.
|
||||
func (c *criService) Run() error {
|
||||
func (c *criService) Run(ready func()) error {
|
||||
log.L.Info("Start subscribing containerd event")
|
||||
c.eventMonitor.subscribe(c.client)
|
||||
|
||||
@@ -291,6 +291,7 @@ func (c *criService) Run() error {
|
||||
|
||||
// Set the server as initialized. GRPC services could start serving traffic.
|
||||
c.initialized.Store(true)
|
||||
ready()
|
||||
|
||||
var eventMonitorErr, streamServerErr, cniNetConfMonitorErr error
|
||||
// Stop the whole CRI service if any of the critical service exits.
|
||||
|
||||
@@ -62,7 +62,7 @@ type CRIService interface {
|
||||
// Closer is used by containerd to gracefully stop cri service.
|
||||
io.Closer
|
||||
|
||||
Run() error
|
||||
Run(ready func()) error
|
||||
|
||||
Register(*grpc.Server) error
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func (c *criService) RegisterTCP(s *grpc.Server) error {
|
||||
}
|
||||
|
||||
// Run starts the CRI service.
|
||||
func (c *criService) Run() error {
|
||||
func (c *criService) Run(ready func()) error {
|
||||
log.L.Info("Start subscribing containerd event")
|
||||
c.eventMonitor.subscribe(c.client)
|
||||
|
||||
@@ -266,6 +266,7 @@ func (c *criService) Run() error {
|
||||
|
||||
// Set the server as initialized. GRPC services could start serving traffic.
|
||||
c.initialized.Store(true)
|
||||
ready()
|
||||
|
||||
var eventMonitorErr, streamServerErr, cniNetConfMonitorErr error
|
||||
// Stop the whole CRI service if any of the critical service exits.
|
||||
|
||||
Reference in New Issue
Block a user