Documentation
¶
Overview ¶
Package settings is the handful of host knobs an operator may change at RUNTIME, without restarting the control container.
── SEVEN KEYS, AND THE LIST IS CLOSED ───────────────────────────────────────────────────────────
max_jobs integer >= 1 how many lifecycle jobs run at once across every stack default_role one of the four the role an account created with no role named gets pressure_disk_pct integer 0–100 disk used % that puts a node in pressure (90) pressure_mem_pct integer 0–100 MemAvailable % at or below which a node is in pressure (10) pressure_cpu_load number >= 0 5-min load per core that puts a node in pressure (2) pressure_sleep_idle_min integer 0–525600 idle minutes before pressure may sleep a stack (30) image_prune_after_h integer 0–87600 age in hours of an unused image the prune removes (168)
For the last five, `0` turns that thing off (docs/node-pressure-design.md §3). The two upper bounds, a year of minutes and ten years of hours, keep minutes × 60 000 in an int64 and the prune's `until=<N>h` a duration docker takes.
This is NOT a generic key-value store: Set validates both the key and the value, and an unknown key is REFUSED rather than stored. A settings table that accepts anything becomes the dumping ground the migration says it is not, and every "just one more key" arrives without a validator. Adding a key is an arm in Set's and Usable's switches, a reader beside MaxJobs, and a permissions row.
It is also not a hole in invariant 10: every row is configuration an operator CHOSE. Nothing here describes what is running.
── PRECEDENCE, PER KEY ──────────────────────────────────────────────────────────────────────────
max_jobs database > PSTACK_MAX_JOBS (envMaxJobs) > jobs.DefaultMaxRunning default_role database > viewer — there is NO environment variable the five pressure keys database > the default above — no environment variable either
The environment variable is the DEFAULT, not the authority. An operator who never opens the UI keeps exactly the behaviour they had, and one who sets the value in the UI is not overridden by the container's environment on the next restart. (`PSTACK_MAX_JOBS` is parsed once at boot by the API's TuningFromEnv and handed in here — this package reads no environment itself, so there is one parse of that variable and one place to find it.)
── A READ NEVER FAILS, IT RESOLVES DOWNWARD ─────────────────────────────────────────────────────
The readers return a value and no error. A database that will not answer, a missing row and a row an operator hand-edited to nonsense all fall to the next source down, because every caller's alternative is worse in exactly one direction:
- max_jobs — a zero cap would stall every job on the host. Falling back keeps it running.
- default_role — an unrankable role is refused by auth.Role.Rank, so a garbage row would mint accounts that can do nothing; falling back to `viewer` is the same least-privilege direction the rest of the auth code takes. It can never resolve UPWARD, and never to admin.
- the pressure keys — a garbage row read as 0 would silently turn a guard off. The default keeps it on.
Usable is the one predicate for "is this stored row a value its reader takes": the readers and the API's `source` both use it, so the two cannot disagree about a hand-edited row.
── NEVER CALL A READER FROM INSIDE store.Tx ─────────────────────────────────────────────────────
Every method here goes to Store.DB, and the pool is ONE connection (store's header, rule 16): a read from inside a transaction waits for the connection that transaction holds — a permanent self-deadlock. auth.SsoSignIn is one long transaction, so the SSO default role must be resolved BEFORE it is called and handed in as SsoSignInOpts.DefaultRole, never looked up in provision.
Index ¶
- Constants
- func IsError(err error) bool
- func Usable(key, raw string) bool
- type Error
- type Settings
- func (s *Settings) DefaultRole() string
- func (s *Settings) ImagePruneAfterH() int
- func (s *Settings) MaxJobs() int
- func (s *Settings) PressureCPULoad() float64
- func (s *Settings) PressureDiskPct() int
- func (s *Settings) PressureMemPct() int
- func (s *Settings) PressureSleepIdleMin() int
- func (s *Settings) Set(key, value string) error
Constants ¶
const ( KeyMaxJobs = "max_jobs" KeyDefaultRole = "default_role" KeyPressureDiskPct = "pressure_disk_pct" KeyPressureMemPct = "pressure_mem_pct" KeyPressureCPULoad = "pressure_cpu_load" KeyPressureSleepIdleMin = "pressure_sleep_idle_min" KeyImagePruneAfterH = "image_prune_after_h" )
The keys. There are no others, and Set refuses anything that is not one of these.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct{ Msg string }
Error is a refused key or value. The API maps it to 400.
type Settings ¶
Settings is the table. Owner: the server; every method is one statement.
func New ¶
New wraps a store. envMaxJobs is api.Options.MaxJobs (PSTACK_MAX_JOBS), zero meaning unset.
func (*Settings) DefaultRole ¶
DefaultRole is the role for an account created with no role named: database > viewer.
It NEVER widens what a caller may do. It decides what accounts they create get, and creating an account is already admin-only; the SSO side asks for it only when a provider's own defaultRole is empty ("inherit the host default"). A stored value that is not one of the four is ignored, so this cannot resolve to anything unrankable — or to admin by omission.
func (*Settings) ImagePruneAfterH ¶ added in v0.45.0
ImagePruneAfterH is the age in hours of an unused image the prune removes: database > 168.
func (*Settings) MaxJobs ¶
MaxJobs is the running-job cap: database > PSTACK_MAX_JOBS > jobs.DefaultMaxRunning.
The result is what jobs.Registry.SetMaxRunning is given, at boot and after every write. Lowering it cancels nothing that is already running — see that method.
func (*Settings) PressureCPULoad ¶ added in v0.45.0
PressureCPULoad is the 5-min load per core that puts a node in pressure: database > 2.
func (*Settings) PressureDiskPct ¶ added in v0.45.0
PressureDiskPct is the disk used % that puts a node in pressure: database > 90. 0 is off.
func (*Settings) PressureMemPct ¶ added in v0.45.0
PressureMemPct is the MemAvailable % at or below which a node is in pressure: database > 10.
func (*Settings) PressureSleepIdleMin ¶ added in v0.45.0
PressureSleepIdleMin is how long a stack must sit idle before pressure may sleep it: database > 30.
func (*Settings) Set ¶
Set validates and stores one setting. The key must be one of the seven and the value must be valid FOR that key; anything else returns *Error and writes nothing.
Values are stored in canonical form ("008" becomes "8"), so a reader never has to be lenient about what a writer accepted.