plugin

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 55

README

plugin

A Go package providing a common plugin interface across containerd repositories.

This package is intended to be imported by the main containerd repository as well as plugin implementations. By sharing a common implementations, plugins can register themselves without needing to import the main containerd repository. This plugin is intended to provide an interface and common functionality, but is not intended to define plugin types used by containerd. Plugins should copy plugin type strings to avoid creating unintended depdenencies.

Project details

plugin is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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")
	// ErrIDRegistered is returned when a duplicate id is already registered
	ErrIDRegistered = errors.New("plugin: id already registered")
	// 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.
	ErrSkipPlugin = errors.New("skip plugin")
	// ErrPluginInitialized is used when a plugin is already initialized
	ErrPluginInitialized = errors.New("plugin: already initialized")
	// ErrPluginNotFound is used when a plugin is looked up but not found
	ErrPluginNotFound = errors.New("plugin: not found")
	// ErrPluginMultipleInstances is used when a plugin is expected a single instance but has multiple
	ErrPluginMultipleInstances = errors.New("plugin: multiple instances")

	// ErrInvalidRequires will be thrown if the requirements for a plugin are
	// defined in an invalid manner.
	ErrInvalidRequires = errors.New("invalid requires")
)

Functions

func IsSkipPlugin

func IsSkipPlugin(err error) bool

IsSkipPlugin returns true if the error is skipping the plugin

Types

type DisableFilter

type DisableFilter func(r *Registration) bool

DisableFilter filters out disabled plugins

type InitContext

type InitContext struct {
	Context           context.Context
	Properties        map[string]string
	Config            interface{}
	RegisterReadiness func() func()

	// Meta is metadata plugins can fill in at init
	Meta *Meta
	// contains filtered or unexported fields
}

InitContext is used for plugin initialization

func NewContext

func NewContext(ctx context.Context, plugins *Set, properties map[string]string) *InitContext

NewContext returns a new plugin InitContext

func (*InitContext) GetAll

func (i *InitContext) GetAll() []*Plugin

GetAll plugins in the set

func (*InitContext) GetByID

func (i *InitContext) GetByID(t Type, id string) (interface{}, error)

GetByID returns the plugin of the given type and ID

func (*InitContext) GetByType

func (i *InitContext) GetByType(t Type) (map[string]interface{}, error)

GetByType returns all plugins with the specific type.

func (*InitContext) GetSingle

func (i *InitContext) GetSingle(t Type) (interface{}, error)

GetSingle returns a plugin instance of the given type when only a single instance of that type is expected. Throws an ErrPluginNotFound if no plugin is found and ErrPluginMultipleInstances when multiple instances are found. Since plugins are not ordered, if multiple instances is suported then GetByType should be used. If only one is expected, then to switch plugins, disable or remove the unused plugins of the same type.

func (*InitContext) Plugins

func (i *InitContext) Plugins() *Set

Plugins returns plugin set

type Meta

type Meta struct {
	Platforms    []imagespec.Platform // platforms supported by plugin
	Exports      map[string]string    // values exported by plugin
	Capabilities []string             // feature switches for plugin
}

Meta contains information gathered from the registration and initialization process.

type Plugin

type Plugin struct {
	Registration Registration // registration, as initialized
	Config       interface{}  // config, as initialized
	Meta         Meta
	// contains filtered or unexported fields
}

Plugin represents an initialized plugin, used with an init context.

func (*Plugin) Err

func (p *Plugin) Err() error

Err returns the errors during initialization. returns nil if no error was encountered

func (*Plugin) Instance

func (p *Plugin) Instance() (interface{}, error)

Instance returns the instance and any initialization error of the plugin

type Registration

type Registration struct {
	// Type of the plugin
	Type Type
	// ID of the plugin
	ID string
	// Config specific to the plugin
	Config interface{}
	// Requires is a list of plugins that the registered plugin requires to be available
	Requires []Type

	// InitFn is called when initializing a plugin. The registration and
	// context are passed in. The init function may modify the registration to
	// add exports, capabilities and platform support declarations.
	InitFn func(*InitContext) (interface{}, error)

	// ConfigMigration allows a plugin to migrate configurations from an older
	// version to handle plugin renames or moving of features from one plugin
	// to another in a later version.
	// The configuration map is keyed off the plugin name and the value
	// is the configuration for that objects, with the structure defined
	// for the plugin. No validation is done on the value before performing
	// the migration.
	ConfigMigration func(context.Context, int, map[string]interface{}) error
}

Registration contains information for registering a plugin

func (Registration) Init

func (r Registration) Init(ic *InitContext) *Plugin

Init the registered plugin

func (*Registration) URI

func (r *Registration) URI() string

URI returns the full plugin URI

type Registry

type Registry []*Registration

Registry is list of registrations which can be registered to and produce a filtered and ordered output. The Registry itself is immutable and the list will be copied and appeneded to a new registry when new items are registered.

func (Registry) Graph

func (registry Registry) Graph(filter DisableFilter) []Registration

Graph computes the ordered list of registrations based on their dependencies, filtering out any plugins which match the provided filter.

func (Registry) Register

func (registry Registry) Register(r *Registration) Registry

Register adds the registration to a Registry and returns the updated Registry, panicking if registration could not succeed.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set defines a plugin collection, used with InitContext.

This maintains ordering and unique indexing over the set.

After iteratively instantiating plugins, this set should represent, the ordered, initialization set of plugins for a containerd instance.

func NewPluginSet

func NewPluginSet() *Set

NewPluginSet returns an initialized plugin set

func (*Set) Add

func (ps *Set) Add(p *Plugin) error

Add a plugin to the set

func (*Set) Get

func (ps *Set) Get(t Type, id string) *Plugin

Get returns the plugin with the given type and id

func (*Set) GetAll

func (ps *Set) GetAll() []*Plugin

GetAll returns all initialized plugins

type Type

type Type string

Type is the type of the plugin

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL