HA P1a #433: a CARLOS_POOLS token for the shared pool
CARLOS_POOLS could not name the shared "" pool beside a named one, so a
dev box could not serve both its ordinary instances and a test pool
(hapair) shared with another box.
provision.ParseBoxPools is now the one parser (the provision tick, and
through its config the edges file's serves_shared_pool; boxPools for the
rootfs refusal), replacing two copies. The token "@shared"
(provision.SharedPoolToken) is the shared pool; the pool grammar
[a-z0-9-]{0,16} can never name it. Other tokens are literal, as before;
one that is no pool name is logged once and serves no pool a door
creates. Empty elements are still dropped (",tito" serves tito alone),
repeats are dropped, and unset is still the shared pool alone. boxPools
leaves the shared pool out, so "@shared" alone keeps the shared-box
refusal text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+122
−13
internal/host/agent.go+1 −6internal/host/edgesfile_test.go+3 −0internal/host/host_test.go+12 −0internal/host/rootfsplacement.go+10 −7internal/provision/boxpools_test.go+53 −0internal/provision/reconcile.go+41 −0internal/provision/reconcile_eligibility_test.go+2 −0
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 5bd85df81..7e9d28513 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -3489,12 +3489,7 @@ func domainsTickConfig(getenv func(string) string, publicIP string) (domains.Con |
| // record's own "no-inbound" placement request — see ReconcileConfig.Inbound. |
| func provisionTickConfig(getenv func(string) string) provision.ReconcileConfig { |
| region := strings.TrimSpace(getenv("CARLOS_REGION")) |
| - var pools []string |
| - for _, p := range strings.Split(getenv("CARLOS_POOLS"), ",") { |
| - if p = strings.TrimSpace(p); p != "" { |
| - pools = append(pools, p) |
| - } |
| - } |
| + pools := provision.ParseBoxPools(getenv("CARLOS_POOLS")) |
| dd := getenv("CARLOS_DATA_DIR") |
| if dd == "" { |
| dd = "/data" |
diff --git a/internal/host/edgesfile_test.go b/internal/host/edgesfile_test.go| index 9d4ec950f..c16dfca27 100644 |
| --- a/internal/host/edgesfile_test.go |
| +++ b/internal/host/edgesfile_test.go |
| @@ -1264,6 +1264,9 @@ func TestEdgesFileEligibilityFollowsTheReconcileConfig(t *testing.T) { |
| {"", "", true, true}, |
| {"tito", "", false, true}, |
| {",tito", "", false, true}, |
| + {"@shared,hapair", "", true, true}, |
| + {"@shared", "", true, true}, |
| + {"cohort1,hapair", "", false, true}, |
| {"", "none", true, false}, |
| {"tito", "NONE", false, false}, |
| } |
diff --git a/internal/host/host_test.go b/internal/host/host_test.go| index 872e958ea..d96d2c955 100644 |
| --- a/internal/host/host_test.go |
| +++ b/internal/host/host_test.go |
| @@ -896,6 +896,18 @@ func TestProvisionTickConfig(t *testing.T) { |
| t.Errorf("Pools = %v, want empties dropped and whitespace trimmed", got.Pools) |
| } |
| + // The shared pool's token (provision.SharedPoolToken) is the "" pool, |
| + // beside a named one: one parser for the tick and for boxPools. |
| + got = provisionTickConfig(env(map[string]string{"CARLOS_POOLS": "@shared, hapair"})) |
| + if !reflect.DeepEqual(got.Pools, []string{"", "hapair"}) { |
| + t.Errorf("Pools = %#v, want the shared pool and hapair", got.Pools) |
| + } |
| + for raw, want := range map[string]string{"": "", "@shared": "", "@shared,hapair": "hapair", "cohort1, hapair": "cohort1,hapair"} { |
| + if got := boxPools(env(map[string]string{"CARLOS_POOLS": raw})); got != want { |
| + t.Errorf("boxPools(%q) = %q, want %q", raw, got, want) |
| + } |
| + } |
| + |
| got = provisionTickConfig(env(map[string]string{"CARLOS_DATA_DIR": "/custom"})) |
| if got.DataDir != "/custom" { |
| t.Errorf("DataDir = %q, want /custom", got.DataDir) |
diff --git a/internal/host/rootfsplacement.go b/internal/host/rootfsplacement.go| index 66e47b851..b43c5b3cc 100644 |
| --- a/internal/host/rootfsplacement.go |
| +++ b/internal/host/rootfsplacement.go |
| @@ -23,6 +23,7 @@ import ( |
| "github.com/carlosframework/platform/internal/activator" |
| "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| @@ -305,16 +306,18 @@ func singleTenant(getenv func(string) string) bool { |
| } |
| } |
| -// boxPools is CARLOS_POOLS as the provision tick reads it: the non-empty |
| -// trimmed names, joined by commas. |
| +// boxPools is the dedicated pools this box serves, as the provision tick |
| +// reads CARLOS_POOLS (provision.ParseBoxPools), joined by commas: "" when |
| +// it serves the shared pool alone. The shared pool is no dedicated pool, |
| +// so it is left out. |
| func boxPools(getenv func(string) string) string { |
| - var pools []string |
| - for _, p := range strings.Split(getenv("CARLOS_POOLS"), ",") { |
| - if p = strings.TrimSpace(p); p != "" { |
| - pools = append(pools, p) |
| + var named []string |
| + for _, p := range provision.ParseBoxPools(getenv("CARLOS_POOLS")) { |
| + if p != "" { |
| + named = append(named, p) |
| } |
| } |
| - return strings.Join(pools, ",") |
| + return strings.Join(named, ",") |
| } |
| // rootfsReadiness is the control client's /ready/rootfs. |
diff --git a/internal/provision/boxpools_test.go b/internal/provision/boxpools_test.go| new file mode 100644 |
| index 000000000..b18ea986c |
| --- /dev/null |
| +++ b/internal/provision/boxpools_test.go |
| @@ -0,0 +1,53 @@ |
| +package provision |
| + |
| +import ( |
| + "reflect" |
| + "testing" |
| +) |
| + |
| +// CARLOS_POOLS (#433 follow-up): SharedPoolToken names the shared "" pool, |
| +// so a box can serve it beside a named pool. Every other token is taken |
| +// literally, as before, and an empty element is dropped, never read as the |
| +// shared pool (",tito" serves tito alone, codex R3-3). |
| +func TestParseBoxPools(t *testing.T) { |
| + for _, c := range []struct { |
| + raw string |
| + pools []string |
| + serve []string // pools served |
| + not []string // pools not served |
| + }{ |
| + {"", nil, []string{""}, []string{"hapair"}}, |
| + {"@shared", []string{""}, []string{""}, []string{"hapair", "@shared"}}, |
| + {"@shared,hapair", []string{"", "hapair"}, []string{"", "hapair"}, []string{"cohort1", "@shared"}}, |
| + {" hapair , @shared ,, ", []string{"hapair", ""}, []string{"", "hapair"}, []string{"cohort1"}}, |
| + {"cohort1,hapair", []string{"cohort1", "hapair"}, []string{"cohort1", "hapair"}, []string{""}}, |
| + {",tito", []string{"tito"}, []string{"tito"}, []string{""}}, |
| + {"hapair,@shared,hapair,@shared", []string{"hapair", ""}, []string{"", "hapair"}, nil}, |
| + // Not the token and not a pool name: literal, so it serves no |
| + // record a door mints, and never the shared pool. |
| + {"@Shared", []string{"@Shared"}, nil, []string{"", "shared"}}, |
| + {"@other,hapair", []string{"@other", "hapair"}, []string{"hapair"}, []string{"", "other"}}, |
| + } { |
| + got := ParseBoxPools(c.raw) |
| + if !reflect.DeepEqual(got, c.pools) { |
| + t.Errorf("ParseBoxPools(%q) = %#v, want %#v", c.raw, got, c.pools) |
| + } |
| + for _, p := range c.serve { |
| + if !poolServed(got, p) { |
| + t.Errorf("CARLOS_POOLS=%q does not serve pool %q", c.raw, p) |
| + } |
| + } |
| + for _, p := range c.not { |
| + if poolServed(got, p) { |
| + t.Errorf("CARLOS_POOLS=%q serves pool %q", c.raw, p) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// The token can never be a pool's name: the record grammar refuses it. |
| +func TestSharedPoolTokenIsNoPoolName(t *testing.T) { |
| + if ValidPool(SharedPoolToken) { |
| + t.Fatalf("%q is a valid pool name", SharedPoolToken) |
| + } |
| +} |
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go| index c47f75c7a..397d7e343 100644 |
| --- a/internal/provision/reconcile.go |
| +++ b/internal/provision/reconcile.go |
| @@ -2891,6 +2891,47 @@ func forEach(items []string, f func(string)) { |
| wg.Wait() |
| } |
| +// SharedPoolToken is the CARLOS_POOLS token for the shared "" pool, so a |
| +// box can serve it beside a named pool ("@shared,hapair"). A pool name is |
| +// [a-z0-9-]{0,16} (ValidPool), so no pool can be called this. |
| +const SharedPoolToken = "@shared" |
| + |
| +// ParseBoxPools parses CARLOS_POOLS, the pools this box serves, into |
| +// ReconcileConfig.Pools. It is the one parser: the provision tick, the |
| +// edges file's serves_shared_pool (through the same config) and the rootfs |
| +// placement refusal all read the variable through it. |
| +// |
| +// Elements are comma-separated and trimmed; an empty one is dropped, never |
| +// read as the shared pool (",tito" serves tito alone). SharedPoolToken is |
| +// the shared pool, "" in the result. Every other token is taken literally, |
| +// as before this token existed: one that is not a pool name (another "@" |
| +// word, "@Shared", upper case) matches no record a door mints and never |
| +// the shared pool, and is logged once. A repeat is dropped. No element at |
| +// all is nil, which poolServed reads as the shared pool alone. |
| +func ParseBoxPools(raw string) []string { |
| + var pools []string |
| + for _, p := range strings.Split(raw, ",") { |
| + p = strings.TrimSpace(p) |
| + switch { |
| + case p == "": |
| + continue |
| + case p == SharedPoolToken: |
| + p = "" |
| + case !ValidPool(p): |
| + if _, seen := oddBoxPools.LoadOrStore(p, true); !seen { |
| + log.Printf("provision: CARLOS_POOLS names %q, which is not a pool name (want [a-z0-9-]{0,16}, or %s for the shared pool); it serves no pool a door creates", p, SharedPoolToken) |
| + } |
| + } |
| + if !slices.Contains(pools, p) { |
| + pools = append(pools, p) |
| + } |
| + } |
| + return pools |
| +} |
| + |
| +// oddBoxPools is the CARLOS_POOLS tokens ParseBoxPools has logged. |
| +var oddBoxPools sync.Map |
| + |
| // poolServed reports whether pool is one this box serves. An empty |
| // cfg.Pools means the shared "" pool ONLY, never "every pool" — the same |
| // convention domains.Config's AppsDomain=="" carries: unconfigured means the |
diff --git a/internal/provision/reconcile_eligibility_test.go b/internal/provision/reconcile_eligibility_test.go| index 6f9ac5556..6c38cd5e2 100644 |
| --- a/internal/provision/reconcile_eligibility_test.go |
| +++ b/internal/provision/reconcile_eligibility_test.go |
| @@ -13,6 +13,8 @@ func TestSharedInstanceEligibilityIsTheMintPredicate(t *testing.T) { |
| {nil, "", true, true}, |
| {[]string{"tito"}, "", false, true}, |
| {[]string{"", "tito"}, "", true, true}, |
| + {ParseBoxPools("@shared,hapair"), "", true, true}, |
| + {ParseBoxPools("cohort1,hapair"), "", false, true}, |
| {nil, InboundNone, true, false}, |
| {[]string{"tito"}, InboundNone, false, false}, |
| } |