runtime

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VsockAddr

func VsockAddr(cid, port uint32) string

VsockAddr formats a vsock address string.

Types

type CreateOpts

type CreateOpts struct {
	Image     string
	Memory    int64   // bytes
	CPU       float64 // cores
	Storage   string  // tmpfs size (e.g. "500m", "1g")
	AuthToken string
	Labels    map[string]string
	Profile   string
}

CreateOpts holds parameters for creating a new sandbox instance.

type DockerRuntime

type DockerRuntime struct {
	Client      *client.Client
	NetworkID   string
	NetworkName string
	OCIRuntime  string // OCI runtime name passed to Docker (e.g. "runsc"). Empty = daemon default (runc).

	Log *slog.Logger
	// contains filtered or unexported fields
}

DockerRuntime implements Runtime using Docker containers.

func NewDockerRuntime

func NewDockerRuntime(name string, networkName string, ociRuntime string, log *slog.Logger) (*DockerRuntime, error)

NewDockerRuntime creates a DockerRuntime with a new Docker client. name is the canonical runtime name used in config and map keys (e.g. "docker", "docker+gvisor"). ociRuntime specifies the OCI runtime binary for containers (e.g. "runsc" for gVisor). Pass "" for both to use the Docker daemon's default runtime (runc).

func (*DockerRuntime) Close

func (r *DockerRuntime) Close() error

Close closes the Docker client.

func (*DockerRuntime) Create

func (r *DockerRuntime) Create(ctx context.Context, opts CreateOpts) (*Instance, error)

Create creates and starts a Docker container, waits for the agent to be reachable, and returns the instance.

func (*DockerRuntime) Destroy

func (r *DockerRuntime) Destroy(ctx context.Context, instanceID string) error

Destroy stops and removes a Docker container.

func (*DockerRuntime) DialAgent

func (r *DockerRuntime) DialAgent(_ context.Context, _ string, timeout time.Duration) (net.Conn, error)

DialAgent dials the agent via TCP.

func (*DockerRuntime) Init

func (r *DockerRuntime) Init(ctx context.Context) error

Init ensures the Docker bridge network exists and validates the OCI runtime.

func (*DockerRuntime) Name

func (r *DockerRuntime) Name() string

func (*DockerRuntime) Stats

func (r *DockerRuntime) Stats(ctx context.Context, instanceID string) (*Stats, error)

Stats returns resource usage metrics for a Docker container.

type FirecrackerRuntime

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

FirecrackerRuntime implements Runtime using Firecracker microVMs.

func NewFirecrackerRuntime

func NewFirecrackerRuntime(cfg config.FirecrackerConfig, log *slog.Logger) *FirecrackerRuntime

NewFirecrackerRuntime creates a new Firecracker runtime.

func (*FirecrackerRuntime) Close

func (r *FirecrackerRuntime) Close() error

Close cleans up all running VMs.

func (*FirecrackerRuntime) Create

func (r *FirecrackerRuntime) Create(ctx context.Context, opts CreateOpts) (*Instance, error)

Create launches a Firecracker microVM with the given options.

func (*FirecrackerRuntime) Destroy

func (r *FirecrackerRuntime) Destroy(_ context.Context, instanceID string) error

Destroy stops a Firecracker microVM and cleans up its resources.

func (*FirecrackerRuntime) DialAgent

func (r *FirecrackerRuntime) DialAgent(_ context.Context, instanceID string, timeout time.Duration) (net.Conn, error)

DialAgent connects to the agent inside a Firecracker microVM via vsock.

func (*FirecrackerRuntime) Init

Init validates that the Firecracker binary and kernel exist.

func (*FirecrackerRuntime) Name

func (r *FirecrackerRuntime) Name() string

func (*FirecrackerRuntime) Stats

func (r *FirecrackerRuntime) Stats(_ context.Context, instanceID string) (*Stats, error)

Stats returns resource usage for a Firecracker microVM. For now, this queries /proc/{pid}/stat for basic metrics.

type FirecrackerTemplateBackend

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

FirecrackerTemplateBackend implements TemplateBackend for Firecracker by snapshotting the VM's rootfs disk state.

func NewFirecrackerTemplateBackend

func NewFirecrackerTemplateBackend(rt *FirecrackerRuntime, dataDir string) *FirecrackerTemplateBackend

NewFirecrackerTemplateBackend creates a template backend for Firecracker VMs.

func (*FirecrackerTemplateBackend) Capture

func (b *FirecrackerTemplateBackend) Capture(_ context.Context, instanceID, tag string) (string, int64, error)

Capture creates a template by copying the VM's current rootfs state. The tag is used as the snapshot filename.

func (*FirecrackerTemplateBackend) Remove

Remove deletes a snapshot file.

type Instance

type Instance struct {
	ID        string // Container ID or VM ID.
	AgentAddr string // "ip:port" for Docker, "vsock:CID:port" for Firecracker.
}

Instance represents a running sandbox unit (container or microVM).

type Runtime

type Runtime interface {
	// Name returns the runtime identifier (e.g. "docker", "firecracker").
	Name() string

	// Init performs one-time setup such as creating networks or validating
	// paths. Called once at daemon start.
	Init(ctx context.Context) error

	// Create creates and starts a new sandbox instance. It must wait for the
	// guest agent to become reachable before returning.
	Create(ctx context.Context, opts CreateOpts) (*Instance, error)

	// Destroy stops and removes a sandbox instance.
	Destroy(ctx context.Context, instanceID string) error

	// Stats returns resource usage for a sandbox instance.
	Stats(ctx context.Context, instanceID string) (*Stats, error)

	// DialAgent returns a connection to the agent inside the instance.
	DialAgent(ctx context.Context, instanceID string, timeout time.Duration) (net.Conn, error)

	// Close releases any resources held by the runtime.
	Close() error
}

Runtime abstracts the sandbox execution backend (Docker, Firecracker, etc.).

type Stats

type Stats struct {
	CPUPercent    float64
	MemoryUsage   uint64
	MemoryLimit   uint64
	MemoryPercent float64
	NetRxBytes    uint64
	NetTxBytes    uint64
	PIDs          uint64
}

Stats holds resource usage metrics for a sandbox instance.

Jump to

Keyboard shortcuts

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