Skip to content

refac(gcp): model the data centers of a bootstrap - #625

Open
NJona wants to merge 1 commit into
mainfrom
multi-dc-03-datacenter-model
Open

refac(gcp): model the data centers of a bootstrap#625
NJona wants to merge 1 commit into
mainfrom
multi-dc-03-datacenter-model

Conversation

@NJona

@NJona NJona commented Jul 31, 2026

Copy link
Copy Markdown
Member

Until now a bootstrapped project was implicitly a single data center: its nodes, gateway IPs, config paths and domains all lived directly on CodesphereEnvironment. Multi-DC needs more than one of each, so this introduces the DataCenter type holding everything that must differ per data center, while project-level state (project, VPC, jumpbox, shared postgres node, registry) stays on the environment.

BuildDataCenters derives the layout from the flags: one entry today, and with --multi-dc a second one that shares the first's PostgreSQL server. The primary data center keeps an empty resource-name suffix, so every name, path and domain a single-DC bootstrap produces is unchanged.

Review notes

Nothing consumes the layout yet — the callers are migrated in the following PRs. Two mechanisms keep that migration safe:

  • ensureDataCenters derives the layout on first use and adopts state a caller passed through the legacy top-level environment fields, so every entry point works whether or not Bootstrap ran first — including infra files written before multi-DC support.
  • mirrorPrimaryDataCenter projects the primary data center back onto those fields before the infra file is written, so cleanup and restart-vms keep reading what they always have. The projection is one-way and never read back.

Part of the oms beta bootstrap-gcp --multi-dc stack (10 PRs). Merge in order; each PR is based on its predecessor.

@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from 6c7780b to 98bed26 Compare August 4, 2026 08:12
@NJona
NJona requested a review from joka134 August 4, 2026 11:42
@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from 98bed26 to aacd865 Compare August 5, 2026 15:48

@joka134 joka134 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but two questions

Comment thread internal/bootstrap/gcp/datacenter.go Outdated
Comment thread internal/bootstrap/gcp/datacenter.go Outdated
}
}

// adoptLegacyEnvFields moves state that a caller supplied through the legacy top-level

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to remove the legacy structs afterwards?

@NJona NJona Aug 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and it now happens inside the stack. The mirror was a migration scaffold: PRs 4–7 still read Env.ControlPlaneNodes etc., so it has to stay through those. The new PR 11 (multi-dc-11-drop-legacy-env-mirror) deletes mirrorPrimaryDataCenter and its 8 call sites once nothing reads those fields. The fields themselves stay read-only — ensureDataCenters adopts them so an infra file from a pre-multi-DC OMS still works for cleanup/restart-vms — and got omitempty so new infra files don't write dead keys.

Comment thread internal/bootstrap/gcp/datacenter.go Outdated
}

return []*DataCenter{
newDataCenter(env, primaryDatacenterID, "", newICG),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more consistent to use the suffix for dc1 as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep it backwards compatible when only installing one dc, that's why I kept the names for them

@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from aacd865 to 06e24fc Compare August 7, 2026 16:03
@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from 06e24fc to 62807bf Compare August 10, 2026 14:17
Base automatically changed from multi-dc-02-datacenter-secrets to main August 10, 2026 15:47
@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from 62807bf to 31eacb3 Compare August 10, 2026 15:47
@NJona
NJona requested a review from joka134 August 10, 2026 15:47
Until now a bootstrapped project was implicitly a single data center:
its nodes, gateway IPs, config paths and domains all lived directly on
CodesphereEnvironment. Multi-DC support needs more than one of each, so
this introduces the DataCenter type that holds everything which must
differ per data center, while project-level state (project, VPC,
jumpbox, shared postgres node, registry) stays on the environment.

DataCenter references no GCP state, so it lives in the new
internal/bootstrap/datacenter package where the other bootstrap flows
can use it too. Deriving a layout from the GCP flags stays in the gcp
package, since that is what differs per flow.

BuildDataCenters derives the layout from the flags: one entry today, and
with --multi-dc a second one that shares the first's PostgreSQL server.
The primary data center keeps an empty resource-name suffix, so every
name, path and domain a single-DC bootstrap produces is unchanged.

Nothing consumes the layout yet — the callers are migrated in the
following commits. Two mechanisms keep that migration safe:

- ensureDataCenters derives the layout on first use and adopts state a
  caller passed through the top-level environment fields, so every entry
  point works whether or not Bootstrap ran first, including infra files
  written before multi-DC support.
- mirrorPrimaryDataCenter projects the primary data center back onto
  those fields, so the steps that still read them keep working while they
  are migrated. The last commit of the stack drops it again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Jona Neef <Jona.Neef.97@gmail.com>
@NJona
NJona force-pushed the multi-dc-03-datacenter-model branch from 31eacb3 to 9b9a977 Compare August 12, 2026 09:16
@NJona
NJona requested a review from NautiluX August 12, 2026 11:17
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.

2 participants