Files
ilkerandClaude Opus 5 9ad16290bf hpcod: oversubscription is a policy you can change, not a line in a file
It was enabled - 168 cores offered from 28, 655 GiB from 504 - but only
because I edited sites.yaml on the server and restarted the service. So
changing it needed a shell, an editor and a restart, which means it needed
whoever had those rather than whoever had the judgement. It is a judgement
about how much of the hardware to promise, it moves with load, and it
belongs where the person making it can reach it.

It is now a row per site, set from the Sites page by an administrator, and
it takes effect on the next discovery sweep rather than the next restart.

The ratio is applied after discovery instead of inside the provider, which
is what makes that possible - and because it recomputes from the physical
core and memory counts rather than from whatever Cores already held,
applying it twice gives the same answer as applying it once. Without that
the provider's own default would compound with it.

The file stays as the default. A site with no row shows what the catalogue
gave it, read back from the numbers rather than claimed, and says so: "from
the site catalogue - nobody has set this" against "set by ilker". One
authority at a time, and the page says which.

The rules the config loader already enforced are enforced here too, in the
database rather than in the handler: a policy that reads as off cannot
still multiply, and turning it off resets the ratios instead of leaving
numbers behind that would take effect again for whoever turns it back on.
Memory is capped at 8x where CPU is capped at 64x, because oversubscribed
cores make jobs slow and oversubscribed memory makes them die.

Also fixed a test that was crying wolf: the public-page leak check matched
bare substrings, so adding a "label" rule to the stylesheet looked like the
tenant name "lab" appearing on the front door. It matches word boundaries
now - a test that raises false alarms gets weakened until it stops catching
anything.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 12:54:24 +02:00

64 lines
1.9 KiB
Go

package model
// Overcommit is how much of a site may be promised beyond what it has.
//
// It lives with the inventory types rather than with the provider because
// it is not a property of Proxmox: every backing cloud has the same
// question, and the answer is the operator's, not the cloud's.
type Overcommit struct {
Site string `json:"site"`
Enabled bool `json:"enabled"`
CPU float64 `json:"cpu"`
Mem float64 `json:"mem"`
UpdatedBy string `json:"updated_by,omitempty"`
// FromFile marks a policy that is still whatever the site catalogue
// said, with nothing recorded against it. Worth showing: it is the
// difference between a number someone chose and a number nobody has
// looked at.
FromFile bool `json:"from_file"`
}
// Ratios returns the multipliers to apply, which are 1.0 whenever the
// policy is off however the ratios were left.
func (o Overcommit) Ratios() (cpu, mem float64) {
if !o.Enabled {
return 1, 1
}
cpu, mem = o.CPU, o.Mem
if cpu < 1 {
cpu = 1
}
if mem < 1 {
mem = 1
}
return cpu, mem
}
// ApplyOvercommit recomputes what each node may be promised.
//
// It works from the physical figures, not from whatever Cores already
// held, so applying it twice gives the same answer as applying it once -
// which matters because the provider has already applied its own default
// by the time this runs.
//
// A node that never reported its physical capacity is left alone. Guessing
// would mean inventing hardware.
func ApplyOvercommit(sites []Site, policies map[string]Overcommit) {
for si := range sites {
p, ok := policies[sites[si].ID]
if !ok {
continue
}
cpu, mem := p.Ratios()
for ni := range sites[si].Nodes {
n := &sites[si].Nodes[ni]
if n.PhysicalCores > 0 {
n.Cores = int(float64(n.PhysicalCores) * cpu)
}
if n.PhysicalMemBytes > 0 {
n.MemBytes = int64(float64(n.PhysicalMemBytes) * mem)
}
}
}
}