Update plugin load and snapshot service
Allow plugins to be mapped and returned by their ID. Add skip plugin to allow plugins to decide whether they should be loaded. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -17,11 +17,6 @@ type Config struct {
|
||||
Debug Debug `toml:"debug"`
|
||||
// Metrics and monitoring settings
|
||||
Metrics MetricsConfig `toml:"metrics"`
|
||||
// Snapshotter specifies which snapshot driver to use
|
||||
Snapshotter string `toml:"snapshotter"`
|
||||
// Differ specifies which differ to use. Differ is tightly coupled with the snapshotter
|
||||
// so not all combinations may work.
|
||||
Differ string `toml:"differ"`
|
||||
// Plugins provides plugin specific configuration for the initialization of a plugin
|
||||
Plugins map[string]toml.Primitive `toml:"plugins"`
|
||||
// Enable containerd as a subreaper
|
||||
|
||||
@@ -55,14 +55,10 @@ func New(ctx context.Context, config *Config) (*Server, error) {
|
||||
rpc: rpc,
|
||||
emitter: events.NewEmitter(),
|
||||
}
|
||||
initialized = make(map[plugin.PluginType][]interface{})
|
||||
initialized = make(map[plugin.PluginType]map[string]interface{})
|
||||
)
|
||||
for _, p := range plugins {
|
||||
id := p.URI()
|
||||
if !shouldLoadPlugin(p, config) {
|
||||
log.G(ctx).WithField("type", p.Type).Infof("skip loading plugin %q...", id)
|
||||
continue
|
||||
}
|
||||
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
|
||||
|
||||
initContext := plugin.NewContext(
|
||||
@@ -83,10 +79,21 @@ func New(ctx context.Context, config *Config) (*Server, error) {
|
||||
}
|
||||
instance, err := p.Init(initContext)
|
||||
if err != nil {
|
||||
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
|
||||
if plugin.IsSkipPlugin(err) {
|
||||
log.G(ctx).WithField("type", p.Type).Infof("skip loading plugin %q...", id)
|
||||
} else {
|
||||
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
|
||||
}
|
||||
continue
|
||||
}
|
||||
initialized[p.Type] = append(initialized[p.Type], instance)
|
||||
|
||||
if types, ok := initialized[p.Type]; ok {
|
||||
types[p.ID] = instance
|
||||
} else {
|
||||
initialized[p.Type] = map[string]interface{}{
|
||||
p.ID: instance,
|
||||
}
|
||||
}
|
||||
// check for grpc services that should be registered with the server
|
||||
if service, ok := instance.(plugin.Service); ok {
|
||||
services = append(services, service)
|
||||
@@ -170,17 +177,6 @@ func loadPlugins(config *Config) ([]*plugin.Registration, error) {
|
||||
return plugin.Graph(), nil
|
||||
}
|
||||
|
||||
func shouldLoadPlugin(p *plugin.Registration, config *Config) bool {
|
||||
switch p.Type {
|
||||
case plugin.SnapshotPlugin:
|
||||
return p.URI() == config.Snapshotter
|
||||
case plugin.DiffPlugin:
|
||||
return p.URI() == config.Differ
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func interceptor(
|
||||
ctx context.Context,
|
||||
req interface{},
|
||||
|
||||
Reference in New Issue
Block a user