Documentation
¶
Overview ¶
Package lease holds the machine's shared resources, one holder at a time: kind labs, shared installations, the browser. A lease is a directory (mkdir is atomic) holding the holder's record; the record's fields are the ones the lab's earlier shell lock wrote, so both read the same directory.
Grants live in the state document and queue claims in grant order. A resource with no pending grants can be claimed directly.
Index ¶
- func Check(st *state.State, g Gate) (int, error)
- func IsDestructiveProof(purpose string) bool
- func LabDiff(was, now []byte) ([]string, error)
- func Pending(st *state.State, res string, held bool, now time.Time, ttl time.Duration) []state.Grant
- func Prune(st *state.State, held map[string]bool, now time.Time, ttl time.Duration)
- func ToHead(st *state.State, i int, now time.Time) int
- type Dir
- func (d Dir) Claim(res string, h Holder) (*Holder, error)
- func (d Dir) ClaimedLabConfig(res string) ([]byte, error)
- func (d Dir) DropLabChange(res string) error
- func (d Dir) Get(res string) (*Holder, error)
- func (d Dir) Hand(h Holder) error
- func (d Dir) KeepLabConfig(res string, raw []byte) error
- func (d Dir) LabChangeOf(res string) (*LabChange, error)
- func (d Dir) LeaveLabChange(res string, c LabChange) error
- func (d Dir) List() ([]Holder, error)
- func (d Dir) PreviousProof(res string) (*Proof, error)
- func (d Dir) Release(res string) error
- func (d Dir) RestoreLabConfig(res, path string) (string, error)
- type Gate
- type Holder
- type LabChange
- type LabConfig
- type Proof
- type Refusal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check admits the head grant only; an empty queue permits a direct claim. Upgrade holds require an upgrade-unblock grant.
func IsDestructiveProof ¶
IsDestructiveProof recognizes purposes that may leave a lab disrupted.
func LabDiff ¶ added in v0.160.0
LabDiff names the keys in which two agentlab.yaml files differ, as dotted paths to the first value that is no map (a list is one value), sorted.
func Pending ¶
func Pending(st *state.State, res string, held bool, now time.Time, ttl time.Duration) []state.Grant
Pending returns the grants of res still claimable, in order.
Types ¶
type Dir ¶
type Dir string
Dir is the lease directory.
func (Dir) Claim ¶
Claim takes res for h. It returns the current holder instead when res is held already.
func (Dir) ClaimedLabConfig ¶ added in v0.160.0
ClaimedLabConfig is the agentlab.yaml the claim of res kept.
func (Dir) DropLabChange ¶ added in v0.160.0
DropLabChange ends the wait of the change left for res: its claim took it.
func (Dir) Get ¶
Get returns the holder of res, or nil when it is free. A record that cannot be read or decoded is a damaged holder: the resource stays held, named, and the error is the caller's only for the lease directory itself.
func (Dir) Hand ¶ added in v0.140.1
Hand gives the lease h.Env, held, to h: its record is replaced in one rename, so a reader sees the old holder or the new one, never none.
func (Dir) KeepLabConfig ¶ added in v0.160.0
KeepLabConfig keeps raw, the lab's agentlab.yaml at the claim of res, in the lease of res.
func (Dir) LabChangeOf ¶ added in v0.160.0
LabChangeOf is the change a release of res left for its next claim, nil when none waits.
func (Dir) LeaveLabChange ¶ added in v0.160.0
LeaveLabChange keeps c for the next claim of res.
func (Dir) List ¶
List returns every held lease, oldest first; a damaged record is listed as its damaged holder, so a listing never calls an occupied resource free.
func (Dir) PreviousProof ¶
PreviousProof reads the last released holder's destructive purpose. The notice remains available for retries until the next release.
func (Dir) RestoreLabConfig ¶ added in v0.160.0
RestoreLabConfig writes the claim-time agentlab.yaml of res back to path in one rename through any symlink; the link stays in place and the configuration it replaces is kept as path.released. It returns where that copy is.
type Gate ¶
type Gate struct {
Resource string
Caller state.Party
// Held is whether the resource is held right now (by anyone).
Held bool
Now time.Time
TTL time.Duration
}
Gate is what a claim is checked against.
type Holder ¶
type Holder struct {
// Env is the resource; the field name is the shell lock's.
Env string `json:"env"`
Holder string `json:"holder"`
Session string `json:"session"`
HostSession string `json:"hostSession,omitempty"`
Name string `json:"name,omitempty"`
// Person, Team and Host are the holder party's.
Person string `json:"person,omitempty"`
Team string `json:"team,omitempty"`
Host string `json:"host,omitempty"`
Purpose string `json:"purpose"`
DestructiveProof bool `json:"destructiveProof,omitempty"`
PreviousProof *Proof `json:"previousProof,omitempty"`
Since string `json:"since"`
// UpgradeUnblock is the reason of the upgrade-unblock grant the claim
// was admitted by during an upgrade, empty for any other claim.
UpgradeUnblock string `json:"upgradeUnblock,omitempty"`
// BudgetGiB is what the holder's models may hold on the model server,
// 0 on every other resource.
BudgetGiB int `json:"budgetGiB,omitempty"`
// LabConfig is a lab's agentlab.yaml at the claim, nil on every other
// resource and on a lab whose configuration the claim could not read.
LabConfig *LabConfig `json:"labConfig,omitempty"`
// LabChange is the change the lab's previous release left, shown to
// this holder at its claim.
LabChange *LabChange `json:"labChange,omitempty"`
// Damaged is why the resource's record could not be read, empty for a
// readable one. A damaged lease stays held: only a forced release frees
// it.
Damaged string `json:"-"`
}
Holder is the record in <leaseDir>/<resource>/holder.json.
type LabChange ¶ added in v0.160.0
type LabChange struct {
By string `json:"by"`
At string `json:"at"`
Keys []string `json:"keys"`
// Why is the holder's declaration (release --keep-config), empty for a
// change released with --force and not declared.
Why string `json:"why,omitempty"`
}
LabChange is a lab's configuration a release left different from its claim-time state, kept for the next claim of the lab.
type LabConfig ¶ added in v0.160.0
type LabConfig struct {
Path string `json:"path"`
// SHA256 is the hash of the parsed configuration, so a comment agentlab
// rewrites (its version line) is no change.
SHA256 string `json:"sha256"`
ValuesFiles []string `json:"valuesFiles,omitempty"`
}
LabConfig is a lab's agentlab.yaml as the claim of its lease found it.