region HA P1a Task 13: stamp instance records only
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+42
−7
internal/console/apiinstances.go+2 −5internal/console/domainattach.go+2 −2internal/console/ha_born_test.go+30 −0internal/console/seedmove.go+8 −0
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index a62e90e91..46cbff989 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -1776,11 +1776,8 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| return |
| } |
| // 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. A |
| - // replica is a copy for another region, not a home, so it is not either. |
| - if rec.Role == "" { |
| - rec.HA = s.haRegion(rec.Region) |
| - } |
| + // taken their records, so a seed or an import is never stamped. |
| + rec.HA = s.shouldStampHA(rec) |
| // A fresh budget for the write and its rollback: validation and the |
| // rail's listings may have spent most of the original one. |
| cancel() |
diff --git a/internal/console/domainattach.go b/internal/console/domainattach.go| index 92c213ad7..9daca8d73 100644 |
| --- a/internal/console/domainattach.go |
| +++ b/internal/console/domainattach.go |
| @@ -250,7 +250,7 @@ func (s *Server) attachDomainAs(ctx context.Context, acct *Account, app, host, k |
| Channel: channel, Kind: "static", |
| CreatedAt: time.Now().UTC(), CreatedBy: principal, |
| } |
| - rec.HA = s.haRegion(rec.Region) // born HA (region HA P1a) |
| + rec.HA = s.shouldStampHA(rec) // never true for a static record |
| // The primary record draws its asset generation at create, like every |
| // instance record (edge asset cache design ยง6). |
| if err := provision.EnsureAssetGen(&rec); err != nil { |
| @@ -676,7 +676,7 @@ func (s *Server) attachFirstRouteLocked(ctx context.Context, acct *Account, app, |
| Channel: channel, Kind: "static", |
| CreatedAt: time.Now().UTC(), CreatedBy: principal, |
| } |
| - rec.HA = s.haRegion(rec.Region) // born HA (region HA P1a) |
| + rec.HA = s.shouldStampHA(rec) // never true for a static record |
| ambiguous := &doorRefusal{http.StatusInternalServerError, |
| "could not declare the route for this domain โ nothing was attached, try again"} |
| _, err = s.createRecordWithLifetimeLocked(ctx, rec, lifetime) |
diff --git a/internal/console/ha_born_test.go b/internal/console/ha_born_test.go| index fcb858ad1..3516cb2bb 100644 |
| --- a/internal/console/ha_born_test.go |
| +++ b/internal/console/ha_born_test.go |
| @@ -199,3 +199,33 @@ func TestImportUploadAndStoppedRefusedInHARegion(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// Only instance-kind records are born HA: a static record in an HA region |
| +// is not stamped, so its own move is not refused with C1. |
| +func TestStaticRecordIsNotStampedAndDoesNotBlockAMove(t *testing.T) { |
| + w := newOfflineWorld(t, oneEach...) |
| + w.fx.srv.cfg.HARegions = []string{"ie"} |
| + const staticHost = "site.shop.example.com" |
| + u := instancesURL(w.fx, "bab", "shop") |
| + if c, _, out := rawReq(t, http.MethodPost, u, w.token, `{"host":"`+staticHost+`","kind":"static","region":"ie"}`); c != http.StatusCreated { |
| + t.Fatalf("static create = %d %s", c, out) |
| + } |
| + rec, err := provision.GetRecord(context.Background(), w.fx.rel, "bab", "shop", staticHost) |
| + if err != nil || rec.HA || rec.KindOrDefault() != "static" { |
| + t.Fatalf("static record = %+v, %v; want unstamped", rec, err) |
| + } |
| + for _, p := range []string{"/move/offline", "/move"} { |
| + c, _, out := rawReq(t, http.MethodPost, u+"/"+staticHost+p, w.token, `{"region":"uk"}`) |
| + if strings.Contains(out, "high availability") { |
| + t.Fatalf("%s refused a static record as HA: %d %s", p, c, out) |
| + } |
| + } |
| + // And an instance record made in the same console is stamped, so the |
| + // check above is the kind's doing. |
| + if c, _, out := rawReq(t, http.MethodPost, u, w.token, `{"host":"inst.shop.example.com","region":"ie"}`); c != http.StatusCreated { |
| + t.Fatalf("instance create = %d %s", c, out) |
| + } |
| + if inst, err := provision.GetRecord(context.Background(), w.fx.rel, "bab", "shop", "inst.shop.example.com"); err != nil || !inst.HA { |
| + t.Fatalf("instance record = %+v, %v; want stamped", inst, err) |
| + } |
| +} |
diff --git a/internal/console/seedmove.go b/internal/console/seedmove.go| index a666fbb07..827f8a71b 100644 |
| --- a/internal/console/seedmove.go |
| +++ b/internal/console/seedmove.go |
| @@ -36,6 +36,14 @@ func (s *Server) haRegion(region string) bool { |
| return region != "" && slices.Contains(s.cfg.HARegions, region) |
| } |
| +// shouldStampHA is the one place a create decides a record is born HA: an |
| +// instance-kind record with no role, in an HA region. Static records and |
| +// replicas are never stamped: boxes ignore non-instance kinds, and a |
| +// stamped static would make its app's moves and places refuse. |
| +func (s *Server) shouldStampHA(rec provision.Record) bool { |
| + return rec.KindOrDefault() == "instance" && rec.Role == "" && s.haRegion(rec.Region) |
| +} |
| + |
| // haMoveSentence is RHA-P1a-C1 (approved): name is the host's region. |
| func haMoveSentence(name string) string { |
| return fmt.Sprintf("%s has high availability turned on. offline moves into or out of it are not available yet", name) |