Merge pull request #3197 from Random-Liu/add-required-plugins
Add support for required plugins.
This commit is contained in:
commit
5703f415c6
@ -30,5 +30,7 @@ func defaultConfig() *srvconfig.Config {
|
|||||||
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
||||||
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
||||||
},
|
},
|
||||||
|
DisabledPlugins: []string{},
|
||||||
|
RequiredPlugins: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,5 +34,7 @@ func defaultConfig() *srvconfig.Config {
|
|||||||
Level: "info",
|
Level: "info",
|
||||||
Address: defaults.DefaultDebugAddress,
|
Address: defaults.DefaultDebugAddress,
|
||||||
},
|
},
|
||||||
|
DisabledPlugins: []string{},
|
||||||
|
RequiredPlugins: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,5 +30,7 @@ func defaultConfig() *srvconfig.Config {
|
|||||||
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
||||||
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
||||||
},
|
},
|
||||||
|
DisabledPlugins: []string{},
|
||||||
|
RequiredPlugins: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ type Config struct {
|
|||||||
// DisabledPlugins are IDs of plugins to disable. Disabled plugins won't be
|
// DisabledPlugins are IDs of plugins to disable. Disabled plugins won't be
|
||||||
// initialized and started.
|
// initialized and started.
|
||||||
DisabledPlugins []string `toml:"disabled_plugins"`
|
DisabledPlugins []string `toml:"disabled_plugins"`
|
||||||
|
// RequiredPlugins are IDs of required plugins. Containerd exits if any
|
||||||
|
// required plugin doesn't exist or fails to be initialized or started.
|
||||||
|
RequiredPlugins []string `toml:"required_plugins"`
|
||||||
// Plugins provides plugin specific configuration for the initialization of a plugin
|
// Plugins provides plugin specific configuration for the initialization of a plugin
|
||||||
Plugins map[string]toml.Primitive `toml:"plugins"`
|
Plugins map[string]toml.Primitive `toml:"plugins"`
|
||||||
// OOMScore adjust the containerd's oom score
|
// OOMScore adjust the containerd's oom score
|
||||||
|
@ -107,7 +107,11 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
initialized = plugin.NewPluginSet()
|
initialized = plugin.NewPluginSet()
|
||||||
|
required = make(map[string]struct{})
|
||||||
)
|
)
|
||||||
|
for _, r := range config.RequiredPlugins {
|
||||||
|
required[r] = struct{}{}
|
||||||
|
}
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
id := p.URI()
|
id := p.URI()
|
||||||
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
|
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
|
||||||
@ -142,8 +146,12 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
} else {
|
} else {
|
||||||
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
|
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
|
||||||
}
|
}
|
||||||
|
if _, ok := required[p.ID]; ok {
|
||||||
|
return nil, errors.Wrapf(err, "load required plugin %s", id)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
delete(required, p.ID)
|
||||||
// check for grpc services that should be registered with the server
|
// check for grpc services that should be registered with the server
|
||||||
if src, ok := instance.(plugin.Service); ok {
|
if src, ok := instance.(plugin.Service); ok {
|
||||||
grpcServices = append(grpcServices, src)
|
grpcServices = append(grpcServices, src)
|
||||||
@ -153,6 +161,14 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
|||||||
}
|
}
|
||||||
s.plugins = append(s.plugins, result)
|
s.plugins = append(s.plugins, result)
|
||||||
}
|
}
|
||||||
|
if len(required) != 0 {
|
||||||
|
var missing []string
|
||||||
|
for id := range required {
|
||||||
|
missing = append(missing, id)
|
||||||
|
}
|
||||||
|
return nil, errors.Errorf("required plugin %s not included", missing)
|
||||||
|
}
|
||||||
|
|
||||||
// register services after all plugins have been initialized
|
// register services after all plugins have been initialized
|
||||||
for _, service := range grpcServices {
|
for _, service := range grpcServices {
|
||||||
if err := service.Register(grpcServer); err != nil {
|
if err := service.Register(grpcServer); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user