Skip to content

feat: support multi-cluster Keeper and ClickHouse deployments - #412

Open
melancholictheory wants to merge 4 commits into
ClickHouse:mainfrom
melancholictheory:feat/multi-cluster
Open

melancholictheory wants to merge 4 commits into
ClickHouse:mainfrom
melancholictheory:feat/multi-cluster

Conversation

@melancholictheory

@melancholictheory melancholictheory commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

Running a single ClickHouse or Keeper cluster across multiple Kubernetes clusters or regions was not possible because each operator assumed local shard/replica IDs starting at 0, odd local Keeper replica counts, and sole ownership of all replicas in raft_configuration, remote_servers, and Keeper metadata cleanup.

What

  • KeeperCluster (v1alpha1): added spec.replicaIDOffset (immutable) and spec.externalPeers; relaxed local replicas to allow even counts when externalPeers is set; updated Raft quorum generation, loadQuorumReplicas, readiness/scaling checks (supporting remote Raft leaders), and ClickHouseCluster Keeper peer discovery via keeperClusterRef.
  • ClickHouseCluster (v1alpha1): added spec.shardIDOffset, spec.replicaIDOffset (both immutable), and spec.externalReplicas; merged local and external replicas into remote_servers.default; updated schema sync, stale replica metadata cleanup (preserving external replicas), and shard-peer recovery fallback.
  • Added CEL/webhook validations, unit/integration tests, regenerated CRDs/Helm charts/API reference, and documented multi-cluster setup.

Related Issues

Fixes #144


Note

High Risk
Changes core CRD shape, Raft quorum, remote_servers, and Keeper metadata cleanup—misconfiguration or bugs could break cross-cluster replication or quorum.

Overview
Adds multi-cluster / multi-region support so one logical ClickHouse cluster and Keeper Raft ensemble can span several Kubernetes clusters, each running its own operator instance.

ClickHouseCluster gains immutable shardIDOffset and replicaIDOffset, plus externalReplicas (host, port, optional TLS). Local shard/replica iteration and obsolescence checks use those offsets. Generated config merges local and external replicas into remote_servers.default; Keeper client config can include KeeperCluster externalPeers. Schema sync can discover databases via clusterAllReplicas; stale-replica cleanup skips external replicas and uses offset-aware bounds, with optional TLS to external peers for shard-peer operations.

KeeperCluster gains immutable replicaIDOffset and externalPeers (Raft + optional clientPort). Local replica IDs and quorum raft_configuration include external members; readiness and horizontal scaling use total ensemble size (local + external), including when the Raft leader is remote. The odd-local-replica rule is relaxed when externalPeers is set, within a 15-node ensemble cap.

CRD CEL rules, validating webhooks, Helm values, API reference, and a configuration guide section document and enforce non-colliding IDs and immutability.

Reviewed by Cursor Bugbot for commit deac6d8. Bugbot is set up for automated code reviews on this repo. Configure here.


Workflow [PR]

Add replicaIDOffset and externalPeers to KeeperCluster, and shardIDOffset,
replicaIDOffset, and externalReplicas to ClickHouseCluster so a single
logical Keeper ensemble and ClickHouse cluster can span multiple Kubernetes
clusters or regions.

Fixes ClickHouse#144

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 3048c43. Configure here.

Comment thread internal/controller/keeper/sync.go Resolved
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

@GrigoryPervakov GrigoryPervakov self-assigned this Dec 1, 2026
@GrigoryPervakov

Copy link
Copy Markdown
Member

Thank you for your contribution. It's a cool feature. I would try to review it, but it may take longer.
Maybe it would make sense to postpone schema changes until we switch to v1alpha2

@clickhouse-operator

clickhouse-operator Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [eca7e32]

Summary: ❌

job_name test_name status info comment
Vale Linter FAIL
Compat E2E (supported-clickhouse-compatibility) FAIL
deploy suite :: [It] Manifests deployment should successfully work with version: 26.11.5.8 [manifest] FAIL
Compat E2E (operator-upgrade) FAIL
deploy suite :: [It] Operator upgrade should reconcile cluster after upgrade without data loss [upgrade] FAIL

Code Review

Result: ❌ Blocking issues

What changed: Adds multi-cluster Keeper and ClickHouse support through local ID offsets, externally managed Keeper peers and ClickHouse replicas, merged runtime configuration, cross-cluster schema discovery, and metadata-preserving cleanup. It also updates validation, generated CRDs/charts, documentation, and tests for these deployment modes.

Blocking

  • Offset immutability is enforced only by fail-open admission webhooks. If the webhook is unavailable, changing an offset can make every existing StatefulSet appear obsolete and trigger destructive cleanup. The CRD schema must enforce immutability with CEL.

Other issue

  • The new direct TLS connection to an external ClickHouse peer disables certificate verification, contrary to the API contract and documentation.

Investigation: 8/13 rounds, 49 tool calls.

Comment thread api/v1alpha1/clickhousecluster_types.go Resolved
Comment thread api/v1alpha1/keepercluster_types.go Resolved

This branch has not been deployed

No deployments
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.

Multi K8S cluster/region support

3 participants