Comment more packages to pass go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
)
|
||||
|
||||
func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface{}, root, state, id string) *InitContext {
|
||||
// NewContext returns a new plugin InitContext
|
||||
func NewContext(ctx context.Context, plugins map[Type]map[string]interface{}, root, state, id string) *InitContext {
|
||||
return &InitContext{
|
||||
plugins: plugins,
|
||||
Root: filepath.Join(root, id),
|
||||
@@ -18,6 +19,7 @@ func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface
|
||||
}
|
||||
}
|
||||
|
||||
// InitContext is used for plugin inititalization
|
||||
type InitContext struct {
|
||||
Root string
|
||||
State string
|
||||
@@ -26,17 +28,19 @@ type InitContext struct {
|
||||
Config interface{}
|
||||
Events *events.Exchange
|
||||
|
||||
plugins map[PluginType]map[string]interface{}
|
||||
plugins map[Type]map[string]interface{}
|
||||
}
|
||||
|
||||
func (i *InitContext) Get(t PluginType) (interface{}, error) {
|
||||
// Get returns the first plugin by its type
|
||||
func (i *InitContext) Get(t Type) (interface{}, error) {
|
||||
for _, v := range i.plugins[t] {
|
||||
return v, nil
|
||||
}
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
}
|
||||
|
||||
func (i *InitContext) GetAll(t PluginType) (map[string]interface{}, error) {
|
||||
// GetAll returns all plugins with the specific type
|
||||
func (i *InitContext) GetAll(t Type) (map[string]interface{}, error) {
|
||||
p, ok := i.plugins[t]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Differ allows the apply and creation of filesystem diffs between mounts
|
||||
type Differ interface {
|
||||
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
|
||||
DiffMounts(ctx context.Context, lower, upper []mount.Mount, media, ref string) (ocispec.Descriptor, error)
|
||||
|
||||
@@ -9,49 +9,62 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoPluginType = errors.New("plugin: no type")
|
||||
ErrNoPluginID = errors.New("plugin: no id")
|
||||
// ErrNoType is returned when no type is specified
|
||||
ErrNoType = errors.New("plugin: no type")
|
||||
// ErrNoPluginID is returned when no id is specified
|
||||
ErrNoPluginID = errors.New("plugin: no id")
|
||||
|
||||
// SkipPlugin is used when a plugin is not initialized and should not be loaded,
|
||||
// ErrSkipPlugin is used when a plugin is not initialized and should not be loaded,
|
||||
// this allows the plugin loader differentiate between a plugin which is configured
|
||||
// not to load and one that fails to load.
|
||||
SkipPlugin = errors.New("skip plugin")
|
||||
ErrSkipPlugin = errors.New("skip plugin")
|
||||
)
|
||||
|
||||
// IsSkipPlugin returns true if the error is skipping the plugin
|
||||
func IsSkipPlugin(err error) bool {
|
||||
if errors.Cause(err) == SkipPlugin {
|
||||
if errors.Cause(err) == ErrSkipPlugin {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type PluginType string
|
||||
// Type is the type of the plugin
|
||||
type Type string
|
||||
|
||||
const (
|
||||
RuntimePlugin PluginType = "io.containerd.runtime.v1"
|
||||
GRPCPlugin PluginType = "io.containerd.grpc.v1"
|
||||
SnapshotPlugin PluginType = "io.containerd.snapshotter.v1"
|
||||
TaskMonitorPlugin PluginType = "io.containerd.monitor.v1"
|
||||
DiffPlugin PluginType = "io.containerd.differ.v1"
|
||||
MetadataPlugin PluginType = "io.containerd.metadata.v1"
|
||||
ContentPlugin PluginType = "io.containerd.content.v1"
|
||||
// RuntimePlugin implements a runtime
|
||||
RuntimePlugin Type = "io.containerd.runtime.v1"
|
||||
// GRPCPlugin implements a grpc service
|
||||
GRPCPlugin Type = "io.containerd.grpc.v1"
|
||||
// SnapshotPlugin implements a snapshotter
|
||||
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
|
||||
// TaskMonitorPlugin implements a task monitor
|
||||
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
|
||||
// DiffPlugin implements a differ
|
||||
DiffPlugin Type = "io.containerd.differ.v1"
|
||||
// MetadataPlugin implements a metadata store
|
||||
MetadataPlugin Type = "io.containerd.metadata.v1"
|
||||
// ContentPlugin implements a content store
|
||||
ContentPlugin Type = "io.containerd.content.v1"
|
||||
)
|
||||
|
||||
// Registration contains information for registering a plugin
|
||||
type Registration struct {
|
||||
Type PluginType
|
||||
Type Type
|
||||
ID string
|
||||
Config interface{}
|
||||
Requires []PluginType
|
||||
Requires []Type
|
||||
Init func(*InitContext) (interface{}, error)
|
||||
|
||||
added bool
|
||||
}
|
||||
|
||||
// URI returns the full plugin URI
|
||||
func (r *Registration) URI() string {
|
||||
return fmt.Sprintf("%s.%s", r.Type, r.ID)
|
||||
}
|
||||
|
||||
// Service allows GRPC services to be registered with the underlying server
|
||||
type Service interface {
|
||||
Register(*grpc.Server) error
|
||||
}
|
||||
@@ -75,11 +88,12 @@ func Load(path string) (err error) {
|
||||
return loadPlugins(path)
|
||||
}
|
||||
|
||||
// Register allows plugins to register
|
||||
func Register(r *Registration) {
|
||||
register.Lock()
|
||||
defer register.Unlock()
|
||||
if r.Type == "" {
|
||||
panic(ErrNoPluginType)
|
||||
panic(ErrNoType)
|
||||
}
|
||||
if r.ID == "" {
|
||||
panic(ErrNoPluginID)
|
||||
@@ -87,6 +101,7 @@ func Register(r *Registration) {
|
||||
register.r = append(register.r, r)
|
||||
}
|
||||
|
||||
// Graph returns an ordered list of registered plugins for initialization
|
||||
func Graph() (ordered []*Registration) {
|
||||
for _, r := range register.r {
|
||||
children(r.Requires, &ordered)
|
||||
@@ -98,7 +113,7 @@ func Graph() (ordered []*Registration) {
|
||||
return ordered
|
||||
}
|
||||
|
||||
func children(types []PluginType, ordered *[]*Registration) {
|
||||
func children(types []Type, ordered *[]*Registration) {
|
||||
for _, t := range types {
|
||||
for _, r := range register.r {
|
||||
if r.Type == t {
|
||||
|
||||
Reference in New Issue
Block a user