Bootstrap registration: HA client, planner, controller wiring#22
Merged
Conversation
Make a freshly provisioned cluster become an actual HA cluster without human action (specs/operator-mvp/issues/03-bootstrap-registration.md): - internal/memgraph: narrow HA client interface (show instances, add coordinator, register instance, set main) over the Bolt driver; the only place the driver is referenced, and the mock seam for tests. - internal/planner: pure diff of declared topology against observed SHOW INSTANCES output into ordered registration commands, empty when converged. SET INSTANCE TO MAIN is planned only when no MAIN exists. - internal/resources: DeclaredTopology derives per-pod registration identity (coordinator IDs, instance names, advertised FQDNs) from pod ordinals, sharing the FQDN derivation with the coordinator start script so advertised and registered addresses cannot drift. - internal/controller: once both role StatefulSets report all pods ready, find the coordinator leader (follower views redirect to the leader they report; a fresh cluster bootstraps against the first reachable coordinator), plan, and execute. All interaction is read-before-write, so operator restarts mid-bootstrap are harmless. Planner and topology derivation are covered by pure unit tests; the controller registration flow by envtest with an in-memory fake cluster that rejects duplicate registrations and second MAIN promotions.
as51340
added a commit
that referenced
this pull request
Jul 24, 2026
* Bootstrap registration: HA client, planner, controller wiring Make a freshly provisioned cluster become an actual HA cluster without human action (specs/operator-mvp/issues/03-bootstrap-registration.md): - internal/memgraph: narrow HA client interface (show instances, add coordinator, register instance, set main) over the Bolt driver; the only place the driver is referenced, and the mock seam for tests. - internal/planner: pure diff of declared topology against observed SHOW INSTANCES output into ordered registration commands, empty when converged. SET INSTANCE TO MAIN is planned only when no MAIN exists. - internal/resources: DeclaredTopology derives per-pod registration identity (coordinator IDs, instance names, advertised FQDNs) from pod ordinals, sharing the FQDN derivation with the coordinator start script so advertised and registered addresses cannot drift. - internal/controller: once both role StatefulSets report all pods ready, find the coordinator leader (follower views redirect to the leader they report; a fresh cluster bootstraps against the first reachable coordinator), plan, and execute. All interaction is read-before-write, so operator restarts mid-bootstrap are harmless. Planner and topology derivation are covered by pure unit tests; the controller registration flow by envtest with an in-memory fake cluster that rejects duplicate registrations and second MAIN promotions. * feat: 0-based indexing for data instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
specs/operator-mvp/issues/03-bootstrap-registration.md: a freshly provisionedMemgraphClusterbecomes an actual HA cluster with no human action — all coordinators added, all data instances registered, one MAIN promoted.What's in the slice
internal/memgraph) — a narrow interface (ShowInstances,AddCoordinator,RegisterInstance,SetInstanceToMain) plus aConnectorseam, implemented over the neo4j Bolt driver. The driver is referenced nowhere else; queries mirror the HA chart's registration grammar, run as autocommit (coordinator queries cannot run in transactions), andSHOW INSTANCESrows are parsed by column name so added/reordered columns don't break parsing.internal/planner) — pure diff: declared topology + observedSHOW INSTANCESin, ordered commands out (coordinators, then data instances, then the initial MAIN promotion; empty when converged). MAIN is planned only when no MAIN exists — an existing MAIN, on any instance, is never overridden. Undeclared instances are left untouched (no unregistration in v1).internal/resources.DeclaredTopology) — per-pod registration identity from ordinals: coordinator ordinal N is Raft coordinator N+1, data ordinal N registers asinstance_{N+1}(matching the chart's naming), addresses are the pods' stable headless-Service FQDNs. The FQDN derivation is shared with the coordinator start script so advertised and registered addresses cannot drift.Everything is read-before-write and idempotent, so killing the operator mid-bootstrap just resumes with only the missing registrations.
Acceptance criteria
MemgraphClusterconverges to fully registered: all coordinators added, all data instances registered, one MAIN promotedTesting
Connectorseam. The fake rejects duplicate registrations and second MAIN promotions, so any non-read-before-write behavior fails loudly. Covers: no Bolt contact before pods are ready, full fresh bootstrap with a convergence-confirming follow-up, resuming a partial bootstrap, and executing against the leader a follower reports.make lint,make lint-config,make test-unit,make testall green.Live-cluster verification lands with the KinD e2e harness (issue 04).