plugin

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DeployEnginePluginPathEnvVar is the name of the environment variable
	// that should be set to a colon-separated list of directories to search
	// for plugins in.
	DeployEnginePluginPathEnvVar = "BLUELINK_DEPLOY_ENGINE_PLUGIN_PATH"
	// DeployEnginePluginLaunchAttemptLimitEnvVar is the name of the environment
	// variable that should be set to the number of times to attempt launching
	// a plugin before giving up.
	DeployEnginePluginLaunchAttemptLimitEnvVar = "BLUELINK_DEPLOY_ENGINE_PLUGIN_LAUNCH_ATTEMPT_LIMIT"
	// DeployEnginePluginLogFileRootDirEnvVar is the name of the environment variable
	// that should be set to the root directory for plugin log files.
	DeployEnginePluginLogFileRootDirEnvVar = "BLUELINK_DEPLOY_ENGINE_PLUGIN_LOG_FILE_ROOT_DIR"
)
View Source
const (
	// DefaultPluginLaunchAttemptLimit is the default number of times to attempt
	// launching a plugin before giving up.
	DefaultPluginLaunchAttemptLimit = 5
	// DefaultLaunchWaitTimeout is the default timeout to wait for a plugin to register
	// with the host service.
	DefaultLaunchWaitTimeout = 20 * time.Millisecond
	// DefaultCheckRegisteredInterval is the default interval to check if a plugin has
	// registered with the host service.
	DefaultCheckRegisteredInterval = 5 * time.Millisecond
)

Variables

View Source
var (
	// ErrPluginRegistrationTimeout is returned when a plugin does not register
	// with the host service within the wait timeout.
	ErrPluginRegistrationTimeout = errors.New("plugin registration timeout")
)
View Source
var (
	// ErrUnsupportedProviderProtocolVersion is returned when the protocol version
	// is not supported.
	ErrUnsupportedProviderProtocolVersion = errors.New("unsupported provider protocol version")
)
View Source
var (
	// ErrUnsupportedTransformerProtocolVersion is returned when the protocol version
	// is not supported.
	ErrUnsupportedTransformerProtocolVersion = errors.New("unsupported transformer protocol version")
)

Functions

func CreatePluginInstance

func CreatePluginInstance(info *pluginservicev1.PluginInstanceInfo, hostID string) (any, func(), error)

CreatePluginInstance is a function that creates a new instance of a plugin. This implements the pluginservicev1.PluginFactory interface.

func ServeProviderV1

func ServeProviderV1(
	ctx context.Context,
	providerServer any,
	pluginServiceClient pluginservicev1.ServiceClient,
	hostInfoContainer pluginutils.HostInfoContainer,
	config ServePluginConfiguration,
) (func(), error)

ServeProviderV1 handles serving the v1 provider plugin with the given providerServer and options. This will deal with registering the provider with the host service.

func ServeTransformerV1

func ServeTransformerV1(
	ctx context.Context,
	transformerServer any,
	pluginServiceClient pluginservicev1.ServiceClient,
	hostInfoContainer pluginutils.HostInfoContainer,
	config ServePluginConfiguration,
) (func(), error)

ServeTransformerV1 handles serving the v1 transformer plugin with the given transformerServer and options. This will deal with registering the transformer with the host service.

Types

type Launcher

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

Launcher is a service that launches plugins and waits for them to register with the host service.

func NewLauncher

func NewLauncher(
	pluginPath string,
	manager pluginservicev1.Manager,
	executor PluginExecutor,
	logger core.Logger,
	opts ...LauncherOption,
) *Launcher

NewLauncher creates a new Launcher.

func (*Launcher) Launch

func (l *Launcher) Launch(ctx context.Context) (*PluginMaps, error)

Launch discovers, executes plugin binaries and waits for the plugins to have registered with the host service. This returns a set of adaptors that can be used as maps of providers and transformers to be used to create a blueprint loader.

The provided plugin path is expected to be a list of root directories separated by os.PathListSeparator (colon on Unix, semicolon on Windows).

The provided context should set a deadline to avoid waiting indefinitely for plugins to register with the host service.

type LauncherOption

type LauncherOption func(*Launcher)

LauncherOption is a function that configures a Launcher.

func WithLauncherAttemptLimit

func WithLauncherAttemptLimit(attemptLimit int) LauncherOption

WithLauncherAttemptLimit is a Launcher option that sets the number of times to attempt launching a plugin before giving up.

func WithLauncherCheckRegisteredInterval

func WithLauncherCheckRegisteredInterval(interval time.Duration) LauncherOption

WithLauncherCheckRegisteredInterval is a Launcher option that sets the interval to check if a plugin has registered with the host service.

func WithLauncherFS

func WithLauncherFS(fs afero.Fs) LauncherOption

WithLauncherFS is a Launcher option that sets the file system to use when discovering plugins.

func WithLauncherTransformerKeyType

func WithLauncherTransformerKeyType(keyType TransformerKeyType) LauncherOption

WithLauncherTransformerKeyType is a Launcher option that sets the key type to use for transformer plugins.

func WithLauncherWaitTimeout

func WithLauncherWaitTimeout(timeout time.Duration) LauncherOption

WithLauncherWaitTimeout is a Launcher option that sets the timeout to wait for a plugin to register with the host service.

type PluginExecutor

type PluginExecutor interface {
	// Execute the plugin binary at the given path.
	Execute(pluginID string, pluginBinary string) (PluginProcess, error)
}

PluginExecutor is an interface that represents the executor of a plugin. This interface is used to abstract the execution of a plugin from the plugin launcher.

func NewOSCmdExecutor

func NewOSCmdExecutor(
	logFileRootDir string,
	env map[string]string,
) PluginExecutor

NewOSCmdExecutor creates a new PluginExecutor that uses an operating system command to execute the plugin binary. stdout and stderr for each plugin will be redirected to a log file for the plugin under the logFileRootDir directory. The log file will be located at: {logFileRootDir}/({pluginHost}/?)/{namespace}/{pluginName}/plugin.log

type PluginMaps

type PluginMaps struct {
	Providers    map[string]provider.Provider
	Transformers map[string]transform.SpecTransformer
}

PluginMaps is a set of adaptors that can be used as maps of providers and transformers to be used to create a blueprint loader.

type PluginPathInfo

type PluginPathInfo struct {
	// The absolute path to the plugin executable.
	AbsolutePath string
	// The plugin type extracted from the path.
	PluginType string
	// The ID of the plugin extracted from the path.
	// This is essential to track the plugins that have
	// registered with the host service.
	ID string
	// The version of the plugin extracted from the path.
	Version string
}

PluginPathInfo contains important metadata extracted from a plugin path.

func DiscoverPlugins

func DiscoverPlugins(pluginPath string, fs afero.Fs, logger bpcore.Logger) ([]*PluginPathInfo, error)

DiscoverPlugins handles the discovery of plugins in the current host environment. The provided plugin path is expected to be a list of root directories separated by os.PathListSeparator (colon on Unix, semicolon on Windows). This returns a list of discovered plugin paths with important plugin metadata extracted from the file paths.

type PluginProcess

type PluginProcess interface {
	// Kill the plugin process.
	Kill() error
}

PluginProcess is an interface that represents a running plugin process.

type ServePluginConfiguration

type ServePluginConfiguration struct {
	// The unique identifier for the plugin.
	// In addition to being unique, the ID should point to the location
	// where the plugin can be downloaded.
	// {hostname/}?{namespace}/{pluginName}
	//
	// For example:
	// registry.bluelink.dev/bluelink/aws
	// bluelink/aws
	//
	// For providers, the last portion of the ID is the unique name of the provider
	// that is expected to be used as the namespace for resources, data sources
	// and custom variable types used in blueprints.
	// For example, the namespace for AWS resources is "aws"
	// used in the resource type "aws/lambda/function".
	// For transformers, the last portion of the ID is the unique name of the transformer,
	// unlike providers, transformer elements are not namespaced so it is purely an ID
	// for the plugin.
	ID string

	// ProtocolVersion is the protocol version that should be
	// used for the plugin.
	// Currently, the only supported protocol version is "1.0".
	ProtocolVersion string

	// PluginMetadata is the metadata for the plugin.
	// This is used to provide information about the plugin
	// to the host service.
	PluginMetadata *pluginservicev1.PluginMetadata

	// Debug runs the plugin in a mode compatible with
	// debugging processes such as delve.
	Debug bool

	// UnixSocketPath is the path to the Unix socket that the
	// plugin should listen on.
	// If this is set, the TCPPort should be empty.
	UnixSocketPath string

	// TCPPort is the port that the plugin should listen on.
	// If this is set, the UnixSocketPath should be empty.
	// If this is not set and UnixSocketPath is not set, the
	// plugin will listen on the next available port.
	TCPPort int

	// Listener is the listener that the plugin server should use.
	// If this is provided, TCPPort and UnixSocketPath will be ignored.
	Listener net.Listener
}

ServePluginConfiguration contains configuration for serving a plugin.

type TransformerKeyType

type TransformerKeyType int32

TransformerKeyType defines the type of key to be used to identify a transformer in the plugin map produced by the plugin launcher. Transformer plugins can either be keyed by the plugin name (namespace) or the transform string name used in the transform section of a blueprint.

const (
	// TransformerKeyTypePluginName indicates that the plugin should be keyed
	// by the plugin name (namespace).
	TransformerKeyTypePluginName TransformerKeyType = iota
	// TransformerKeyTypeTransformName indicates that the plugin should be keyed
	// by the transform string name used in the transform section of a blueprint.
	// This is the default value when one isn't provided to the plugin launcher.
	TransformerKeyTypeTransformName
)

Jump to

Keyboard shortcuts

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