base

package
v0.9.0-beta3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2019 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PluginTypeBase implements the base plugin interface
	PluginTypeBase = "base"

	// PluginTypeDriver implements the driver plugin interface
	PluginTypeDriver = "driver"

	// PluginTypeDevice implements the device plugin interface
	PluginTypeDevice = "device"
)

Variables

View Source
var (
	// Handshake is a common handshake that is shared by all plugins and Nomad.
	Handshake = plugin.HandshakeConfig{

		ProtocolVersion:  2,
		MagicCookieKey:   "NOMAD_PLUGIN_MAGIC_COOKIE",
		MagicCookieValue: "e4327c2e01eabfd75a8a67adb114fb34a757d57eee7728d857a8cec6e91a7255",
	}
)
View Source
var MsgpackHandle = func() *codec.MsgpackHandle {
	h := &codec.MsgpackHandle{}
	h.RawToString = true
	h.MapType = reflect.TypeOf(map[string]interface{}(nil))
	return h
}()

MsgpackHandle is a shared handle for encoding/decoding of structs

View Source
var (
	// TestSpec is an hcl Spec for testing
	TestSpec = &hclspec.Spec{
		Block: &hclspec.Spec_Object{
			Object: &hclspec.Object{
				Attributes: map[string]*hclspec.Spec{
					"foo": {
						Block: &hclspec.Spec_Attr{
							Attr: &hclspec.Attr{
								Type:     "string",
								Required: false,
							},
						},
					},
					"bar": {
						Block: &hclspec.Spec_Attr{
							Attr: &hclspec.Attr{
								Type:     "number",
								Required: false,
							},
						},
					},
					"baz": {
						Block: &hclspec.Spec_Attr{
							Attr: &hclspec.Attr{
								Type: "bool",
							},
						},
					},
				},
			},
		},
	}
)

Functions

func MsgPackDecode

func MsgPackDecode(buf []byte, out interface{}) error

MsgPackDecode is used to decode a MsgPack encoded object

func MsgPackEncode

func MsgPackEncode(b *[]byte, in interface{}) error

MsgPackEncode is used to encode an object to MsgPack

Types

type AgentConfig

type AgentConfig struct {
	Driver *ClientDriverConfig
}

AgentConfig is the Nomad agent's configuration sent to all plugins

type BasePlugin

type BasePlugin interface {
	// PluginInfo describes the type and version of a plugin.
	PluginInfo() (*PluginInfoResponse, error)

	// ConfigSchema returns the schema for parsing the plugins configuration.
	ConfigSchema() (*hclspec.Spec, error)

	// SetConfig is used to set the configuration by passing a MessagePack
	// encoding of it.
	SetConfig(c *Config) error
}

BasePlugin is the interface that all Nomad plugins must support.

type BasePluginClient

type BasePluginClient struct {
	Client proto.BasePluginClient

	// DoneCtx is closed when the plugin exits
	DoneCtx context.Context
}

BasePluginClient implements the client side of a remote base plugin, using gRPC to communicate to the remote plugin.

func (*BasePluginClient) ConfigSchema

func (b *BasePluginClient) ConfigSchema() (*hclspec.Spec, error)

func (*BasePluginClient) PluginInfo

func (b *BasePluginClient) PluginInfo() (*PluginInfoResponse, error)

func (*BasePluginClient) SetConfig

func (b *BasePluginClient) SetConfig(c *Config) error

type ClientDriverConfig

type ClientDriverConfig struct {
	// ClientMaxPort is the upper range of the ports that the client uses for
	// communicating with plugin subsystems over loopback
	ClientMaxPort uint

	// ClientMinPort is the lower range of the ports that the client uses for
	// communicating with plugin subsystems over loopback
	ClientMinPort uint
}

ClientDriverConfig is the driver specific configuration for all driver plugins

type Config

type Config struct {
	// ApiVersion is the negotiated plugin API version to use.
	ApiVersion string

	// PluginConfig is the MessagePack encoding of the plugins user
	// configuration.
	PluginConfig []byte

	// AgentConfig is the Nomad agents configuration as applicable to plugins
	AgentConfig *AgentConfig
}

Config contains the configuration for the plugin.

type ConfigSchemaFn

type ConfigSchemaFn func() (*hclspec.Spec, error)

func StaticConfigSchema

func StaticConfigSchema(out *hclspec.Spec) ConfigSchemaFn

StaticConfigSchema returns the passed Spec with no error

func TestConfigSchema

func TestConfigSchema() ConfigSchemaFn

TestConfigSchema returns a ConfigSchemaFn that statically returns the TestSpec

type MockPlugin

type MockPlugin struct {
	PluginInfoF   PluginInfoFn
	ConfigSchemaF ConfigSchemaFn
	SetConfigF    SetConfigFn
}

MockPlugin is used for testing. Each function can be set as a closure to make assertions about how data is passed through the base plugin layer.

func (*MockPlugin) ConfigSchema

func (p *MockPlugin) ConfigSchema() (*hclspec.Spec, error)

func (*MockPlugin) PluginInfo

func (p *MockPlugin) PluginInfo() (*PluginInfoResponse, error)

func (*MockPlugin) SetConfig

func (p *MockPlugin) SetConfig(cfg *Config) error

type PluginBase

type PluginBase struct {
	plugin.NetRPCUnsupportedPlugin
	Impl BasePlugin
}

PluginBase is wraps a BasePlugin and implements go-plugins GRPCPlugin interface to expose the interface over gRPC.

func (*PluginBase) GRPCClient

func (p *PluginBase) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

func (*PluginBase) GRPCServer

func (p *PluginBase) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

type PluginInfoFn

type PluginInfoFn func() (*PluginInfoResponse, error)

func StaticInfo

func StaticInfo(out *PluginInfoResponse) PluginInfoFn

StaticInfo returns the passed PluginInfoResponse with no error

type PluginInfoResponse

type PluginInfoResponse struct {
	// Type returns the plugins type
	Type string

	// PluginApiVersions returns the versions of the Nomad plugin API that the
	// plugin supports.
	PluginApiVersions []string

	// PluginVersion is the version of the plugin.
	PluginVersion string

	// Name is the plugins name.
	Name string
}

PluginInfoResponse returns basic information about the plugin such that Nomad can decide whether to load the plugin or not.

type SetConfigFn

type SetConfigFn func(*Config) error

func NoopSetConfig

func NoopSetConfig() SetConfigFn

NoopSetConfig is a noop implementation of set config

type TestConfig

type TestConfig struct {
	Foo string `cty:"foo" codec:"foo"`
	Bar int64  `cty:"bar" codec:"bar"`
	Baz bool   `cty:"baz" codec:"baz"`
}

TestConfig is used to decode a config from the TestSpec

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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