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:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
)
|
||||
|
||||
func NewContext(ctx context.Context, plugins map[PluginType][]interface{}, root, id string) *InitContext {
|
||||
func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface{}, root, id string) *InitContext {
|
||||
return &InitContext{
|
||||
plugins: plugins,
|
||||
Root: filepath.Join(root, id),
|
||||
@@ -23,18 +23,17 @@ type InitContext struct {
|
||||
Config interface{}
|
||||
Emitter *events.Emitter
|
||||
|
||||
plugins map[PluginType][]interface{}
|
||||
plugins map[PluginType]map[string]interface{}
|
||||
}
|
||||
|
||||
func (i *InitContext) Get(t PluginType) (interface{}, error) {
|
||||
p := i.plugins[t]
|
||||
if len(p) == 0 {
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
for _, v := range i.plugins[t] {
|
||||
return v, nil
|
||||
}
|
||||
return p[0], nil
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
}
|
||||
|
||||
func (i *InitContext) GetAll(t PluginType) ([]interface{}, error) {
|
||||
func (i *InitContext) GetAll(t PluginType) (map[string]interface{}, error) {
|
||||
p, ok := i.plugins[t]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
|
||||
Reference in New Issue
Block a user