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.
While a supervisor is recorded, a free lease is not permission: a session claims only what the supervisor granted it, in the order the grants were given, from the supervisor's start to a deliberate stop, whether its session runs or has crashed. Grants live in the state document.
Index ¶
- func Check(st *state.State, g Gate) (int, error)
- 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) Release(res string) error
- func (d Dir) RestoreLabConfig(res, path string) (string, error)
- type Gate
- type Holder
- type LabChange
- type LabConfig
- type Refusal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check decides whether the caller may claim and, when a grant carries the claim, returns its index in st.Grants (-1 when none is needed). While an upgrade runs on the installation of the resource's name only an upgrade-unblock grant admits a claim, in grant order.
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) 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) 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
// Supervisor is the recorded supervisor, nil when none is.
Supervisor *state.Supervisor
// RestartUntil is set while the supervisor's CLI may still come back
// as a restart; Gone once its CLI stayed away longer: claims wait for
// its successor.
RestartUntil time.Time
Gone bool
// 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"`
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"`
}
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.