Documentation
¶
Index ¶
- func VsockAddr(cid, port uint32) string
- type CreateOpts
- type DockerRuntime
- func (r *DockerRuntime) Close() error
- func (r *DockerRuntime) Create(ctx context.Context, opts CreateOpts) (*Instance, error)
- func (r *DockerRuntime) Destroy(ctx context.Context, instanceID string) error
- func (r *DockerRuntime) DialAgent(_ context.Context, _ string, timeout time.Duration) (net.Conn, error)
- func (r *DockerRuntime) Init(ctx context.Context) error
- func (r *DockerRuntime) Name() string
- func (r *DockerRuntime) Stats(ctx context.Context, instanceID string) (*Stats, error)
- type FirecrackerRuntime
- func (r *FirecrackerRuntime) Close() error
- func (r *FirecrackerRuntime) Create(ctx context.Context, opts CreateOpts) (*Instance, error)
- func (r *FirecrackerRuntime) Destroy(_ context.Context, instanceID string) error
- func (r *FirecrackerRuntime) DialAgent(_ context.Context, instanceID string, timeout time.Duration) (net.Conn, error)
- func (r *FirecrackerRuntime) Init(_ context.Context) error
- func (r *FirecrackerRuntime) Name() string
- func (r *FirecrackerRuntime) Stats(_ context.Context, instanceID string) (*Stats, error)
- type FirecrackerTemplateBackend
- type Instance
- type Runtime
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) 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
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 ¶
func (r *FirecrackerRuntime) Init(_ context.Context) error
Init validates that the Firecracker binary and kernel exist.
func (*FirecrackerRuntime) Name ¶
func (r *FirecrackerRuntime) Name() string
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.
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.).