nspawn

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DockerImage string = "docker"
	TarImage    string = "tar"
	RawImage    string = "raw"

	ImagePath string = "/var/lib/machines"
)

Variables

View Source
var (
	NspawnMeasuredCpuStats = []string{"System Mode", "User Mode", "Percent"}

	NspawnMeasuredMemStats = []string{"RSS", "Cache"}
)

Functions

func ConfigureIPTablesRules added in v0.5.0

func ConfigureIPTablesRules(delete bool, interfaces []string) error

func DownloadImage added in v0.2.0

func DownloadImage(url, name, verify, imageType string, force bool, logger hclog.Logger) error

func NewNspawnDriver

func NewNspawnDriver(logger hclog.Logger) drivers.DriverPlugin

NewNspawnDriver returns a new DriverPlugin implementation

func PullDocker added in v0.9.0

func PullDocker(c *import1.Conn, url, image string, force bool) (*import1.Transfer, error)

Types

type Config

type Config struct {
	// Enabled is set to true to enable the nspawn driver
	Enabled bool `codec:"enabled"`
	Volumes bool `codec:"volumes"`
}

Config is the driver configuration set by the SetConfig RPC call

type Driver

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

Driver is a driver for running nspawn containers

func (*Driver) Capabilities

func (d *Driver) Capabilities() (*drivers.Capabilities, error)

Capabilities define what features the driver implements.

func (*Driver) ConfigSchema

func (d *Driver) ConfigSchema() (*hclspec.Spec, error)

ConfigSchema function allows a plugin to tell Nomad the schema for its configuration. This configuration is given in a plugin block of the client configuration. The schema is defined with the hclspec package.

func (*Driver) DestroyTask

func (d *Driver) DestroyTask(taskID string, force bool) error

DestroyTask function cleans up and removes a task that has terminated. If force is set to true, the driver must destroy the task even if it is still running.

func (*Driver) ExecTask

func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error)

ExecTask function is used by the Nomad client to execute scripted health checks inside the task execution context.

func (*Driver) ExecTaskStreamingRaw added in v0.2.0

func (d *Driver) ExecTaskStreamingRaw(ctx context.Context,
	taskID string,
	command []string,
	tty bool,
	stream drivers.ExecTaskStream) error

ExecTaskStreamingRaw function is used by the Nomad client to execute commands inside the task execution context. i.E. nomad alloc exec ....

func (*Driver) Fingerprint

func (d *Driver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, error)

Fingerprint is called by the client when the plugin is started. It allows the driver to indicate its health to the client. The channel returned should immediately send an initial Fingerprint, then send periodic updates at an interval that is appropriate for the driver until the context is canceled.

func (*Driver) InspectTask

func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error)

InspectTask function returns detailed status information for the referenced taskID.

func (*Driver) PluginInfo

func (d *Driver) PluginInfo() (*base.PluginInfoResponse, error)

PluginInfo returns metadata about the nspawn driver plugin

func (*Driver) RecoverTask

func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error

RecoverTask detects running tasks when nomad client or task driver is restarted. When a driver is restarted it is not expected to persist any internal state to disk. To support this, Nomad will attempt to recover a task that was previously started if the driver does not recognize the task ID. During task recovery, Nomad calls RecoverTask passing the TaskHandle that was returned by the StartTask function.

func (*Driver) SetConfig

func (d *Driver) SetConfig(cfg *base.Config) error

SetConfig function is called when starting the plugin for the first time. The Config given has two different configuration fields. The first PluginConfig, is an encoded configuration from the plugin block of the client config. The second, AgentConfig, is the Nomad agent's configuration which is given to all plugins.

func (*Driver) Shutdown

func (d *Driver) Shutdown(ctx context.Context) error

func (*Driver) SignalTask

func (d *Driver) SignalTask(taskID string, signal string) error

SignalTask function is used by drivers which support sending OS signals (SIGHUP, SIGKILL, SIGUSR1 etc.) to the task. It is an optional function and is listed as a capability in the driver Capabilities struct.

func (*Driver) StartTask

StartTask creates and starts a new nspawn Container based on the given TaskConfig.

func (*Driver) StopTask

func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) error

StopTask function is expected to stop a running task by sending the given signal to it. If the task does not stop during the given timeout, the driver must forcefully kill the task. StopTask does not clean up resources of the task or remove it from the driver's internal state.

func (*Driver) TaskConfigSchema

func (d *Driver) TaskConfigSchema() (*hclspec.Spec, error)

TaskConfigSchema returns the schema for the driver configuration of the task.

func (*Driver) TaskEvents

func (d *Driver) TaskEvents(ctx context.Context) (<-chan *drivers.TaskEvent, error)

TaskEvents function allows the driver to publish driver specific events about tasks and the Nomad client publishes events associated with an allocation.

func (*Driver) TaskStats

func (d *Driver) TaskStats(ctx context.Context, taskID string, interval time.Duration) (<-chan *drivers.TaskResourceUsage, error)

TaskStats function returns a channel which the driver should send stats to at the given interval. The driver must send stats at the given interval until the given context is canceled or the task terminates.

func (*Driver) WaitTask

func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.ExitResult, error)

WaitTask function is expected to return a channel that will send an *ExitResult when the task exits or close the channel when the context is canceled. It is also expected that calling WaitTask on an exited task will immediately send an *ExitResult on the returned channel. A call to WaitTask after StopTask is valid and should be handled. If WaitTask is called after DestroyTask, it should return drivers.ErrTaskNotFound as no task state should exist after DestroyTask is called.

type ImageDownloadOpts added in v0.2.0

type ImageDownloadOpts struct {
	URL    string `codec:"url"`
	Type   string `codec:"type"`
	Force  bool   `codec:"force"`
	Verify string `codec:"verify"`
}

type ImageProps added in v0.2.0

type ImageProps struct {
	CreationTimestamp     uint64
	Limit                 uint64
	LimitExclusive        uint64
	ModificationTimestamp uint64
	Name                  string
	Path                  string
	ReadOnly              bool
	Type                  string
	Usage                 uint64
	UsageExclusive        uint64
}

func DescribeImage added in v0.2.0

func DescribeImage(name string) (*ImageProps, error)

type ImageType added in v0.2.0

type ImageType string

type MachineAddrs

type MachineAddrs struct {
	IPv4 net.IP
}

func MachineAddresses

func MachineAddresses(name string, timeout time.Duration) (*MachineAddrs, error)

type MachineConfig

type MachineConfig struct {
	Bind             hclutils.MapStrStr `codec:"bind"`
	BindReadOnly     hclutils.MapStrStr `codec:"bind_read_only"`
	Boot             bool               `codec:"boot"`
	Capability       []string           `codec:"capability"`
	Command          []string           `codec:"command"`
	Console          string             `codec:"console"`
	Environment      hclutils.MapStrStr `codec:"environment"`
	Ephemeral        bool               `codec:"ephemeral"`
	Image            string             `codec:"image"`
	ImageDownload    *ImageDownloadOpts `codec:"image_download,omitempty"`
	Machine          string             `codec:"machine"`
	NetworkNamespace string             `codec:"network_namespace"`
	NetworkVeth      bool               `codec:"network_veth"`
	NetworkZone      string             `codec:"network_zone"`
	NetworkBridge    string             `codec:"network_bridge"`
	PivotRoot        string             `codec:"pivot_root"`
	Port             hclutils.MapStrStr `codec:"port"`
	Ports            []string           `codec:"ports"` // :-(
	// Deprecated: Nomad dropped support for task network resources in 0.12
	PortMap               hclutils.MapStrInt `codec:"port_map"`
	PrivateUsers          string             `codec:"private_users"`
	PrivateUsersOwnership string             `codec:"private_users_ownership"`
	ProcessTwo            bool               `codec:"process_two"`
	Properties            hclutils.MapStrStr `codec:"properties"`
	ReadOnly              bool               `codec:"read_only"`
	ResolvConf            string             `codec:"resolv_conf"`
	User                  string             `codec:"user"`
	UserNamespacing       bool               `codec:"user_namespacing"`
	Volatile              string             `codec:"volatile"`
	WorkingDirectory      string             `codec:"working_directory"`
	// contains filtered or unexported fields
}

func (*MachineConfig) ConfigArray

func (c *MachineConfig) ConfigArray() ([]string, error)

func (*MachineConfig) GetImagePath added in v0.2.0

func (c *MachineConfig) GetImagePath() (string, error)

func (*MachineConfig) Validate added in v0.1.0

func (c *MachineConfig) Validate() error

type MachineProps

type MachineProps struct {
	Name               string
	TimestampMonotonic uint64
	Timestamp          uint64
	NetworkInterfaces  []int32
	ID                 []uint8
	Class              string
	Leader             uint32
	RootDirectory      string
	Service            string
	State              string
	Unit               string
}

func DescribeMachine

func DescribeMachine(name string, timeout time.Duration) (*MachineProps, error)

func (*MachineProps) GetNetworkInterfaces added in v0.5.0

func (p *MachineProps) GetNetworkInterfaces() ([]string, error)

type TaskState

type TaskState struct {
	ReattachConfig *pstructs.ReattachConfig
	MachineName    string
	StartedAt      time.Time
}

TaskState is the state which is encoded in the handle returned in StartTask. This information is needed to rebuild the task state and handler during recovery.

Jump to

Keyboard shortcuts

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