Skip to content

feat: add EtcdMirror CRD for one-way cross-cluster replication (types and CEL only)#406

Open
xrl wants to merge 2 commits into
etcd-io:mainfrom
xrl:pr/etcdmirror-api-types
Open

feat: add EtcdMirror CRD for one-way cross-cluster replication (types and CEL only)#406
xrl wants to merge 2 commits into
etcd-io:mainfrom
xrl:pr/etcdmirror-api-types

Conversation

@xrl

@xrl xrl commented Jul 7, 2026

Copy link
Copy Markdown

Adds the EtcdMirror CRD: a declarative, continuous one-way key-range replication link from a source etcd cluster to a target etcd cluster (types, generated code, CRD schema, CEL validation and docs only — the replication engine and controller follow in separate PRs; the engine library PR is next in the series).

The API encodes the design's core decisions so they are contract, not implementation detail:

  • Checkpoint lives in the target etcd at a reserved, fenced key — not on a PVC. The agent is a stateless size-1 Deployment; every write to the target is guarded by a mod_revision compare on the checkpoint key, so two agents (or a pre-cutover straggler) can never interleave writes silently.
  • spec.mode: Sync | Drain with a status.cutover block (drainTargetRevision, drainedRevision, verifiedTime, per-side key counts, leasedKeyCount). Cutover is gated on the CutoverReady condition, which requires Drain mode and a reached drain target revision — InvariantsHeld alone never means "safe to cut over".
  • initialSync.mode: RequireEmpty | Overwrite | OverwriteAndPrune replaces a boolean expectEmptyPrefix; OverwriteAndPrune is what makes reversal-by-recreate workable. Two-way replication is a non-goal by data model, not by roadmap: etcd revisions are cluster-local and carry no provenance channel, so bidirectional sync cannot be made loop-safe.
  • One anchored rewrite formula everywhere: key' = target.prefix + destPrefix + TrimPrefix(key, source.prefix).
  • Frozen condition vocabulary (TargetQuotaExhausted, ResyncLoopDetected, CutoverReady, InvariantsHeld, LearnerEndpoint, PrefixConflict, DirectionConflict, …) and Event/Reason constants declared up front as API contract — later PRs add setters, never names. The condition comments carry the paging algebra (what pages immediately, what self-heals) so operators can alert on the API doc alone.
  • Watermark-derived lag/liveness semantics documented on the status fields, including the source-compaction retention formula and the ResyncLoopDetected livelock signature.

Two placement choices worth calling out (and the reasoning, since both had a plausible alternative):

  • startRevision sits under initialSync, not at spec top level: its only valid pairing is with initialSync.mode (it seeds a fidelity-preserving restore via etcdutl snapshot restore --bump-revision --mark-compacted), and the CEL rule that enforces the pairing reads cleaner within one struct.
  • resources sits at spec.resources rather than inside a shared PodTemplate type: PodTemplate is shared with EtcdCluster, and coupling EtcdMirror's much smaller surface to it would inherit fields (persistence, member scheduling) that have no meaning for a stateless agent.

Validation: table-driven CEL envtest suite (etcdmirror_cel_test.go, following the tls_cel_test.go pattern) covering the endpoint oneOf, scheme-vs-TLS rules, conditional TLS secretRef, initialSync/startRevision pairing and prefix/rewrite immutability, against a real envtest apiserver. zz_generated.deepcopy.go, the CRD manifest and docs/api-references/docs.md are regenerated in the same commits; verified with make test and make verify.


PR series — operability fixes, TLS & EtcdMirror

Small single-purpose PRs from live kind-cluster testing of the operator. Each stands alone unless an After is listed. → = this PR.

PR Lands After
Reviewable now — small, any order
🟢 #374 Requeue instead of swallowing the client-cert provisioning error
🟢 #391 Grant events.k8s.io RBAC so operator Events are actually recorded
🟢 #392 Correlate members[]/leaderID from one health snapshot (consistent leader)
🟢 #393 Propagate user-supplied altNames.ipAddresses into certificates
🟢 #394 Accept day-suffix validityDuration (365d, 100d12h) as documented
🟢 #395 Surface early reconcile errors as a Degraded condition (was empty status)
🟢 #379 Configurable reconcile worker pool (--max-concurrent-reconciles)
🟢 #369 kind-based stress/scale e2e harness (1/3/7 members, churn, quorum watcher)
🟢 #398 podTemplate.spec scheduling fields: topologySpread, resources, priorityClass, schedulerName
🟢 #397 First-class Helm chart covering the full config/ surface
🟢 #399 Quorum-aware PodDisruptionBudget per EtcdCluster
🟢 #400 Scale-in removes the right member and transfers leadership first
🟢 #401 Backend quota + auto-compaction spec fields, NOSPACE alarm surfacing
🟢 #402 Reconcile-loop gates replace the blocking StatefulSet-ready wait
🟢 #403 Quorum-gated one-pod-at-a-time version upgrades via OnDelete
TLS stack — in order
🟢 #376 Independent spec.tls.{peer,client} surfaces (breaking alpha API)
#377 TLSReady condition + TLS lifecycle Events #376
#378 Multi-member TLS quorum e2e + PeerCANotShared #377
EtcdMirror — in order
🟢→ #406 EtcdMirror CRD: one-way cross-cluster replication API (types + CEL)
🟢 #407 pkg/mirroragent replication engine (fenced checkpoint-in-target) #406
🟢 #408 Periodic reconciliation pass wired into the engine's steady-state loop #407
🟢 #412 mirror-agent binary: config/TLS-reload/statusz/metrics + kind e2e #408
🟢 #413 EtcdMirror controller: Deployment rendering, statusz-driven conditions, guards, fenced finalizer #412
🟢 #414 CRD/sample/editor+viewer-role kustomize wiring #413
🟢 #415 Controller-side phase/condition gauges, shipped PrometheusRule + dashboard #414
🟢 #416 Full-lifecycle kind e2e: fence overlap, compaction+prune, restart resume, cert rotation, cutover/reversal #415
Parked as drafts pending #363
#382 Per-cluster domain metrics on the operator /metrics endpoint
#384 EtcdCluster admission webhooks (consolidating with #328) #363
#386 EtcdBackup CR → object storage (S3/GCS) #363
#387 Automatic quorum-loss disaster recovery (bootstrap-latch guarded) #363

🟢 ready · ⚪ draft

xrl and others added 2 commits July 1, 2026 12:30
Introduces the EtcdMirror CRD (schema only, no controller/agent) that
will describe a continuous one-way key-range sync from a source etcd
cluster to a target etcd cluster. Adds EtcdMirrorSpec/Status, the
EtcdMirrorEndpoint/TLS/Auth/Sync/Checkpoint/Reconciliation sub-specs,
phase and condition constants (including TargetThrottled and
ReplicationLagExceeded), printer columns, and CEL XValidation rules
for the destPrefix/noDestPrefix mutual exclusion, the
endpointList/serviceRef oneOf, and the insecureSkipVerify/
insecureSkipVerifyAcknowledgeRisk companion-field requirement.

Registers EtcdMirror/EtcdMirrorList in the scheme, regenerates
zz_generated.deepcopy.go and the CRD manifest via controller-gen, and
adds a realistic sample CR. CEL rules are covered by a table-driven
envtest suite in etcdmirror_cel_test.go, following the
tls_cel_test.go pattern, exercised against a real envtest apiserver.

The design's Metrics field (reusing EtcdClusterSpec's MetricsSpec) is
intentionally omitted: MetricsSpec does not exist on this branch yet
and will land with pr/domain-metrics; it will be added in a later PR
once that type is importable.

No controller or agent logic in this PR -- types, generated code, and
CRD schema only.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Xavier Lange <xrlange@gmail.com>
Reshape the EtcdMirror API for the Design-3 engine (checkpoint stored in
the target etcd, stateless agent) per the 48-finding cross-cloud review.

Deletions:
- checkpoint.storageSpec (no PVC; checkpoint lives in the target at a
  reserved fenced key)
- expectEmptyPrefix (superseded by initialSync.mode)
- noDestPrefix (redundant; one anchored rewrite formula
  key' = target.prefix + destPrefix + TrimPrefix(key, source.prefix))
- syncInterval

Additions/renames:
- spec.mode: Sync|Drain; status.cutover{drainTargetRevision,
  drainedRevision, verifiedTime, counts, leasedKeyCount}
- initialSync.mode: RequireEmpty|Overwrite|OverwriteAndPrune,
  startRevision
- sync: requestTimeout, excludePrefixes, pageKeyLimit,
  watchBufferBytes; batching flushes only at source-revision boundaries
- TLS: secretRef pointerized (nil = system trust roots), caBundleRef
- pod resources; configurable reserved checkpoint key
- watermark-derived lag/liveness semantics; frozen condition vocabulary
  (TargetQuotaExhausted, ResyncLoopDetected, CutoverReady,
  InvariantsHeld, LearnerEndpoint, Prefix/DirectionConflict) and Event
  Reason constants as API contract
- status: source/target versions and cluster IDs, leaseBackedKeyCount,
  always-on source/target key counts, initialSyncTotalKeyCount
- CEL: scheme-vs-TLS rules, prefix/rewrite immutability
- docs/etcdmirror.md (fidelity caveats, one-way contract) and
  regenerated API reference

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Xavier Lange <xrlange@gmail.com>
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xrl
Once this PR has been reviewed and has the lgtm label, please assign jberkus for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow

Copy link
Copy Markdown

Hi @xrl. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

This was referenced Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant