@@ -19,20 +19,15 @@ package plugin
1919import (
2020 "context"
2121 "fmt"
22- "path/filepath"
2322
24- "github.com/containerd/containerd/errdefs"
25- ocispec "github.com/opencontainers/image-spec/specs-go/v1"
23+ imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2624)
2725
2826// InitContext is used for plugin initialization
2927type InitContext struct {
3028 Context context.Context
31- Root string
32- State string
29+ Properties map [string ]string
3330 Config interface {}
34- Address string
35- TTRPCAddress string
3631 RegisterReadiness func () func ()
3732
3833 // Meta is metadata plugins can fill in at init
@@ -42,11 +37,13 @@ type InitContext struct {
4237}
4338
4439// NewContext returns a new plugin InitContext
45- func NewContext (ctx context.Context , r * Registration , plugins * Set , root , state string ) * InitContext {
40+ func NewContext (ctx context.Context , plugins * Set , properties map [string ]string ) * InitContext {
41+ if properties == nil {
42+ properties = map [string ]string {}
43+ }
4644 return & InitContext {
47- Context : ctx ,
48- Root : filepath .Join (root , r .URI ()),
49- State : filepath .Join (state , r .URI ()),
45+ Context : ctx ,
46+ Properties : properties ,
5047 Meta : & Meta {
5148 Exports : map [string ]string {},
5249 },
@@ -62,16 +59,16 @@ func (i *InitContext) Get(t Type) (interface{}, error) {
6259// Meta contains information gathered from the registration and initialization
6360// process.
6461type Meta struct {
65- Platforms []ocispec .Platform // platforms supported by plugin
66- Exports map [string ]string // values exported by plugin
67- Capabilities []string // feature switches for plugin
62+ Platforms []imagespec .Platform // platforms supported by plugin
63+ Exports map [string ]string // values exported by plugin
64+ Capabilities []string // feature switches for plugin
6865}
6966
7067// Plugin represents an initialized plugin, used with an init context.
7168type Plugin struct {
72- Registration * Registration // registration, as initialized
73- Config interface {} // config, as initialized
74- Meta * Meta
69+ Registration Registration // registration, as initialized
70+ Config interface {} // config, as initialized
71+ Meta Meta
7572
7673 instance interface {}
7774 err error // will be set if there was an error initializing the plugin
@@ -115,7 +112,7 @@ func (ps *Set) Add(p *Plugin) error {
115112 } else if _ , idok := byID [p .Registration .ID ]; ! idok {
116113 byID [p .Registration .ID ] = p
117114 } else {
118- return fmt .Errorf ("plugin %v already initialized : %w" , p .Registration .URI (), errdefs . ErrAlreadyExists )
115+ return fmt .Errorf ("plugin add failed for %s : %w" , p .Registration .URI (), ErrPluginInitialized )
119116 }
120117
121118 ps .ordered = append (ps .ordered , p )
@@ -127,7 +124,7 @@ func (ps *Set) Get(t Type) (interface{}, error) {
127124 for _ , v := range ps .byTypeAndID [t ] {
128125 return v .Instance ()
129126 }
130- return nil , fmt .Errorf ("no plugins registered for %s: %w" , t , errdefs . ErrNotFound )
127+ return nil , fmt .Errorf ("no plugins registered for %s: %w" , t , ErrPluginNotFound )
131128}
132129
133130// GetAll returns all initialized plugins
@@ -153,7 +150,7 @@ func (i *InitContext) GetByID(t Type, id string) (interface{}, error) {
153150 }
154151 p , ok := ps [id ]
155152 if ! ok {
156- return nil , fmt .Errorf ("no %s plugins with id %s: %w" , t , id , errdefs . ErrNotFound )
153+ return nil , fmt .Errorf ("no %s plugins with id %s: %w" , t , id , ErrPluginNotFound )
157154 }
158155 return p .Instance ()
159156}
@@ -162,7 +159,7 @@ func (i *InitContext) GetByID(t Type, id string) (interface{}, error) {
162159func (i * InitContext ) GetByType (t Type ) (map [string ]* Plugin , error ) {
163160 p , ok := i .plugins .byTypeAndID [t ]
164161 if ! ok {
165- return nil , fmt .Errorf ("no plugins registered for %s: %w" , t , errdefs . ErrNotFound )
162+ return nil , fmt .Errorf ("no plugins registered for %s: %w" , t , ErrPluginNotFound )
166163 }
167164
168165 return p , nil
0 commit comments