console: no unlabelled process creates on multi-box fleets (D1)
On a fleet with two or more active boxes, a create of a process the platform runs is labelled at create (chooseMoveDestination with the channel head's manifest, then MarkFleetBoxLabelled) or refused before any record, environment or claim write: 503, Retry-After 30 and C39 for an incomplete view, sidecars, a box or the console below FleetRecordLabelFloor (fleetAtRecordFloor, shared with the label door), no destination, or a failed mark; 409 and C42 for a record movable rejects. The view's unmovable records no longer keep creates unlabelled. One-box fleets, static and Addr records, seeds and imports, demos and host-claim consoles are unchanged. Fixtures that create on two-box fleets now run the record label floor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/apiinstances.go+48 −20internal/console/apiinstances_test.go+297 −0internal/console/appcopies_test.go+4 −2internal/console/fleetbox_test.go+29 −22internal/console/fleetcreate.go+119 −0internal/console/server.go+4 −0internal/console/stateless_floor_test.go+7 −5internal/host/fleettwobox_e2e_test.go+28 −8
Intent
<task-notification> <task-id>ab2cf8140995c083d</task-id> <tool-use-id>toolu_01PsEu6yhJsj7QhgPnxkAUw8</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/ab2cf8140995c083d.output</output-file> <status>completed</status> <summary>Agent "Implement Task 5: carlos instances label" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>- **Status:** DONE. All three review findings are fixed. - **Commits:** - `b39eecf5 cli: carlos instances label` - `7ad76752 console, cli: label answer names the coordinator and the floor box` - `083e9643 cli: label reads flags after the host; a gateway status is C38` - **Tests:** RED first: the flags-after-host test and both cut-off-body cases failed. Then GREEN: the brief's Step 4 command passes, `go test ./internal/parity` passes, and the darwin and windows builds compile. - **Argument order:** flags are now read on both sides of the host, so the order C01 shows and C14 prints works. - **Gateway answers:** on a write, a 502 or 504 now prints C38 even when the body is cut off. The new tests use a barrier, not sleeps, and the stub's error body no longer contains C38, so the test proves the CLI's own classification. - **`--account-id` help:** lowercase now, with no em dash. - **Concerns:** none new. The UX items for T7 are listed in the report. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-record-labels/.superpowers/sdd/2026-11-14-fleet-record-labels/task-5-report.md (round-1 fix report appended)</result> <usage><subagent_tokens>184308</subagent_tokens><tool_uses>5</tool_uses><duration_ms>97205</duration_ms></usage> </task-notification>
Attributed to this commit: 18.2 g CO₂e (2,139,816 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fleet-record-labels-m2, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index 5fb85f8b4..2cfda245e 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -2158,19 +2158,32 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| // Managed fleets 1b (rules 1, 7, 8): on a fleet the console labels, the |
| // record names the box that runs it. The fleet's lock is held from this |
| // read until the record is written, so concurrent creates count each |
| - // other's records and spread. fleetActive is nil unless the activation |
| - // gate is open; a view that cannot be read leaves the record unlabelled, |
| - // as on main, and the rootfs admission below asks as it always did. A |
| - // one-box fleet reads nothing beyond its registry rows. |
| - var fleetActive *fleetView |
| + // other's records and spread. A one-box fleet reads nothing beyond its |
| + // registry rows. |
| + // |
| + // Fleet record labels D1 (fleetcreate.go): on a fleet with two or more |
| + // active boxes, a process create is labelled or refused below, before |
| + // any write (fleetCreateLabel); the view read here, and its error, are |
| + // what it decides on. fleetActive is the view the rootfs admission asks |
| + // about the chosen box: there, a complete view; on a host-claim console, |
| + // one the activation gate admits, as before D1. Otherwise nil, and the |
| + // rootfs admission asks as it always did. |
| + var ( |
| + fleetActive *fleetView |
| + fleetName string |
| + fleetSeen fleetView |
| + fleetErr error |
| + ) |
| unlockFleet := func() {} |
| defer func() { unlockFleet() }() |
| if fleet, ok := registry.FleetPlacement(placed); ok { |
| unlockFleet = s.lockFleet(fleet) |
| - switch v, err := s.loadFleetView(ctx, fleet); { |
| - case err != nil: |
| - log.Printf("console: api instances create %s/%s: fleet %s view: %v", acct.Sqid, app, fleet, err) |
| - case v.labelActive(): |
| + fleetName = fleet |
| + fleetSeen, fleetErr = s.loadFleetView(ctx, fleet) |
| + switch v := fleetSeen; { |
| + case fleetErr != nil: |
| + log.Printf("console: api instances create %s/%s: fleet %s view: %v", acct.Sqid, app, fleet, fleetErr) |
| + case s.cfg.HostClaim && v.labelActive(), !s.cfg.HostClaim && v.Active: |
| fleetActive = &v |
| } |
| } |
| @@ -2503,19 +2516,34 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| // Born HA (region HA P1a): only here, after the seed doors above have |
| // taken their records, so a seed or an import is never stamped. |
| rec.HA = s.shouldStampHA(rec) |
| - // The fleet box (managed fleets 1b, rule 1): on a fleet the gate admits, |
| - // the ready box holding the fewest records, stamped with the time it was |
| + // The fleet box (managed fleets 1b, rule 1; fleet record labels D1): the |
| + // ready box holding the fewest records, stamped with the time it was |
| // assigned, before the claim, lifetime and plain writers below all write |
| - // this rec. A static record, served by every box from the bucket, and a |
| - // record the platform cannot move (rule 11) are left unlabelled. No box |
| - // to choose leaves it unlabelled too; a rootfs create never gets here |
| - // without one (rootfsChosenBoxRefusal). |
| + // this rec. The box is marked labelled in the registry first (Task 6): |
| + // from then on its detach needs the machine's termination confirmed |
| + // (rule 5, detachHeld). |
| + // |
| + // On a fleet with two or more active boxes a process create is labelled |
| + // or refused here (fleetCreateLabel): every check above reads, and |
| + // nothing has been written yet. The channel head's manifest decides an |
| + // always-on binary's eligibility and a stateless release's box. |
| // |
| - // The box is marked labelled in the registry first (Task 6): from then |
| - // on its detach needs the machine's termination confirmed (rule 5, |
| - // detachHeld). A mark that fails leaves the |
| - // record unlabelled, as on main. |
| - if fleetActive != nil && fleetLabelsRecord(rec) && movable(rec) { |
| + // On a host-claim console D1 is off, as before it: a static record, a |
| + // record the platform cannot move (rule 11), no box to choose and a mark |
| + // that fails all leave the record unlabelled. |
| + if fleetName != "" && s.fleetCreateApplies(fleetSeen, fleetErr, rec) { |
| + var head *release.Manifest |
| + if chHead != nil { |
| + head = chHead.Manifest |
| + } |
| + if ref := s.fleetCreateLabel(ctx, reg, fleetName, fleetSeen, fleetErr, &rec, head); ref != nil { |
| + if ref.Msg == msgFleetCreateUnavailable(fleetName) { |
| + w.Header().Set("Retry-After", fleetCreateRetryAfter) // C39 only |
| + } |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| + } else if s.cfg.HostClaim && fleetActive != nil && fleetLabelsRecord(rec) && movable(rec) { |
| if box := fleetActive.chooseDestination(rec.Runtime == provision.RuntimeRootfsV1, ""); box != "" { |
| if chHead != nil { |
| if ref := s.statelessPublicationRefusal(ctx, acct.Sqid, app, channel, chHead.Manifest, fleetActive, box); ref != nil { |
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go| index 4ed6b385a..8f23835c7 100644 |
| --- a/internal/console/apiinstances_test.go |
| +++ b/internal/console/apiinstances_test.go |
| @@ -3027,3 +3027,300 @@ func TestExistingUpstreamRecordsKeepServing(t *testing.T) { |
| t.Fatalf("member restating the legacy addr = %d %s, want 200", status, out) |
| } |
| } |
| + |
| +// ---- Fleet record labels D1 (#1008 option B, spec §6): no unlabelled |
| +// process create on a fleet with two or more active boxes ---- |
| + |
| +// fleetCreateC39 is C39 for fleet pi. |
| +const fleetCreateC39 = "no box of fleet pi can take a new instance right now. try again in a minute" |
| + |
| +// d1World is fleetBoxWorld with every box beating now at the record label |
| +// floor and the console at it too: a create on it is labelled. |
| +func d1World(t *testing.T, code string, boxes ...string) (*consoleFixture, string, *registry.Registry) { |
| + t.Helper() |
| + fx, token, reg := fleetBoxWorld(t, code, boxes...) |
| + for _, b := range boxes { |
| + piBeat(t, fx, b, true, time.Now(), release.FleetRecordLabelFloor) |
| + } |
| + fx.srv.consoleBuild = release.FleetRecordLabelFloor |
| + return fx, token, reg |
| +} |
| + |
| +// wantFleetCreateRefused creates shop's instance at host and fails unless |
| +// the door answers 503 with Retry-After 30 and C39, and wrote no record |
| +// and marked no box. |
| +func wantFleetCreateRefused(t *testing.T, fx *consoleFixture, reg *registry.Registry, token, host string) { |
| + t.Helper() |
| + wantCreateUnavailable(t, fx, token, host) |
| + boxes, err := reg.ListFleetBoxes("pi") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, b := range boxes { |
| + if b.LabelledAt != 0 { |
| + t.Fatalf("a refused create marked %s labelled", b.Label) |
| + } |
| + } |
| +} |
| + |
| +// wantCreateUnavailable creates shop's instance at host and fails unless |
| +// the door answers 503 with Retry-After 30 and C39, and wrote no record. |
| +func wantCreateUnavailable(t *testing.T, fx *consoleFixture, token, host string) { |
| + t.Helper() |
| + code, hdr, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, `{"host":"`+host+`"}`) |
| + if code != http.StatusServiceUnavailable || hdr.Get("Retry-After") != "30" || errorOf(t, raw) != fleetCreateC39 { |
| + t.Fatalf("create %s = %d (Retry-After %q) %s; want 503, Retry-After 30 and C39", host, code, hdr.Get("Retry-After"), raw) |
| + } |
| + noShopRecord(t, fx, host) |
| +} |
| + |
| +// putsAll is how many writes of any key were made. |
| +func (c *countStore) putsAll() int { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + n := 0 |
| + for _, v := range c.puts { |
| + n += v |
| + } |
| + return n |
| +} |
| + |
| +func TestCreateRefusesWhenNoDestination(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-nodest", "pi-1", "pi-2") |
| + // Both boxes active, at the floor and heard from, neither fresh. |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + piBeat(t, fx, b, true, time.Now().Add(-time.Hour), release.FleetRecordLabelFloor) |
| + } |
| + cs := newCountStore(fx.srv.cfg.Releases) |
| + fx.srv.cfg.Releases = cs |
| + code, hdr, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, `{"host":"a.example.com","environment":"prod"}`) |
| + if code != http.StatusServiceUnavailable || hdr.Get("Retry-After") != "30" || errorOf(t, raw) != fleetCreateC39 { |
| + t.Fatalf("create = %d (Retry-After %q) %s; want 503, Retry-After 30 and C39", code, hdr.Get("Retry-After"), raw) |
| + } |
| + // No record, environment or claim write: nothing was written to the |
| + // bucket at all, and the registry holds no route for the host. |
| + if n := cs.putsAll(); n != 0 { |
| + t.Fatalf("a refused create made %d writes: %v", n, cs.puts) |
| + } |
| + noShopRecord(t, fx, "a.example.com") |
| + if rt, err := reg.Get("a.example.com"); err != nil || rt != nil { |
| + t.Fatalf("route for a refused create: %+v, %v", rt, err) |
| + } |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + if boxRow(t, reg, b).LabelledAt != 0 { |
| + t.Fatalf("%s marked labelled", b) |
| + } |
| + } |
| +} |
| + |
| +func TestCreateRefusesBelowLabelFloor(t *testing.T) { |
| + t.Run("a box below the record floor", func(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-floor-box", "pi-1", "pi-2") |
| + // Above the box label floor, below the record label floor. |
| + piBeat(t, fx, "pi-2", true, time.Now(), release.StatelessReplicasFloor) |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| + }) |
| + t.Run("a stale box below the record floor", func(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-floor-stale", "pi-1", "pi-2") |
| + piBeat(t, fx, "pi-2", true, time.Now().Add(-time.Hour), release.StatelessReplicasFloor) |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| + }) |
| + t.Run("the console below the record floor", func(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-floor-console", "pi-1", "pi-2") |
| + fx.srv.consoleBuild = release.StatelessReplicasFloor |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| + }) |
| + t.Run("a platform box below the box floor", func(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-floor-deploy", "pi-1", "pi-2") |
| + writeFleetBoxOn(t, fx, "", "box-1", "", true, time.Now(), "v0.32.9") |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| + }) |
| + t.Run("a static record is still created", func(t *testing.T) { |
| + fx, token, _ := d1World(t, "code-d1-floor-static", "pi-1", "pi-2") |
| + piBeat(t, fx, "pi-2", true, time.Now(), release.StatelessReplicasFloor) |
| + if code, out := createShop(t, fx, token, `{"host":"s.example.com","kind":"static"}`); code != http.StatusCreated { |
| + t.Fatalf("static create = %d %s; want 201", code, out) |
| + } |
| + rec, _ := storedShop(t, fx, "s.example.com") |
| + wantNoLabel(t, rec) |
| + }) |
| +} |
| + |
| +func TestCreateRefusesWithSidecars(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-sidecars", "pi-1", "pi-2") |
| + if err := provision.CreateSidecarRecord(context.Background(), fx.rel, provision.SidecarRecord{Schema: 1, Name: "bot", |
| + Host: provision.SidecarHost("bot", "shop", fx.sqid), App: "shop", Account: fx.sqid, Region: "fleet/pi", |
| + Channel: "edge", CreatedAt: time.Now().UTC()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| +} |
| + |
| +// A deployment heartbeat that cannot be read leaves the view incomplete |
| +// with no error. |
| +func TestCreateRefusesOnIncompleteView(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-incomplete", "pi-1", "pi-2") |
| + writeFleetBoxOn(t, fx, "", "box-1", "", true, time.Now(), release.FleetRecordLabelFloor) |
| + fx.srv.cfg.Releases = &failGetStore{Store: fx.srv.cfg.Releases, key: "status/boxes/box-1.json"} |
| + if v, err := fx.srv.loadFleetViewRequiredAt(context.Background(), "pi", time.Now(), true); err != nil || v.Complete { |
| + t.Fatalf("view complete %v, %v; want incomplete with no error", v.Complete, err) |
| + } |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| +} |
| + |
| +// The chosen box is detached after every check passed and before the |
| +// mark: MarkFleetBoxLabelled refuses it, so nothing is created. |
| +func TestCreateRefusesWhenMarkFails(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-markfail", "pi-1", "pi-2") |
| + fx.srv.createBeforeMark = func(host string) { |
| + if err := reg.SetFleetBoxStatus("pi", "pi-1", "detached"); err != nil { |
| + t.Error(err) |
| + } |
| + } |
| + wantFleetCreateRefused(t, fx, reg, token, "a.example.com") |
| +} |
| + |
| +func TestCreateLabelsAFreshSurvivor(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-survivor", "pi-1", "pi-2") |
| + piBeat(t, fx, "pi-1", true, time.Now().Add(-time.Hour), release.FleetRecordLabelFloor) // stale, still active |
| + wantLabel(t, createShopAt(t, fx, token, "a.example.com"), "pi-2") |
| + if boxRow(t, reg, "pi-2").LabelledAt == 0 || boxRow(t, reg, "pi-1").LabelledAt != 0 { |
| + t.Fatal("want pi-2, and only pi-2, marked labelled") |
| + } |
| +} |
| + |
| +// A record the platform cannot move, already on the fleet, no longer keeps |
| +// the fleet's new creates unlabelled. |
| +func TestCreateLabelsMovableBesideAnUnmovable(t *testing.T) { |
| + off := false |
| + fx, token, _ := d1World(t, "code-d1-beside", "pi-1", "pi-2") |
| + putFleetRecord(t, fx, "shop", "svc.example.com", func(r *provision.Record) { r.Kind = "instance"; r.Addr = "127.0.0.1:9000" }) |
| + putFleetRecord(t, fx, "shop", "db.example.com", func(r *provision.Record) { r.Hibernate = &off }) |
| + wantLabel(t, createShopAt(t, fx, token, "a.example.com"), "pi-1") |
| + wantLabel(t, createShopAt(t, fx, token, "b.example.com"), "pi-2") |
| +} |
| + |
| +// alwaysOnShop is an always-on binary record of shop at host on fleet pi, |
| +// as fleetCreateLabel is handed it. The create door does not set |
| +// hibernation on a binary record today, so the door's own decision is |
| +// asked directly. |
| +func alwaysOnShop(fx *consoleFixture, host string) provision.Record { |
| + off := false |
| + return provision.Record{Schema: 1, Host: host, Slug: strings.TrimSuffix(host, ".example.com"), App: "shop", |
| + Account: fx.sqid, Region: "fleet/pi", Channel: "edge", CreatedAt: time.Now().UTC(), Hibernate: &off} |
| +} |
| + |
| +func TestCreateRefusesAlwaysOnStatefulOnMultiBox(t *testing.T) { |
| + ctx := context.Background() |
| + for _, c := range []struct { |
| + name, reason string |
| + mut func(*provision.Record) |
| + }{ |
| + {"always on", "it never sleeps and keeps a local database", nil}, |
| + {"unit", "it runs as a system unit", func(r *provision.Record) { r.Unit = "shop.service" }}, |
| + {"ha", "it is a high availability instance", func(r *provision.Record) { r.HA = true }}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + fx, _, reg := d1World(t, "code-d1-stateful", "pi-1", "pi-2") |
| + shipVersion(t, fx, "shop", "v1") // a binary, not stateless |
| + seedChannel(t, fx, "shop", "edge", "v1") |
| + head := fx.srv.readChannelHead(ctx, fx.sqid, "shop", "edge") |
| + if head == nil { |
| + t.Fatal("no channel head") |
| + } |
| + rec := alwaysOnShop(fx, "a.example.com") |
| + if c.mut != nil { |
| + c.mut(&rec) |
| + } |
| + v, verr := fx.srv.loadFleetView(ctx, "pi") |
| + ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head.Manifest) |
| + want := "a.example.com cannot run on a fleet with more than one box: " + c.reason |
| + if ref == nil || ref.Status != http.StatusConflict || ref.Msg != want { |
| + t.Fatalf("refusal %+v; want 409 %q", ref, want) |
| + } |
| + wantNoLabel(t, &rec) |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + if boxRow(t, reg, b).LabelledAt != 0 { |
| + t.Fatalf("%s marked labelled", b) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Spec Q11: an always-on binary whose channel head is stateless is labelled |
| +// at create with that manifest; movable without it says no. |
| +func TestCreateLabelsAlwaysOnStateless(t *testing.T) { |
| + ctx := context.Background() |
| + fx, token, reg := d1World(t, "code-d1-stateless", "pi-1", "pi-2") |
| + shipStatelessFloorRelease(t, fx, "shop", "v1") |
| + seedChannel(t, fx, "shop", "edge", "v1") |
| + head := fx.srv.readChannelHead(ctx, fx.sqid, "shop", "edge") |
| + if head == nil || !head.Manifest.Stateless { |
| + t.Fatalf("channel head %+v; want stateless v1", head) |
| + } |
| + rec := alwaysOnShop(fx, "a.example.com") |
| + if movable(rec) { |
| + t.Fatal("an always-on binary is movable without its manifest") |
| + } |
| + v, verr := fx.srv.loadFleetView(ctx, "pi") |
| + if ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head.Manifest); ref != nil { |
| + t.Fatalf("refusal %+v; want labelled", ref) |
| + } |
| + wantLabel(t, &rec, "pi-1") |
| + if boxRow(t, reg, "pi-1").LabelledAt == 0 { |
| + t.Fatal("pi-1 not marked labelled") |
| + } |
| + // Through the door, a create following the stateless head is labelled |
| + // (a's record above was decided, not written, so pi-1 is still empty). |
| + wantLabel(t, createShopAt(t, fx, token, "b.example.com"), "pi-1") |
| +} |
| + |
| +// Seeded creates keep their own fleet refusal (seedPlacementRefusal), not |
| +// D1's. |
| +func TestCreateSeedOnFleetStillRefused(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-seed", "pi-1", "pi-2") |
| + putFleetRecord(t, fx, "shop", "a.example.com", nil) |
| + code, _, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, `{"host":"b.example.com","from":{"host":"a.example.com"}}`) |
| + if code != http.StatusConflict || errorOf(t, raw) != "shop places its instances in a pool or on a fleet, so it cannot take a seeded instance." { |
| + t.Fatalf("seeded create = %d %s; want 409 with the seed placement refusal", code, raw) |
| + } |
| + noShopRecord(t, fx, "b.example.com") |
| + if boxRow(t, reg, "pi-1").LabelledAt != 0 || boxRow(t, reg, "pi-2").LabelledAt != 0 { |
| + t.Fatal("a seeded create marked a box") |
| + } |
| +} |
| + |
| +// Host-claim consoles keep their create protocol: D1 is off there. On a |
| +// fleet D1 would refuse (a box below the record floor, above the box label |
| +// floor), the host-claim path still runs the activation gate's labelling, |
| +// as before D1: it marks pi-1 before its claim, and never answers C39. |
| +func TestCreateOnHostClaimConsoleUnchanged(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-claim", "pi-1", "pi-2") |
| + piBeat(t, fx, "pi-2", true, time.Now(), release.StatelessReplicasFloor) |
| + fx.srv.cfg.HostClaim = true |
| + code, hdr, raw := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, `{"host":"a.example.com"}`) |
| + if strings.Contains(raw, fleetCreateC39) || strings.Contains(raw, "cannot run on a fleet with more than one box") || hdr.Get("Retry-After") == "30" { |
| + t.Fatalf("host-claim create = %d %s; want no D1 answer", code, raw) |
| + } |
| + if boxRow(t, reg, "pi-1").LabelledAt == 0 { |
| + t.Fatalf("host-claim create = %d %s; want the activation gate's mark on pi-1, as before D1", code, raw) |
| + } |
| +} |
| + |
| +// A one-box fleet is unchanged: below the record floor and with a sidecar, |
| +// a create there is still made, unlabelled. |
| +func TestCreateOnOneBoxFleetUnchanged(t *testing.T) { |
| + fx, token, reg := d1World(t, "code-d1-onebox", "pi-1") |
| + piBeat(t, fx, "pi-1", true, time.Now(), release.FleetBoxLabelFloor) |
| + fx.srv.consoleBuild = release.FleetBoxLabelFloor |
| + if err := provision.CreateSidecarRecord(context.Background(), fx.rel, provision.SidecarRecord{Schema: 1, Name: "bot", |
| + Host: provision.SidecarHost("bot", "shop", fx.sqid), App: "shop", Account: fx.sqid, Region: "fleet/pi", |
| + Channel: "edge", CreatedAt: time.Now().UTC()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + if boxRow(t, reg, "pi-1").LabelledAt != 0 { |
| + t.Fatal("pi-1 marked labelled") |
| + } |
| +} |
diff --git a/internal/console/appcopies_test.go b/internal/console/appcopies_test.go| index d3b2ef893..75bcc1972 100644 |
| --- a/internal/console/appcopies_test.go |
| +++ b/internal/console/appcopies_test.go |
| @@ -19,7 +19,9 @@ import ( |
| func copiesWorld(t *testing.T) (*consoleFixture, string) { |
| t.Helper() |
| fx, token, _ := fleetBoxWorld(t, "copies", "pi-1", "pi-2") |
| - fx.srv.consoleBuild = release.StatelessReplicasFloor |
| + // The record label floor, above the replicas floor: a create on this |
| + // two-box fleet is labelled, not refused (D1). |
| + fx.srv.consoleBuild = release.FleetRecordLabelFloor |
| for i, host := range []string{"a.example.com", "b.example.com"} { |
| channel := []string{"edge", "stable"}[i] |
| putFleetRecord(t, fx, "shop", host, func(r *provision.Record) { |
| @@ -38,7 +40,7 @@ func copiesWorld(t *testing.T) (*consoleFixture, string) { |
| t.Fatal(err) |
| } |
| for _, box := range []string{"pi-1", "pi-2"} { |
| - copiesBeat(t, fx, box, release.StatelessReplicasFloor, time.Now()) |
| + copiesBeat(t, fx, box, release.FleetRecordLabelFloor, time.Now()) |
| } |
| return fx, token |
| } |
diff --git a/internal/console/fleetbox_test.go b/internal/console/fleetbox_test.go| index 3f2cff1cb..ec9486d95 100644 |
| --- a/internal/console/fleetbox_test.go |
| +++ b/internal/console/fleetbox_test.go |
| @@ -21,7 +21,9 @@ import ( |
| // fleetBoxWorld is shop in bab, its instances enabled, placed on fleet pi, |
| // with each of boxes registered active and a fresh, rootfs-ready heartbeat |
| -// at the label floor. The console runs the floor too. |
| +// at the record label floor (release.FleetRecordLabelFloor, above the box |
| +// label floor), so a create on two or more boxes is labelled (D1). The |
| +// console runs that floor too. |
| func fleetBoxWorld(t *testing.T, code string, boxes ...string) (*consoleFixture, string, *registry.Registry) { |
| t.Helper() |
| fx, token := fleetFixture(t, code) |
| @@ -38,9 +40,9 @@ func fleetBoxWorld(t *testing.T, code string, boxes ...string) (*consoleFixture, |
| placeShop(t, fx, token, "pi") |
| for _, b := range boxes { |
| registerFleetBox(t, reg, "pi", b) |
| - piBeat(t, fx, b, true, time.Now(), release.FleetBoxLabelFloor) |
| + piBeat(t, fx, b, true, time.Now(), release.FleetRecordLabelFloor) |
| } |
| - fx.srv.consoleBuild = release.FleetBoxLabelFloor |
| + fx.srv.consoleBuild = release.FleetRecordLabelFloor |
| return fx, token, reg |
| } |
| @@ -134,7 +136,7 @@ func TestCreateLabelsTheLeastLoadedReadyBox(t *testing.T) { |
| func TestCreateSkipsStaleDrainingAndDetachedBoxes(t *testing.T) { |
| fx, token, reg := fleetBoxWorld(t, "code-fb-skip", "pi-1", "pi-2", "pi-3", "pi-4") |
| - piBeat(t, fx, "pi-1", true, time.Now().Add(-time.Hour), release.FleetBoxLabelFloor) // stale |
| + piBeat(t, fx, "pi-1", true, time.Now().Add(-time.Hour), release.FleetRecordLabelFloor) // stale |
| if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil { |
| t.Fatal(err) |
| } |
| @@ -188,7 +190,7 @@ func TestGateNeedsEveryDeploymentBoxCurrent(t *testing.T) { |
| fx, token, reg := fleetBoxWorld(t, "code-fb-deploy", "pi-1", "pi-2") |
| // A platform box below the floor. |
| writeFleetBoxOn(t, fx, "", "box-1", "", true, time.Now(), "v0.32.9") |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| writeFleetBoxOn(t, fx, "", "box-1", "", true, time.Now(), release.FleetBoxLabelFloor) |
| // A box of another fleet below the floor. |
| @@ -198,18 +200,18 @@ func TestGateNeedsEveryDeploymentBoxCurrent(t *testing.T) { |
| } |
| registerFleetBox(t, reg, "away", "aw-1") |
| writeFleetBoxOn(t, fx, "away", "aw-1", "", true, time.Now(), "v0.31.1") |
| - wantNoLabel(t, createShopAt(t, fx, token, "b.example.com")) |
| + wantCreateUnavailable(t, fx, token, "b.example.com") |
| writeFleetBoxOn(t, fx, "away", "aw-1", "", true, time.Now(), release.FleetBoxLabelFloor) |
| // A box of this fleet that names no release. |
| piBeat(t, fx, "pi-2", true, time.Now(), "") |
| - wantNoLabel(t, createShopAt(t, fx, token, "c.example.com")) |
| - piBeat(t, fx, "pi-2", true, time.Now(), release.FleetBoxLabelFloor) |
| + wantCreateUnavailable(t, fx, token, "c.example.com") |
| + piBeat(t, fx, "pi-2", true, time.Now(), release.FleetRecordLabelFloor) |
| // The console itself below the floor. |
| fx.srv.consoleBuild = "dev" |
| - wantNoLabel(t, createShopAt(t, fx, token, "d.example.com")) |
| - fx.srv.consoleBuild = release.FleetBoxLabelFloor |
| + wantCreateUnavailable(t, fx, token, "d.example.com") |
| + fx.srv.consoleBuild = release.FleetRecordLabelFloor |
| // Every box and the console current: labelled. |
| wantLabel(t, createShopAt(t, fx, token, "e.example.com"), "pi-1") |
| @@ -223,7 +225,7 @@ func TestGateClosedForAFleetWithSidecars(t *testing.T) { |
| Channel: "edge", CreatedAt: time.Now().UTC()}); err != nil { |
| t.Fatal(err) |
| } |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| v, err := fx.srv.loadFleetView(context.Background(), "pi") |
| if err != nil { |
| t.Fatal(err) |
| @@ -247,8 +249,13 @@ func TestGateClosedForAnUnmanagedRecord(t *testing.T) { |
| fx, token, _ := fleetBoxWorld(t, "code-fb-unmanaged", "pi-1", "pi-2") |
| wantLabel(t, createShopAt(t, fx, token, "z.example.com"), "pi-1") // open before it |
| putFleetRecord(t, fx, "shop", "svc.example.com", tc.mut) |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| - wantNoLabel(t, createShopAt(t, fx, token, "b.example.com")) |
| + // It closes the host-claim gate; D1 labels new creates beside it. |
| + v, err := fx.srv.loadFleetView(context.Background(), "pi") |
| + if err != nil || !v.Unmovable || v.labelActive() { |
| + t.Fatalf("view %+v, %v; want it unmovable and the host-claim gate closed", v, err) |
| + } |
| + wantLabel(t, createShopAt(t, fx, token, "a.example.com"), "pi-2") |
| + wantLabel(t, createShopAt(t, fx, token, "b.example.com"), "pi-1") |
| }) |
| } |
| @@ -281,7 +288,7 @@ func TestGateClosedOnAnIncompleteListing(t *testing.T) { |
| if err != nil || complete { |
| t.Fatalf("loadDeploymentBoxesComplete = %d boxes, complete %v, %v; want incomplete", len(boxes), complete, err) |
| } |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| fx.srv.cfg.Releases = base |
| }) |
| t.Run("a capped listing", func(t *testing.T) { |
| @@ -292,7 +299,7 @@ func TestGateClosedOnAnIncompleteListing(t *testing.T) { |
| if _, complete, err := fx.srv.loadDeploymentBoxesComplete(context.Background()); err != nil || complete { |
| t.Fatalf("a capped listing: complete %v, %v; want incomplete", complete, err) |
| } |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| }) |
| t.Run("everything read", func(t *testing.T) { |
| fx, _, _ := fleetBoxWorld(t, "code-fb-complete", "pi-1", "pi-2") |
| @@ -317,7 +324,7 @@ func TestSidecarOnlyAppClosesTheGate(t *testing.T) { |
| if err != nil || !complete || sidecars != 1 { |
| t.Fatalf("inventory: %d sidecars, complete %v, %v; want blog's one", sidecars, complete, err) |
| } |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| } |
| // countStore counts store calls by kind and key, and forwards the listing |
| @@ -527,7 +534,7 @@ func TestSidecarCreateRefusedOnAMultiBoxFleet(t *testing.T) { |
| func TestRootfsAdmissionFollowsTheChosenBox(t *testing.T) { |
| fx, token, _ := fleetBoxWorld(t, "code-fb-rootfs", "pi-1", "pi-2") |
| - piBeat(t, fx, "pi-1", false, time.Now(), release.FleetBoxLabelFloor) // not rootfs-ready |
| + piBeat(t, fx, "pi-1", false, time.Now(), release.FleetRecordLabelFloor) // not rootfs-ready |
| shipShop(t, fx, false) |
| rec := createShopAt(t, fx, token, "a.example.com") |
| if rec.Runtime != provision.RuntimeRootfsV1 { |
| @@ -539,7 +546,7 @@ func TestRootfsAdmissionFollowsTheChosenBox(t *testing.T) { |
| wantLabel(t, createShopAt(t, fx, token, "b.example.com"), "pi-2") |
| // No ready destination on an active fleet: today's refusal. |
| - piBeat(t, fx, "pi-2", false, time.Now(), release.FleetBoxLabelFloor) |
| + piBeat(t, fx, "pi-2", false, time.Now(), release.FleetRecordLabelFloor) |
| code, out := createShop(t, fx, token, `{"host":"c.example.com"}`) |
| if code != http.StatusConflict || errorText(out) != fmt.Sprintf(rootfsFleetNotReadyMsg, "pi") { |
| t.Fatalf("create with no ready box = %d %s; want 409 %q", code, out, fmt.Sprintf(rootfsFleetNotReadyMsg, "pi")) |
| @@ -606,7 +613,7 @@ func TestGateNeedsAHeartbeatFromEveryActiveBox(t *testing.T) { |
| fx, token, reg := fleetBoxWorld(t, "code-fb-no-beat", "pi-1", "pi-2") |
| wantLabel(t, createShopAt(t, fx, token, "z.example.com"), "pi-1") // open with both reporting |
| registerFleetBox(t, reg, "pi", "pi-3") // attached, never reported |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| v, err := fx.srv.loadFleetView(context.Background(), "pi") |
| if err != nil { |
| t.Fatal(err) |
| @@ -614,7 +621,7 @@ func TestGateNeedsAHeartbeatFromEveryActiveBox(t *testing.T) { |
| if v.DeploymentCurrent || v.labelActive() { |
| t.Fatalf("view %+v; want the gate closed while pi-3 has no heartbeat", v) |
| } |
| - piBeat(t, fx, "pi-3", true, time.Now(), release.FleetBoxLabelFloor) |
| + piBeat(t, fx, "pi-3", true, time.Now(), release.FleetRecordLabelFloor) |
| wantLabel(t, createShopAt(t, fx, token, "b.example.com"), "pi-2") |
| } |
| @@ -649,9 +656,9 @@ func TestInventoryListFailureClosesTheGate(t *testing.T) { |
| if _, _, complete, err := fx.srv.fleetInventoryFor(context.Background(), "pi"); err != nil || complete { |
| t.Fatalf("inventory with a failed listing: complete %v, %v; want incomplete", complete, err) |
| } |
| - wantNoLabel(t, createShopAt(t, fx, token, "a.example.com")) |
| + wantCreateUnavailable(t, fx, token, "a.example.com") |
| fx.srv.cfg.Releases = failETagStore{Store: base, prefix: provision.SidecarsPrefix(fx.sqid, "shop")} |
| - wantNoLabel(t, createShopAt(t, fx, token, "b.example.com")) |
| + wantCreateUnavailable(t, fx, token, "b.example.com") |
| } |
| // Review fix round 1, finding 3 (controller ruling): a static record is |
diff --git a/internal/console/fleetcreate.go b/internal/console/fleetcreate.go| new file mode 100644 |
| index 000000000..d2a533a4d |
| --- /dev/null |
| +++ b/internal/console/fleetcreate.go |
| @@ -0,0 +1,119 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "log" |
| + "net/http" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Fleet record labels D1 (#1008 option B, spec §6): on a fleet with two or |
| +// more active boxes, a create of a process the platform runs is labelled |
| +// at create, or refused, before any record, environment or claim write. It |
| +// is never created unlabelled: every box of the fleet would serve it. |
| +// Static and Addr/Addrs records (no process the platform runs), seeded and |
| +// imported creates (seedPlacementRefusal), demos (demo_publish.go) and |
| +// host-claim consoles are not asked; the create door decides which |
| +// (fleetCreateApplies). |
| + |
| +// fleetCreateRetryAfter is the Retry-After, in seconds, of a C39 refusal. |
| +const fleetCreateRetryAfter = "30" |
| + |
| +// msgFleetCreateUnavailable is C39: no box of the fleet can take the new |
| +// instance right now (an incomplete view, sidecars, a release below the |
| +// label floor, no destination, or a failed mark). |
| +func msgFleetCreateUnavailable(fleet string) string { |
| + return fmt.Sprintf("no box of fleet %s can take a new instance right now. try again in a minute", fleet) // draft for copy review (C39) |
| +} |
| + |
| +// msgFleetCreateUnplaceable is C42: host is a process the platform cannot |
| +// place on one box or move, on a fleet with more than one box. reason is |
| +// one of C31's (unmovableReasonText). |
| +func msgFleetCreateUnplaceable(host, reason string) string { |
| + return fmt.Sprintf("%s cannot run on a fleet with more than one box: %s", host, reason) // draft for copy review (C42) |
| +} |
| + |
| +// unmovableReasonText is C31's reasons, by unmovableReason's key. C42 |
| +// names one of them. |
| +var unmovableReasonText = map[string]string{ |
| + "addr": "it is served from an address the platform does not manage", // draft for copy review (C31) |
| + "always_on": "it never sleeps and keeps a local database", // draft for copy review (C31) |
| + "unit": "it runs as a system unit", // draft for copy review (C31) |
| + "ha": "it is a high availability instance", // draft for copy review (C31) |
| + "demo": "it is a demo", // draft for copy review (C31) |
| +} |
| + |
| +// fleetCreateApplies reports whether D1 decides a create of rec on a fleet |
| +// whose view the door read under the fleet's lock (v, verr): not on a |
| +// host-claim console, only for a record whose process the platform runs |
| +// (not static, no Addr or Addrs), and only on a fleet with two or more |
| +// active boxes. A view that failed counts unless it proved exactly one |
| +// active box: a fleet whose boxes could not be counted is not assumed to |
| +// have one. |
| +func (s *Server) fleetCreateApplies(v fleetView, verr error, rec provision.Record) bool { |
| + if s.cfg.HostClaim || !fleetLabelsRecord(rec) || rec.Addr != "" || len(rec.Addrs) > 0 { |
| + return false |
| + } |
| + if verr != nil { |
| + return len(v.Boxes) != 1 |
| + } |
| + return len(v.Boxes) >= 2 |
| +} |
| + |
| +// fleetCreateLabel is D1's decision for rec on fleet, whose view (v, verr) |
| +// the caller read under the fleet's lock and still holds. m is the |
| +// channel head's manifest the create follows (nil when there is none yet). |
| +// In order: a record the platform cannot place or move is C42 (409); then |
| +// an incomplete view, sidecars on the fleet, any active box or the console |
| +// below release.FleetRecordLabelFloor (fleetAtRecordFloor, the label |
| +// door's check), no destination, and a failed mark are C39 (503), with the |
| +// stateless publication refusal between the destination and the mark. |
| +// Otherwise the box is marked labelled and rec carries it (FleetBox, |
| +// FleetBoxAt). A new record has no data, so it is not FleetBoxMoved: an |
| +// empty first start is right for it. |
| +func (s *Server) fleetCreateLabel(ctx context.Context, reg consoleRegistry, fleet string, v fleetView, verr error, rec *provision.Record, m *release.Manifest) *doorRefusal { |
| + unavailable := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgFleetCreateUnavailable(fleet)} |
| + tag := fmt.Sprintf("console: api instances create %s/%s/%s: fleet %s", rec.Account, rec.App, rec.Host, fleet) |
| + ok := movable(*rec) |
| + if m != nil { |
| + ok = movable(*rec, m) |
| + } |
| + if !ok { |
| + return &doorRefusal{Status: http.StatusConflict, Msg: msgFleetCreateUnplaceable(rec.Host, unmovableReasonText[unmovableReason(*rec)])} |
| + } |
| + switch { |
| + case verr != nil || !v.Complete: |
| + log.Printf("%s: view incomplete (%v); refused", tag, verr) |
| + return unavailable |
| + case v.HasSidecars: |
| + log.Printf("%s: has sidecars; refused", tag) |
| + return unavailable |
| + case !s.fleetAtRecordFloor(v): |
| + log.Printf("%s: below the record label floor %s; refused", tag, release.FleetRecordLabelFloor) |
| + return unavailable |
| + } |
| + box := v.chooseMoveDestination(rec.Runtime == provision.RuntimeRootfsV1, m != nil && m.Stateless, "") |
| + if box == "" { |
| + log.Printf("%s: no box can take it; refused", tag) |
| + return unavailable |
| + } |
| + if m != nil { |
| + if ref := s.statelessPublicationRefusal(ctx, rec.Account, rec.App, rec.Channel, m, &v, box); ref != nil { |
| + return ref |
| + } |
| + } |
| + if s.createBeforeMark != nil { |
| + s.createBeforeMark(rec.Host) |
| + } |
| + now := time.Now() |
| + if err := reg.MarkFleetBoxLabelled(fleet, box, now.UnixNano()); err != nil { |
| + log.Printf("%s: mark %s labelled: %v; refused", tag, box, err) |
| + return unavailable |
| + } |
| + rec.FleetBox, rec.FleetBoxAt = box, now.UTC().Format(time.RFC3339Nano) |
| + return nil |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index fe795acc9..82cca4228 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1093,6 +1093,10 @@ type Server struct { |
| // and before MarkFleetBoxLabelled (tests only: interleaving seams). |
| labelAfterRead func(host string) |
| labelBeforeMark func(host string) |
| + // createBeforeMark, when set, runs in the create door's fleet label |
| + // (D1, fleetCreateLabel) after every check passed and before |
| + // MarkFleetBoxLabelled (tests only: an interleaving seam). |
| + createBeforeMark func(host string) |
| // consoleBuild, when set, is the release this console reports to the |
| // fleet label gate instead of version.Build (tests only). |
| consoleBuild string |
diff --git a/internal/console/stateless_floor_test.go b/internal/console/stateless_floor_test.go| index 518a6350d..80bbc4875 100644 |
| --- a/internal/console/stateless_floor_test.go |
| +++ b/internal/console/stateless_floor_test.go |
| @@ -259,21 +259,23 @@ func TestStatelessRuntimeFloorBrowserAndPending(t *testing.T) { |
| } |
| } |
| +// On a two-box fleet a box below the record label floor, which is above |
| +// the stateless runtime floor, refuses the create first (D1, C39): only a |
| +// fleet whose every box is at the record floor takes it, labelled. |
| func TestStatelessRuntimeFloorCreateFleet(t *testing.T) { |
| - for _, version := range []string{"v0.33.9", "v0.34.0"} { |
| + for _, version := range []string{"v0.33.9", "v0.34.0", release.FleetRecordLabelFloor} { |
| t.Run(version, func(t *testing.T) { |
| fx, token, _ := fleetBoxWorld(t, "stateless-create", "pi-1", "pi-2") |
| shipStatelessFloorRelease(t, fx, "shop", "v1") |
| seedChannel(t, fx, "shop", "stable", "v1") |
| statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| piBeat(t, fx, "pi-1", true, time.Now(), version) |
| - piBeat(t, fx, "pi-2", true, time.Now(), "v0.34.0") |
| code, out := postJSON(t, instancesURL(fx, "bab", "shop"), map[string]any{"host": "new.example.com", "channel": "stable"}, token) |
| - if version == "v0.33.9" { |
| - if code != http.StatusConflict || out["error"] != statelessFloorWant { |
| + if version != release.FleetRecordLabelFloor { |
| + if code != http.StatusServiceUnavailable || out["error"] != fleetCreateC39 { |
| t.Fatalf("%d %v", code, out) |
| } |
| - } else if code != http.StatusCreated { |
| + } else if code != http.StatusCreated || out["fleet_box"] != "pi-1" { |
| t.Fatalf("%d %v", code, out) |
| } |
| }) |
diff --git a/internal/host/fleettwobox_e2e_test.go b/internal/host/fleettwobox_e2e_test.go| index d8c98ac07..07dd2ff2f 100644 |
| --- a/internal/host/fleettwobox_e2e_test.go |
| +++ b/internal/host/fleettwobox_e2e_test.go |
| @@ -169,12 +169,13 @@ func newFleetWorld(t *testing.T, opts fleetOpts) *fleetWorld { |
| t.Helper() |
| ctx := context.Background() |
| if opts.rel == "" { |
| - opts.rel = release.FleetBoxLabelFloor |
| + opts.rel = release.FleetRecordLabelFloor |
| } |
| t.Setenv("CARLOS_HOST_CLAIM", "") |
| - // The console runs the label floor (gate d). |
| + // The console runs the record label floor, so a create on the two-box |
| + // fleet is labelled (fleet record labels D1). |
| prevBuild := version.Build |
| - version.Build = release.FleetBoxLabelFloor |
| + version.Build = release.FleetRecordLabelFloor |
| t.Cleanup(func() { version.Build = prevBuild }) |
| // The fleet's data bucket over the S3 wire protocol, on loopback. |
| @@ -540,9 +541,10 @@ func (b *fleetBox) setAside(host string) []string { |
| return out |
| } |
| -// heartbeat writes the box's heartbeat composed at at, at the label floor. |
| +// heartbeat writes the box's heartbeat composed at at, at the record label |
| +// floor. |
| func (b *fleetBox) heartbeat(at time.Time) status.Box { |
| - return b.heartbeatRel(at, release.FleetBoxLabelFloor) |
| + return b.heartbeatRel(at, release.FleetRecordLabelFloor) |
| } |
| // heartbeatRel is statusTick's composition with a chosen time and |
| @@ -631,6 +633,23 @@ func (w *fleetWorld) create(host string) provision.Record { |
| return w.record(host) |
| } |
| +// legacyRecord writes shop's record of host straight to the bucket, |
| +// unlabelled, as a console before fleet record labels D1 created it on a |
| +// fleet whose label gate was closed. A create through the door on a |
| +// two-box fleet is now labelled or refused, so such a record predates it. |
| +func (w *fleetWorld) legacyRecord(host string) provision.Record { |
| + w.t.Helper() |
| + rec := provision.Record{Schema: 1, Host: host, Slug: strings.TrimSuffix(host, ".example.com"), App: "shop", |
| + Account: w.acct, Region: "fleet/" + fleetName, Channel: "edge", CreatedAt: time.Now().UTC(), CreatedBy: fleetAddr} |
| + if err := provision.EnsureAssetGen(&rec); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + if err := provision.CreateRecord(context.Background(), w.store, rec); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + return w.record(host) |
| +} |
| + |
| func (w *fleetWorld) record(host string) provision.Record { |
| w.t.Helper() |
| rec, err := provision.GetRecord(context.Background(), w.store, w.acct, "shop", host) |
| @@ -899,16 +918,17 @@ func TestTwoBoxFleetEndToEnd_Real(t *testing.T) { |
| // TestTwoBoxFleetEndToEnd_RealNoAutomaticFirstLabel is step 5: a fleet |
| // whose instances were created and served unlabelled (its boxes below the |
| -// label floor) stays unlabelled once every box is on the floor. The relabel |
| +// label floor, before D1 refused such creates) stays unlabelled once every |
| +// box is on the floor. The relabel |
| // worker never writes a first label (fleet record labels spec §6 D2), even |
| // though each record has a binding its serving box wrote; both boxes keep |
| // minting both records, as on main. |
| func TestTwoBoxFleetEndToEnd_RealNoAutomaticFirstLabel(t *testing.T) { |
| w := newFleetWorld(t, fleetOpts{rel: "v0.32.9"}) |
| pi1, pi2 := w.pi1, w.pi2 |
| - w.create(fleetA) |
| + w.legacyRecord(fleetA) |
| w.wantRecord(fleetA, "", false) |
| - w.create(fleetB) |
| + w.legacyRecord(fleetB) |
| w.wantRecord(fleetB, "", false) |
| // Unlabelled, as on main: both boxes mint both, the lease picks the |