Documentation
¶
Index ¶
- Variables
- type Engine
- func (e *Engine) CreateSandbox(ctx context.Context, cfg runtime.SandboxConfig) (*Sandbox, error)
- func (e *Engine) CurrentPressure() PressureEvent
- func (e *Engine) DeleteSnapshot(ctx context.Context, snapshotID string) error
- func (e *Engine) DestroySandbox(ctx context.Context, id string) error
- func (e *Engine) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (*runtime.ExecResult, error)
- func (e *Engine) ExecStream(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.ExecStream, error)
- func (e *Engine) GetSandbox(id string) (*Sandbox, error)
- func (e *Engine) ListDir(ctx context.Context, id string, path string) ([]runtime.FileInfo, error)
- func (e *Engine) ListSandboxes() []*Sandbox
- func (e *Engine) ListSnapshots(ctx context.Context, sandboxID string) ([]runtime.SnapshotInfo, error)
- func (e *Engine) MkDir(ctx context.Context, id string, path string) error
- func (e *Engine) PressureThresholds() PressureThresholds
- func (e *Engine) ReadFile(ctx context.Context, id string, path string) ([]byte, error)
- func (e *Engine) RemoveFile(ctx context.Context, id string, path string) error
- func (e *Engine) RestoreSnapshot(ctx context.Context, snapshotID string) (*Sandbox, error)
- func (e *Engine) SandboxCount() (total, running int)
- func (e *Engine) Shutdown(_ context.Context)
- func (e *Engine) Snapshot(ctx context.Context, id string, name string) (*runtime.SnapshotInfo, error)
- func (e *Engine) Stats(ctx context.Context, id string) (*runtime.SandboxStats, error)
- func (e *Engine) StopSandbox(ctx context.Context, id string) error
- func (e *Engine) WriteFile(ctx context.Context, id string, path string, content []byte) error
- type LinuxMemoryBackend
- type MemoryBackend
- type PressureEvent
- type PressureLevel
- type PressureMonitor
- type PressureThresholds
- type Sandbox
- type WarmPool
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates sandbox lifecycle.
func NewEngine ¶
func NewEngine(rt runtime.Runtime, st store.Store, cfg config.SandboxConfig, s3Cfg config.S3Config, resCfg config.ResourceConfig, logger *slog.Logger) *Engine
NewEngine creates a new Engine.
func (*Engine) CreateSandbox ¶
CreateSandbox creates and starts a new sandbox.
func (*Engine) CurrentPressure ¶ added in v0.0.6
func (e *Engine) CurrentPressure() PressureEvent
CurrentPressure returns the current pressure event.
func (*Engine) DeleteSnapshot ¶
DeleteSnapshot removes a snapshot.
func (*Engine) DestroySandbox ¶
DestroySandbox stops and removes a sandbox.
func (*Engine) Exec ¶
func (e *Engine) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (*runtime.ExecResult, error)
Exec runs a command in a sandbox.
func (*Engine) ExecStream ¶
func (e *Engine) ExecStream(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.ExecStream, error)
ExecStream runs a streaming command in a sandbox.
func (*Engine) GetSandbox ¶
GetSandbox returns a sandbox by ID.
func (*Engine) ListSandboxes ¶
ListSandboxes returns all tracked sandboxes.
func (*Engine) ListSnapshots ¶
func (e *Engine) ListSnapshots(ctx context.Context, sandboxID string) ([]runtime.SnapshotInfo, error)
ListSnapshots returns all snapshots for a sandbox.
func (*Engine) PressureThresholds ¶ added in v0.0.6
func (e *Engine) PressureThresholds() PressureThresholds
PressureThresholds returns the configured pressure thresholds.
func (*Engine) RemoveFile ¶
RemoveFile removes a file from a sandbox.
func (*Engine) RestoreSnapshot ¶
RestoreSnapshot restores a sandbox from a snapshot.
func (*Engine) SandboxCount ¶ added in v0.0.6
SandboxCount returns total and running sandbox counts without allocating a slice.
func (*Engine) Shutdown ¶
Shutdown gracefully stops all sandboxes. Uses a detached context so shutdown is not cancelled by the caller's context.
func (*Engine) Snapshot ¶
func (e *Engine) Snapshot(ctx context.Context, id string, name string) (*runtime.SnapshotInfo, error)
Snapshot creates a snapshot of a sandbox.
func (*Engine) StopSandbox ¶
StopSandbox stops a sandbox without removing it.
type LinuxMemoryBackend ¶ added in v0.0.6
type LinuxMemoryBackend struct{}
LinuxMemoryBackend reads memory info from /proc/meminfo and cgroup v2 files.
func (*LinuxMemoryBackend) ContainerMemory ¶ added in v0.0.6
func (b *LinuxMemoryBackend) ContainerMemory(containerID string) (uint64, error)
func (*LinuxMemoryBackend) HostMemory ¶ added in v0.0.6
func (b *LinuxMemoryBackend) HostMemory() (total, used, free uint64, err error)
type MemoryBackend ¶ added in v0.0.6
type MemoryBackend interface {
// HostMemory returns total, used, and free host memory in bytes.
HostMemory() (total, used, free uint64, err error)
// ContainerMemory returns memory usage in bytes for a specific container.
ContainerMemory(containerID string) (uint64, error)
}
MemoryBackend abstracts platform-specific memory reading. Linux uses /proc/meminfo + cgroup v2, macOS uses sysctl + Docker API.
func NewPlatformMemoryBackend ¶ added in v0.0.6
func NewPlatformMemoryBackend() MemoryBackend
type PressureEvent ¶ added in v0.0.6
type PressureEvent struct {
Level PressureLevel
MemoryUsed uint64
MemoryTotal uint64
Score float64
Timestamp time.Time
}
PressureEvent is emitted when the pressure level changes.
type PressureLevel ¶ added in v0.0.6
type PressureLevel int
PressureLevel represents the current host memory pressure.
const ( PressureNormal PressureLevel = iota // < 70% PressureWarning // 70-80% PressureHigh // 80-90% PressureCritical // 90-95% PressureEmergency // > 95% )
func (PressureLevel) String ¶ added in v0.0.6
func (p PressureLevel) String() string
type PressureMonitor ¶ added in v0.0.6
type PressureMonitor struct {
// contains filtered or unexported fields
}
PressureMonitor observes host memory pressure and notifies listeners. It implements hysteresis: a level change requires 2 consecutive matching readings.
func NewPressureMonitor ¶ added in v0.0.6
func NewPressureMonitor(backend MemoryBackend, interval time.Duration, thresholds PressureThresholds, logger *slog.Logger) *PressureMonitor
NewPressureMonitor creates a new PressureMonitor.
func (*PressureMonitor) CurrentEvent ¶ added in v0.0.6
func (pm *PressureMonitor) CurrentEvent() PressureEvent
CurrentEvent returns the most recent pressure event.
func (*PressureMonitor) Start ¶ added in v0.0.6
func (pm *PressureMonitor) Start()
Start begins the monitoring loop in a goroutine. Safe to call multiple times.
func (*PressureMonitor) Stop ¶ added in v0.0.6
func (pm *PressureMonitor) Stop()
Stop signals the monitor to stop and waits for the goroutine to finish. Safe to call multiple times.
func (*PressureMonitor) Subscribe ¶ added in v0.0.6
func (pm *PressureMonitor) Subscribe(ch chan<- PressureEvent)
Subscribe registers a channel to receive pressure events. The channel should be buffered to avoid blocking the monitor.
type PressureThresholds ¶ added in v0.0.6
type PressureThresholds struct {
Warning float64 // default: 0.70
High float64 // default: 0.80
Critical float64 // default: 0.90
Emergency float64 // default: 0.95
}
PressureThresholds defines the memory usage thresholds for each pressure level.
func DefaultPressureThresholds ¶ added in v0.0.6
func DefaultPressureThresholds() PressureThresholds
DefaultPressureThresholds returns the default thresholds.
type Sandbox ¶
type Sandbox struct {
ID string `json:"id"`
Image string `json:"image"`
Config runtime.SandboxConfig `json:"-"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Ports []runtime.PortMapping `json:"ports,omitempty"`
// contains filtered or unexported fields
}
Sandbox represents a managed sandbox instance.
func (*Sandbox) GetStatus ¶
func (s *Sandbox) GetStatus() runtime.SandboxStatus
GetStatus returns the sandbox status (thread-safe).
func (*Sandbox) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling to include the status field.
func (*Sandbox) SetStatus ¶
func (s *Sandbox) SetStatus(status runtime.SandboxStatus)
SetStatus updates the sandbox status (thread-safe).
type WarmPool ¶
type WarmPool struct {
// contains filtered or unexported fields
}
WarmPool pre-creates containers so sandbox creation is near-instant.
func NewWarmPool ¶
func NewWarmPool(rt runtime.Runtime, size int, cfg runtime.SandboxConfig, logger *slog.Logger) *WarmPool
NewWarmPool creates a warm pool that maintains `size` pre-created containers.
func (*WarmPool) Acquire ¶
Acquire gets a pre-warmed container ID from the pool. Returns empty string if pool is empty (caller should create normally).