Files
ilkerandClaude Opus 5 421efc1d42 hpcod: make oversubscription a switch, and turn it on for hv01
There was already a cpu_overcommit multiplier, but a multiplier is not a
policy. Nothing said whether a site was meant to be strict, a ratio left in
the file kept inflating capacity indefinitely, and the resulting number was
reported on its own - "56 cores" being either a machine or a decision, with
no way to tell which.

Now: oversubscribe is the switch, off by default, and the ratios say how
much. Separating them means turning the policy off does not mean editing
the numbers back to 1.0 and losing what they were tuned to. Every
combination that has more than one meaning is refused at startup - a ratio
above 1 with the switch off, the switch on with nothing to multiply - so a
config that reads as strict cannot quietly be anything else.

Memory joins CPU, because it had no ratio at all and enabling only CPU
would have moved the refusal from one resource to the other. They are not
equally safe and the comments say so: oversubscribed cores make jobs slow,
oversubscribed memory makes them die.

The inventory now carries the hardware alongside the schedulable figures,
and both the CLI and the plan output say when a node is oversubscribed and
by how much. A held device is finally printed too - discovery learned who
owns each card in the previous commit, and nothing displayed it.

Enabled on hv01 at cpu 6.0, mem 1.3, chosen by measurement. 28 cores with
153 vCPU already committed by 36 running guests, load average 2.3: the box
is committed, not busy, so 6.0 sits just above what is already promised.
Guests claim 618 GiB of 503 and ballooning absorbs it, with 118 GiB
genuinely available, so 1.3 promises about 36 GiB more than today and stays
inside what the host can actually produce.

Measured both ways, because a switch tested in one direction is untested:

  off  28 cores (0 free), 504 GiB (0 free)    request rejected
  on   168 cores (15 free), 655 GiB (37 free) PLACED, compute1 gets
                                              gpu 0000:01:00.0 (Quadro K620)

The live config was the contradictory case - ratio 2.0, no switch - and
startup refused it by name before it was fixed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 23:14:30 +02:00

79 lines
2.2 KiB
Go

package provider
import (
"fmt"
"os"
"strconv"
"strings"
)
// SiteConfig describes one backing cloud.
//
// Settings is intentionally untyped: each provider needs different fields
// (Proxmox wants an API token, OpenStack wants an application credential and a
// region) and the loader should not have to know about any of them.
type SiteConfig struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Kind string `yaml:"kind"`
Settings map[string]string `yaml:"settings"`
}
// Setting returns a required setting, resolving "env:NAME" indirection so that
// secrets live in the environment rather than in the config file.
func (c SiteConfig) Setting(key string) (string, error) {
v, ok := c.Settings[key]
if !ok || v == "" {
return "", fmt.Errorf("site %q: missing required setting %q", c.ID, key)
}
if env, found := strings.CutPrefix(v, "env:"); found {
got := os.Getenv(env)
if got == "" {
return "", fmt.Errorf("site %q: setting %q refers to $%s, which is unset",
c.ID, key, env)
}
return got, nil
}
return v, nil
}
// SettingOr returns a setting or a default, with the same env: indirection.
func (c SiteConfig) SettingOr(key, def string) string {
if _, ok := c.Settings[key]; !ok {
return def
}
v, err := c.Setting(key)
if err != nil {
return def
}
return v
}
// BoolSetting reports a boolean setting, defaulting when absent or unparsable.
func (c SiteConfig) BoolSetting(key string, def bool) bool {
v := strings.ToLower(strings.TrimSpace(c.SettingOr(key, "")))
switch v {
case "true", "yes", "1":
return true
case "false", "no", "0":
return false
default:
return def
}
}
// FloatSetting reads a numeric setting. Unlike BoolSetting it reports a bad
// value rather than falling back, because a ratio silently read as its
// default changes how much hardware a site appears to have.
func (c SiteConfig) FloatSetting(key string, def float64) (float64, error) {
raw := strings.TrimSpace(c.SettingOr(key, ""))
if raw == "" {
return def, nil
}
f, err := strconv.ParseFloat(raw, 64)
if err != nil {
return 0, fmt.Errorf("site %q: setting %q must be a number, got %q", c.ID, key, raw)
}
return f, nil
}