workspace

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package workspace bounds temporary worker storage independently of job output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Root          string
	Policy        Policy
	Job           sandbox.Job
	ServiceMemory uint64
	Deadline      time.Time
	Authorize     func(context.Context, sandbox.Job) error
}

Config binds workspace storage to one signed job and its original deadline. Root must already exist with root ownership and mode 0o700. Authorize must check current host grants for this exact job and honor context cancellation.

type Paths

type Paths struct {
	JobID                                               id.ID
	JobDigest                                           string
	Directory, Images, Inputs, Bundle, Runtime, Scratch string
}

Paths names host-controlled staging and guest scratch directories. They carry no authority; call Check before using them for staging, execution or export.

type Policy

type Policy struct {
	StagingBytes       int64 `json:"staging_bytes"`
	StagingInodes      int64 `json:"staging_inodes"`
	ScratchInodes      int64 `json:"scratch_inodes"`
	ReserveMemoryBytes int64 `json:"reserve_memory_bytes"`
}

Policy is host configuration, pinned by the worker launch profile. Staging covers image, input, bundle and runtime files; scratch is a separate filesystem bounded by the signed job. ReserveMemoryBytes leaves room for worker overhead.

func (Policy) Admit

func (p Policy) Admit(job sandbox.Job, serviceMemory uint64) error

Admit requires storage, guest memory and the overhead reservation to fit the outer service ceiling. This is a limit check, not a promise of runtime capacity.

func (Policy) Validate

func (p Policy) Validate() error

Validate rejects unlimited storage, inode counts and unbounded reservations.

type Workspace

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

Workspace owns one exclusive job directory and two quota-enforced filesystems. It never reuses retained job directories. Failed cleanup requires retry or independent service cleanup before the retained directory can be reclaimed.

func Create

func Create(ctx context.Context, cfg Config) (*Workspace, error)

Create requires the exact Linux worker containment and a private mount namespace. A nonnil workspace returned with an error has unresolved cleanup; it cannot be used and the caller must retain it for Close or exit the worker.

func (*Workspace) Check

func (w *Workspace) Check(ctx context.Context) error

Check revalidates current authority, containment and storage without extending the signed deadline. It serializes with Close so cleanup cannot overlap it.

func (*Workspace) Close

func (w *Workspace) Close(ctx context.Context) error

Close retries normal unmount and removes only owned, empty mountpoints and the original job directory. It ignores execution grants and uses a fresh caller context capped at ten seconds; cancellation of the job does not waive cleanup.

func (*Workspace) Paths

func (w *Workspace) Paths() (Paths, error)

Paths returns a snapshot only while setup is complete and cleanup has not begun.

func (*Workspace) VerifyStorage

func (w *Workspace) VerifyStorage(ctx context.Context) error

VerifyStorage checks the retained filesystem identity without granting execution authority. Runtime cleanup may call it after grants or the signed deadline expire, using its own independent bounded context.

Jump to

Keyboard shortcuts

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