Files
orca/cloud/dev/scripts/relay-live-cell-image-overlay.mjs
Jinwoo Hong bf3f95245c feat(relay): declare Asia cell c30 at the c27 shape (#22375)
* feat(relay): declare Asia cell c30 at the c27 shape

Adds production-gce-c30 in asia-east2-a at the reviewed Asia shape (6,000
request units, 3,000/60 connection limits, 16-connection pool, disabled) and
the rehome trust the other Asia cells carry.

Every Asia enumeration now knows C30. The topology, admission, and director
tools treat it as its own reviewed wave so its plan and registration never
touch the live launch cells. C30 promotion requires C27 general and fresh
staging evidence. The topology and director validators now pin the committed
production pool of 16 instead of the stale 10, which had made the topology
workflow reject the committed launch cells.

* fix(relay): plan C30 at live images and prove it with its own canary

The shared URL map pulls every cell into the C30 topology plan, so the workflow
now plans each non-target cell at the image its live template serves, and the
validator names any change to a cell outside the wave. C30 promotion runs the
same five-minute production canary and automatic rollback C27 used, with the
load report proving the canary control was placed on C30, instead of relying
on staging evidence. C30 leaves the shadow gate's fleet pool list until it
serves, rollback rejects mixed partial sets, and a budget test pins the
mixed-Asia-pool refusal.

* fix(relay): pin C30 to the production director's live image digest

C30 promotion requires the director and C30 to report one digest, so C30
takes the director's sha256:4158d8a2 (read 2026-09-22). C27-C29 keep their
committed lines; every Asia check compares only the cells named in a run.

* fix(relay): read the committed cell map from a plan, not console

terraform console evaluates every output against state, and the Relay
deployments output indexes each cell's MIG, so it fails with Invalid index
while C30 is declared but not created. Read the map from a no-refresh,
unlocked plan over the same targets instead, and refuse empty overlay input.

* fix(relay): keep console readers working and C30 migration-only until promotion

relay_gce_cell_deployments indexed each cell's MIG, backend, and template,
so once C30 is declared but not applied every production terraform console
reader printed a warning to stdout and broke its jq parse. Wrap those six
lookups in try(..., null).

Same-cap listed C30 as general, so a rollback dispatch on a migration-only
C30 would restore it with activate and skip its canary. List it with the
migration-only cells until the promotion follow-up moves it.
2026-09-22 23:41:09 -04:00

85 lines
3.7 KiB
JavaScript

import { readFileSync, writeFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
// Committed images lag what same-cap rolls serve, and a URL map target pulls every cell's
// template into the plan, so a non-target cell must be planned at the image it serves.
const IMAGE_PATTERN = /^[a-z0-9.-]+\/[a-z0-9-]+\/[a-z0-9-]+\/relay@sha256:[a-f0-9]{64}$/
function liveRelayImage(script, committedImage, cellId) {
const repository = committedImage.split('@')[0]
const pulled = [...script.matchAll(/^docker pull '([^']+)'$/gm)]
.map((match) => match[1])
.filter((image) => image.split('@')[0] === repository)
const digest = /^\s*printf 'ORCA_RELAY_IMAGE_DIGEST=%s\\n' '(sha256:[a-f0-9]{64})'$/m.exec(script)?.[1]
if (pulled.length !== 1 || !IMAGE_PATTERN.test(pulled[0]) || pulled[0].split('@')[1] !== digest) {
throw new Error(`${cellId} live template has no single pinned Relay image`)
}
return pulled[0]
}
export function overlayRelayLiveCellImages({ committedCells, liveTemplates, targetCellIds }) {
if (!committedCells || Array.isArray(committedCells) || typeof committedCells !== 'object') {
throw new Error('committed Relay cells must be an object')
}
if (!Array.isArray(liveTemplates)) throw new Error('live templates must be an array')
const targets = new Set(targetCellIds)
for (const cellId of targets) {
if (!committedCells[cellId]) throw new Error(`${cellId} is not a committed Relay cell`)
}
const scripts = new Map()
for (const template of liveTemplates) {
if (typeof template?.index !== 'string' || typeof template.metadata_startup_script !== 'string') {
throw new Error('live template entry is malformed')
}
if (scripts.has(template.index)) throw new Error(`${template.index} has more than one live template`)
scripts.set(template.index, template.metadata_startup_script)
}
const cells = {}
for (const [cellId, cell] of Object.entries(committedCells)) {
if (targets.has(cellId)) {
cells[cellId] = cell
continue
}
const script = scripts.get(cellId)
// A declared cell with no live template would be created here, outside the reviewed wave.
if (script === undefined) throw new Error(`${cellId} is not a target and has no live template`)
cells[cellId] = { ...cell, image: liveRelayImage(script, cell.image, cellId) }
}
return { relay_gce_cells: cells }
}
function argumentsFrom(argv) {
const values = {}
for (let index = 0; index < argv.length; index += 2) {
const key = argv[index]
const value = argv[index + 1]
if (!key?.startsWith('--') || value === undefined) throw new Error('invalid arguments')
values[key.slice(2)] = value
}
for (const key of ['cells-json', 'live-templates-json', 'cell-ids', 'output']) {
if (!values[key]) throw new Error(`missing --${key}`)
}
return values
}
function readJsonFile(path, label) {
const text = readFileSync(path, 'utf8')
if (!text.trim()) throw new Error(`${label} is empty`)
return JSON.parse(text)
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const values = argumentsFrom(process.argv.slice(2))
const committedCells = readJsonFile(values['cells-json'], 'committed Relay cells')
const overlay = overlayRelayLiveCellImages({
committedCells,
liveTemplates: readJsonFile(values['live-templates-json'], 'live Relay templates'),
targetCellIds: values['cell-ids'].split(',').map((value) => value.trim()).filter(Boolean)
})
writeFileSync(values.output, `${JSON.stringify(overlay)}\n`)
const drifted = Object.keys(committedCells).filter(
(cellId) => overlay.relay_gce_cells[cellId].image !== committedCells[cellId].image
)
console.log(JSON.stringify({ cells: Object.keys(committedCells).length, drifted }))
}