loader

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: MPL-2.0 Imports: 23 Imported by: 307

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AgentSupportedApiVersions is the set of API versions supported by the
	// Nomad agent by plugin type.
	AgentSupportedApiVersions = map[string][]string{
		base.PluginTypeDevice: {device.ApiVersion010},
		base.PluginTypeDriver: {drivers.ApiVersion010},
	}
)

Functions

This section is empty.

Types

type InternalPluginConfig

type InternalPluginConfig struct {
	Config  map[string]interface{}
	Factory plugins.PluginCtxFactory
}

InternalPluginConfig is used to configure launching an internal plugin.

type MockCatalog

type MockCatalog struct {
	DispenseF func(name, pluginType string, cfg *base.AgentConfig, logger log.Logger) (PluginInstance, error)
	ReattachF func(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)
	CatalogF  func() map[string][]*base.PluginInfoResponse
}

MockCatalog provides a mock PluginCatalog to be used for testing

func (*MockCatalog) Catalog

func (m *MockCatalog) Catalog() map[string][]*base.PluginInfoResponse

func (*MockCatalog) Dispense

func (m *MockCatalog) Dispense(name, pluginType string, cfg *base.AgentConfig, logger log.Logger) (PluginInstance, error)

func (*MockCatalog) Reattach

func (m *MockCatalog) Reattach(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)

type MockInstance

type MockInstance struct {
	InternalPlugin  bool
	KillF           func()
	ReattachConfigF func() (*plugin.ReattachConfig, bool)
	PluginF         func() interface{}
	ExitedF         func() bool
	ApiVersionF     func() string
}

MockInstance provides a mock PluginInstance to be used for testing

func MockBasicExternalPlugin

func MockBasicExternalPlugin(inst interface{}, apiVersion string) *MockInstance

MockBasicExternalPlugin returns a MockInstance that simulates an external plugin returning it has been exited after kill is called. It returns the passed inst as the plugin

func (*MockInstance) ApiVersion

func (m *MockInstance) ApiVersion() string

func (*MockInstance) Exited

func (m *MockInstance) Exited() bool

func (*MockInstance) Internal

func (m *MockInstance) Internal() bool

func (*MockInstance) Kill

func (m *MockInstance) Kill()

func (*MockInstance) Plugin

func (m *MockInstance) Plugin() interface{}

func (*MockInstance) ReattachConfig

func (m *MockInstance) ReattachConfig() (*plugin.ReattachConfig, bool)

type PluginCatalog

type PluginCatalog interface {
	// Dispense returns the plugin given its name and type. This will also
	// configure the plugin
	Dispense(name, pluginType string, config *base.AgentConfig, logger log.Logger) (PluginInstance, error)

	// Reattach is used to reattach to a previously launched external plugin.
	Reattach(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)

	// Catalog returns the catalog of all plugins keyed by plugin type
	Catalog() map[string][]*base.PluginInfoResponse
}

PluginCatalog is used to retrieve plugins, either external or internal

type PluginID

type PluginID struct {
	// Name is the name of the plugin
	Name string

	// PluginType is the plugin's type
	PluginType string
}

PluginID is a tuple identifying a plugin

func PluginInfoID

func PluginInfoID(resp *base.PluginInfoResponse) PluginID

func (PluginID) String

func (id PluginID) String() string

String returns a friendly representation of the plugin.

type PluginInstance

type PluginInstance interface {
	// Internal returns if the plugin is internal
	Internal() bool

	// Kill kills the plugin if it is external. It is safe to call on internal
	// plugins.
	Kill()

	// ReattachConfig returns the ReattachConfig and whether the plugin is internal
	// or not. If the second return value is false, no ReattachConfig is
	// possible to return.
	ReattachConfig() (config *plugin.ReattachConfig, canReattach bool)

	// Plugin returns the wrapped plugin instance.
	Plugin() interface{}

	// Exited returns whether the plugin has exited
	Exited() bool

	// ApiVersion returns the API version to be used with the plugin
	ApiVersion() string
}

PluginInstance wraps an instance of a plugin. If the plugin is external, it provides methods to retrieve the ReattachConfig and to kill the plugin.

type PluginLoader

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

PluginLoader is used to retrieve plugins either externally or from internal factories.

func NewPluginLoader

func NewPluginLoader(config *PluginLoaderConfig) (*PluginLoader, error)

NewPluginLoader returns an instance of a plugin loader or an error if the plugins could not be loaded

func (*PluginLoader) Catalog

func (l *PluginLoader) Catalog() map[string][]*base.PluginInfoResponse

Catalog returns the catalog of all plugins

func (*PluginLoader) Dispense

func (l *PluginLoader) Dispense(name, pluginType string, config *base.AgentConfig, logger log.Logger) (PluginInstance, error)

Dispense returns a plugin instance, loading it either internally or by launching an external plugin.

func (*PluginLoader) Reattach

func (l *PluginLoader) Reattach(name, pluginType string, config *plugin.ReattachConfig) (PluginInstance, error)

Reattach reattaches to a previously launched external plugin.

type PluginLoaderConfig

type PluginLoaderConfig struct {
	// Logger is the logger used by the plugin loader
	Logger log.Logger

	// PluginDir is the directory scanned for loading plugins
	PluginDir string

	// Configs is an optional set of configs for plugins
	Configs []*config.PluginConfig

	// InternalPlugins allows registering internal plugins.
	InternalPlugins map[PluginID]*InternalPluginConfig

	// SupportedVersions is a mapping of plugin type to the supported versions
	SupportedVersions map[string][]string
}

PluginLoaderConfig configures a plugin loader.

Jump to

Keyboard shortcuts

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