Skip to content

feat: support scaling clusters to 0 replicas - #410

Open
GrigoryPervakov wants to merge 1 commit into
mainfrom
feat/cluster-stop
Open

GrigoryPervakov wants to merge 1 commit into
mainfrom
feat/cluster-stop

Conversation

@GrigoryPervakov

@GrigoryPervakov GrigoryPervakov commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Why

In case the cluster is temporarily unneeded, it should be possible to stop it and later start it again.

What

  • Fix the incorrect defaulting value of the Replicas field when it is explicitly set to 0
  • Remove PDBs in that case, to prevent useless noise
  • Set cluster status to Ready if it's intentionally stopped

Note

Medium Risk
Touches core reconcile paths for cluster size, readiness, PDBs, Keeper quorum, and schema sync; mis-ordered stop/start or missing PVCs can affect data and coordination at runtime.

Overview
Adds replicas: 0 as a supported way to stop ClickHouseCluster and KeeperCluster without deleting PVCs. The operator tears down per-replica workloads (StatefulSets, managed PDBs, etc.) while preserving volumes and (for scale-to-zero) Keeper replica registrations for a later resume.

Reconciliation and status: When desired replica count is 0, PDBs are not created (or are removed); terminating pods are tracked via IncludeTerminating on replica resource lists. Ready moves through ScalingDown until the last pod is gone, then ScaledToZero with a normal ClusterReady event—intentionally stopped clusters are treated as ready, not not-ready. Keeper keeps the last quorum ConfigMap while scaled to zero and can scale to/from zero without the usual one-at-a-time quorum rules.

ClickHouse-specific: Pre scale-down schema sync is skipped when scaling to zero; NoKeeperNodes is emitted if ClickHouse still has replicas while the referenced Keeper has no nodes. ApplyDefault no longer overwrites an explicit replicas: 0 (and similar non-struct pointer defaults).

API comments, CRDs, charts, and user docs (scaling, events, PDB behavior) are updated accordingly, with controller and e2e tests for stop/start flows.

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


Workflow [PR]

@clickhouse-operator

clickhouse-operator Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [1ceb3b3]

Summary: ✅


Code Review

Result: ✅ No issues found

What changed: Adds scale-to-zero support for ClickHouse and Keeper clusters while retaining persistent storage and Keeper membership metadata. It also removes managed PDBs at zero replicas, reports the stopped state as Ready with ScaledToZero, preserves explicit zero values during defaulting, and adds documentation and tests for stop/resume workflows.

No issues found in the current implementation.

Investigation: 8/13 rounds, 49 tool calls.

@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.

Stale Bugbot comment from a previous run.

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

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

@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 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3088d34. Configure here.

Comment thread internal/controller/keeper/sync.go Resolved
Comment thread internal/controller/keeper/sync.go Resolved

@security-ai-gate-reviewer security-ai-gate-reviewer 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.

Auto-approved by the AI review gate on 1ceb3b3. Details in the approver's comment on this pull request.

@security-ai-gate-reviewer

Copy link
Copy Markdown

AI review gate — auto-approved

1ceb3b3269ed is approved by security-ai-gate-reviewer[bot], an automated identity, not a human. The approval stands on the required AI review: Cursor Bugbot concluded green on this commit and the AI review gate is SUCCESS (its own comment has the verdict), and the change touches no path that requires a human reviewer. It is bound to this commit: a new push dismisses it and the approver re-evaluates.

History (latest 5 heads, newest first)

  • 1ceb3b3269ed approved — green: Cursor Bugbot

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.

1 participant