runtime

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	EventActionStart   = "start"
	EventActionUnpause = "unpause"
	EventActionRestart = "restart"
	EventActionDie     = "die"
	EventActionStop    = "stop"
	EventActionDestroy = "destroy"
	EventActionKill    = "kill"
)
View Source
const (
	EventTypeContainer = "container"
)

Variables

View Source
var ContainerRuntimes = map[string]Initializer{}

Functions

func ContainerHasJoinableNetns added in v0.75.0

func ContainerHasJoinableNetns(s ContainerStatus) bool

ContainerHasJoinableNetns reports whether the container likely has a network namespace that GetNSPath can reference (PID-based path under /proc) based on the container status.

func LogTail added in v0.83.0

func LogTail(tail *int64) string

LogTail renders a log tail for container runtime APIs: "all" or the number of lines.

func Register added in v0.15.0

func Register(name string, initFn Initializer)

func WaitForContainerRunning added in v0.33.0

func WaitForContainerRunning(
	ctx context.Context,
	r ContainerRuntime,
	contName, nodeName string,
) error

WaitForContainerRunning waits for container to become running by polling its status.

Types

type ContainerEvent added in v0.72.0

type ContainerEvent struct {
	Timestamp   time.Time
	Type        string
	Action      string
	ActorID     string
	ActorName   string
	ActorFullID string
	Attributes  map[string]string
}

type ContainerLogOptions added in v0.83.0

type ContainerLogOptions struct {
	// Tail limits the output to the last lines of the log; nil writes the whole log.
	Tail *int64
	// Follow keeps writing new log lines until the context ends.
	Follow bool
	// Timestamps prefixes every line with its timestamp.
	Timestamps bool
}

ContainerLogOptions selects the part of a container log WriteContainerLogs writes.

type ContainerLogWriter added in v0.83.0

type ContainerLogWriter interface {
	// WriteContainerLogs writes the container's stdout and stderr to the given writers. A
	// container with a TTY has one combined stream, written to stdout.
	WriteContainerLogs(
		ctx context.Context,
		containerName string,
		opts ContainerLogOptions,
		stdout, stderr io.Writer,
	) error
}

ContainerLogWriter is implemented by container runtimes that can write a container's log.

type ContainerMount added in v0.35.0

type ContainerMount struct {
	Source      string
	Destination string
}

type ContainerRuntime

type ContainerRuntime interface {
	// Initializes the Container runtime struct
	Init(...RuntimeOption) error
	// Mgmt return management network configuration of a runtime
	Mgmt() *clabtypes.MgmtNet
	// Adds custom configuration items to the container runtime struct
	WithConfig(*RuntimeConfig)
	// Set the network management details (generated by the config.go)
	WithMgmtNet(*clabtypes.MgmtNet)
	// Instructs the runtime not to delete the mgmt network on destroy
	WithKeepMgmtNet()
	// CreateNet creates or inspects the management network and stores its resolved subnets.
	CreateNet(context.Context, ...NetworkCreateOptions) error
	// NetworkAddresses snapshots occupied addresses from networks whose pools
	// overlap the requested subnets. Disjoint networks must not be inspected.
	NetworkAddresses(context.Context, []netip.Prefix) ([]NetworkAddress, error)
	// Delete container (bridge) network
	DeleteNet(context.Context) error
	// Pull container image if not present
	PullImage(context.Context, string, clabtypes.PullPolicyValue) error
	// CreateContainer creates a container, but does not start it
	CreateContainer(context.Context, *clabtypes.NodeConfig) (string, error)
	// Start pre-created container by its name. Returns an extra interface that can be used to
	// receive signals
	// about the container life-cycle after it was created, e.g. for post-deploy tasks
	StartContainer(context.Context, string, Node) (any, error)
	// Stop running container by its name AND signal to use
	StopContainer(ctx context.Context, name string, stopSignal clabtypes.Signal) error
	// Pause a container identified by its name
	PauseContainer(context.Context, string) error
	// UnPause / resume a container identified by its name
	UnpauseContainer(context.Context, string) error
	// List all containers matching labels
	ListContainers(context.Context, []*clabtypes.GenericFilter) ([]GenericContainer, error)
	// Get a netns path using the name of a container
	GetNSPath(context.Context, string) (string, error)
	// LogNonRunningContainerOutput fetches recent stdout/stderr from a container that is not
	// running and logs it (best-effort; no-op on inspect failure). Used so deploy failures
	// surface root cause when link attach runs after a fast exit.
	LogNonRunningContainerOutput(ctx context.Context, containerName string)
	// Executes cmd on container identified with id and returns stdout, stderr bytes and an error
	Exec(ctx context.Context, cID string, execCmd *clabexec.ExecCmd) (*clabexec.ExecResult, error)
	// ExecNotWait executes cmd on container identified with id but doesn't wait for output nor
	// attaches stdout/err
	ExecNotWait(ctx context.Context, cID string, execCmd *clabexec.ExecCmd) error
	// Delete container by its name
	DeleteContainer(context.Context, string) error
	// Getter for runtime config options
	Config() RuntimeConfig
	GetName() string
	// GetHostsPath returns fs path to a file which is mounted as /etc/hosts into a given container
	GetHostsPath(context.Context, string) (string, error)
	// GetContainerStatus retrieves the ContainerStatus of the named container
	GetContainerStatus(ctx context.Context, cID string) ContainerStatus
	// IsHealthy returns true is the container is reported as being healthy, false otherwise
	IsHealthy(ctx context.Context, cID string) (bool, error)
	// Immediately write to the stdin of a container, returns error
	WriteToStdinNoWait(ctx context.Context, cID string, data []byte) error
	// CheckConnectivity returns an error if it cannot connect to the runtime, nil otherwise
	CheckConnection(ctx context.Context) error
	// GetRuntimeSocket returns the path to the control socket
	GetRuntimeSocket() (string, error)
	// GetCooCBindMounts returns the extra mounts a container running this runtime in
	// Container-outside-of-Container (CooC - General case – container uses host container
	// runtime) does need to function properly
	GetCooCBindMounts() clabtypes.Binds
	// StreamLogs returns a reader for the container's logs
	// The caller needs to close the returned ReadCloser.
	StreamLogs(ctx context.Context, containerName string) (io.ReadCloser, error)
	// StreamEvents streams runtime events that match provided options.
	StreamEvents(
		ctx context.Context,
		opts EventStreamOptions,
	) (<-chan ContainerEvent, <-chan error, error)
	// InspectImage returns detailed information about a container image
	InspectImage(ctx context.Context, imageName string) (*ImageInspect, error)
	// CopyToContainer copies the contents of the given host path into the named container's
	// destination path.
	// The path must be a file, and the the destination directory must exist inside the container
	CopyToContainer(ctx context.Context, cID string, dstPath string, srcPath string) error
	// SyncMgmtHostRoutes reconciles host routes to current management endpoints.
	SyncMgmtHostRoutes(context.Context) error
}

type ContainerStatus added in v0.32.0

type ContainerStatus string

ContainerStatus summarizes container lifecycle as seen by the runtime. Running and Paused imply a joinable network namespace for typical Linux containers; use ContainerHasJoinableNetns for that check. Stopped means exited or dead (no running task / no usable netns). Created is not yet started (e.g. Docker "created").

const (
	NotFound   ContainerStatus = "NotFound"
	Running    ContainerStatus = "Running"
	Stopped    ContainerStatus = "Stopped" // exited or dead (terminal)
	Paused     ContainerStatus = "Paused"
	Created    ContainerStatus = "Created" // exists but not started
	Restarting ContainerStatus = "Restarting"
	Removing   ContainerStatus = "Removing"
)

type EndpointlessNode added in v0.71.0

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

func (*EndpointlessNode) Config added in v0.71.0

func (n *EndpointlessNode) Config() *clabtypes.NodeConfig

func (*EndpointlessNode) GetEndpoints added in v0.71.0

func (*EndpointlessNode) GetEndpoints() []clablinks.Endpoint

type EventStreamOptions added in v0.72.0

type EventStreamOptions struct {
	Labels map[string]string
}

type GenericContainer added in v0.35.0

type GenericContainer struct {
	Names           []string
	ID              string
	ShortID         string // trimmed ID for display purposes
	Image           string
	State           string
	Status          string
	Labels          map[string]string
	Pid             int
	NetworkName     string
	NetworkSettings GenericMgmtIPs
	Mounts          []ContainerMount
	Runtime         ContainerRuntime
	Ports           []*clabtypes.GenericPortBinding
	// Workload locates the node's Kubernetes workload; it is only set by lab runtimes.
	Workload *clabtypes.LabRuntimeWorkload `json:",omitempty"`
}

GenericContainer stores generic container data.

func (*GenericContainer) GetContainerIPv4 added in v0.35.0

func (ctr *GenericContainer) GetContainerIPv4() string

func (*GenericContainer) GetContainerIPv6 added in v0.35.0

func (ctr *GenericContainer) GetContainerIPv6() string

func (*GenericContainer) RunExec added in v0.35.0

func (gc *GenericContainer) RunExec(
	ctx context.Context,
	execCmd *clabexec.ExecCmd,
) (*clabexec.ExecResult, error)

RunExec executes a single command for a GenericContainer.

func (*GenericContainer) SetRuntime added in v0.35.0

func (ctr *GenericContainer) SetRuntime(r ContainerRuntime)

SetRuntime sets the runtime for this GenericContainer.

type GenericMgmtIPs added in v0.35.0

type GenericMgmtIPs struct {
	IPv4addr string
	IPv4pLen int
	IPv4Gw   string
	IPv6addr string
	IPv6pLen int
	IPv6Gw   string
}

type GraphDriver added in v0.72.0

type GraphDriver struct {
	Name string
	Data GraphDriverData
}

GraphDriver holds information about the storage driver.

type GraphDriverData added in v0.72.0

type GraphDriverData struct {
	UpperDir  string
	WorkDir   string
	MergedDir string
}

GraphDriverData holds the driver-specific data.

type ImageConfig added in v0.72.0

type ImageConfig struct {
	Labels map[string]string
}

ImageConfig holds image configuration data.

type ImageInspect added in v0.72.0

type ImageInspect struct {
	ID          string
	Config      ImageConfig
	RootFS      RootFS
	GraphDriver GraphDriver
}

ImageInspect holds relevant image inspection data.

type Initializer added in v0.15.0

type Initializer func() ContainerRuntime

type MgmtBridgeResolver added in v0.83.0

type MgmtBridgeResolver interface {
	// ResolveMgmtBridge sets the bridge of the bound management network when the
	// network exists and the bridge is not set yet. A missing network is not an error.
	ResolveMgmtBridge(context.Context) error
}

MgmtBridgeResolver is implemented by runtimes that can look up the bridge backing their bound management network without creating the network or changing host state.

type MgmtNetBinder added in v0.80.0

type MgmtNetBinder interface {
	// ForMgmtNet returns a copy of the runtime bound to the given management network
	ForMgmtNet(*clabtypes.MgmtNet) ContainerRuntime
}

MgmtNetBinder is implemented by runtimes that support multiple management networks.

type MgmtNetworkChecker added in v0.81.0

type MgmtNetworkChecker interface {
	// MgmtNetworkExists reports whether the management network bound to the runtime
	// exists.
	MgmtNetworkExists(context.Context) (bool, error)
}

MgmtNetworkChecker is implemented by runtimes that can report whether their bound management network exists without creating it.

type NetworkAddress added in v0.80.0

type NetworkAddress struct {
	NetworkName string
	ContainerID string
	Address     netip.Addr
}

NetworkAddress is a runtime-owned endpoint or infrastructure reservation.

type NetworkCreateOptions added in v0.80.0

type NetworkCreateOptions struct {
	StaticAddresses []netip.Addr
}

NetworkCreateOptions contains runtime-only inputs for management network creation.

type Node added in v0.44.0

type Node interface {
	Config() *clabtypes.NodeConfig
	GetEndpoints() []clablinks.Endpoint
}

Node is an interface that represents a node in the lab and is implemented by containerlab nodes.

func NewEndpointlessNode added in v0.71.0

func NewEndpointlessNode(c *clabtypes.NodeConfig) Node

NewEndpointlessNode returns a EndpointlessNode -- a node w/ only a config, that can satisfy the Node interface.

type RootFS added in v0.72.0

type RootFS struct {
	Type   string
	Layers []string
}

RootFS holds the root filesystem information of an image.

type RuntimeConfig added in v0.15.0

type RuntimeConfig struct {
	Timeout          time.Duration
	GracefulShutdown bool
	Debug            bool
	KeepMgmtNet      bool
	LabNamespace     string
	VerifyLinkParams *clablinks.VerifyLinkParams
}

type RuntimeOption added in v0.15.0

type RuntimeOption func(ContainerRuntime)

func WithConfig added in v0.15.0

func WithConfig(cfg *RuntimeConfig) RuntimeOption

func WithMgmtNet added in v0.15.0

func WithMgmtNet(mgmt *clabtypes.MgmtNet) RuntimeOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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