dynamicplugins

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MPL-2.0 Imports: 4 Imported by: 45

Documentation

Overview

dynamicplugins is a package that manages dynamic plugins in Nomad. It exposes a registry that allows for plugins to be registered/deregistered and also allows subscribers to receive real time updates of these events.

Index

Constants

View Source
const (
	PluginTypeCSIController = "csi-controller"
	PluginTypeCSINode       = "csi-node"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType is the enum of events that will be emitted by a Registry's PluginsUpdatedCh.

const (
	// EventTypeRegistered is emitted by the Registry when a new plugin has been
	// registered.
	EventTypeRegistered EventType = "registered"
	// EventTypeDeregistered is emitted by the Registry when a plugin has been
	// removed.
	EventTypeDeregistered EventType = "deregistered"
)

type PluginConnectionInfo

type PluginConnectionInfo struct {
	// SocketPath is the path to the plugins api socket.
	SocketPath string
}

PluginConnectionInfo is the data required to connect to the plugin. note: We currently only support Unix Domain Sockets, but this may be expanded

to support other connection modes in the future.

type PluginDispenser

type PluginDispenser func(info *PluginInfo) (interface{}, error)

type PluginInfo

type PluginInfo struct {
	Name    string
	Type    string
	Version string

	// ConnectionInfo should only be used externally during `RegisterPlugin` and
	// may not be exposed in the future.
	ConnectionInfo *PluginConnectionInfo

	// AllocID tracks the allocation running the plugin
	AllocID string

	// Options is used for plugin registrations to pass further metadata along to
	// other subsystems
	Options map[string]string
}

PluginInfo is the metadata that is stored by the registry for a given plugin.

type PluginUpdateEvent

type PluginUpdateEvent struct {
	EventType EventType
	Info      *PluginInfo
}

PluginUpdateEvent is a struct that is sent over a PluginsUpdatedCh when plugins are added or removed from the registry.

type Registry

type Registry interface {
	RegisterPlugin(info *PluginInfo) error
	DeregisterPlugin(ptype, name string) error

	ListPlugins(ptype string) []*PluginInfo
	DispensePlugin(ptype, name string) (interface{}, error)

	PluginsUpdatedCh(ctx context.Context, ptype string) <-chan *PluginUpdateEvent

	Shutdown()

	StubDispenserForType(ptype string, dispenser PluginDispenser)
}

Registry is an interface that allows for the dynamic registration of plugins that are running as Nomad Tasks.

func NewRegistry

func NewRegistry(state StateStorage, dispensers map[string]PluginDispenser) Registry

NewRegistry takes a map of `plugintype` to PluginDispenser functions that should be used to vend clients for plugins to be used.

type RegistryState

type RegistryState struct {
	Plugins map[string]map[string]*PluginInfo
}

RegistryState is what we persist in the client state store. It contains a map of plugin types to maps of plugin name -> PluginInfo.

type StateStorage

type StateStorage interface {
	// GetDynamicPluginRegistryState is used to restore the registry state
	GetDynamicPluginRegistryState() (*RegistryState, error)

	// PutDynamicPluginRegistryState is used to store the registry state
	PutDynamicPluginRegistryState(state *RegistryState) error
}

StateStorage is used to persist the dynamic plugin registry's state across agent restarts.

Jump to

Keyboard shortcuts

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