Skip to content

feat(network): deterministic CIDR allocator (ADR 0001 step 1, ground#10) - #24

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/network-cidr-allocator
Jun 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/network-cidr-allocator

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Build step 1 of ground's network foundation (ground docs/adr/0001-network-foundation.md). The pure, AWS-free core the rest of the stack builds on.

What

Allocate(supernetCIDR, spokeTiers, azCount) → a Plan: a hub /16 (index 0) plus one /16 per spoke tier in the given order, each split into per-AZ /20 subnets.

The property that matters

Allocation is a stable function of (supernet, tier index) — no time, no randomness, no AWS. Re-running ground deploy must never renumber an existing spoke (CIDR renumbering is destructive). TestAllocate_AppendTierDoesNotRenumber appends a tier and asserts every existing spoke keeps its block.

Details

  • net/netip-based subnet carving (nthSubnet: e.g. 10.0.0.0/8 index 3 → 10.3.0.0/16).
  • Validates: supernet must be IPv4 /16 or larger and hold 1 hub + len(tiers) /16s; azCount 1–16 (/20s per /16); no empty/duplicate tier names.
  • Unit-tested like the SCPs — pure, no live calls: exact carve (hub 10.0.0.0/16, spokes 10.1–10.4/16, hub subnets 10.0.0.0/20,10.0.16.0/20,10.0.32.0/20), determinism, no-renumber, a tight /14 supernet, hub-only, and all seven error paths.

Next steps per ADR 0001: single-VPC template → hub-and-spoke+TGW → compute-to-data egress (ground#10 routing). Refs: #11, #10.

Build step 1 of ground's network foundation (docs/adr/0001-network-foundation.md):
a pure function from the supernet + ordered tier list to a hub /16 (index 0) plus
one /16 per spoke tier, each split into per-AZ /20 subnets.

- Allocation is a stable function of (supernet, tier index) — no time, no
  randomness, no AWS. Re-running ground deploy never renumbers an existing spoke
  (renumbering is destructive); guarded by TestAllocate_AppendTierDoesNotRenumber.
- net/netip-based subnet carving (nthSubnet); /16 VPCs, /20 per-AZ subnets (16
  AZs max per /16).
- validates supernet size (holds 1 hub + N spokes), AZ count (1..16), rejects
  empty/duplicate tier names, malformed/oversized supernet.
- unit-tested like the SCPs (pure, no live calls): exact carve, determinism,
  no-renumber, small /14 supernet, hub-only, all error paths.

Refs: #11, #10
@scttfrdmn
scttfrdmn merged commit 182da49 into main Jun 12, 2026
2 checks passed
@scttfrdmn
scttfrdmn deleted the feat/network-cidr-allocator branch June 12, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant