Skip to content

Conversation

klinch0
Copy link
Contributor

@klinch0 klinch0 commented Aug 7, 2025

What this PR does

Release note

- update ch operator
- add chk

Summary by CodeRabbit

  • New Features

    • Added configurable parameter to set the number of ClickHouse Keeper replicas, with a default of 3.
    • Replica count for ClickHouse Keeper and related resources can now be adjusted via configuration.
  • Documentation

    • Updated documentation to describe the new clickhouseKeeper.replicas parameter and its usage.
    • Removed an outdated command from setup instructions.

Signed-off-by: kklinch0 <kklinch0@gmail.com>
@klinch0 klinch0 requested review from kvaps and lllamnyp as code owners August 7, 2025 11:08
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

This change introduces a configurable replica count for ClickHouse Keeper in the Helm chart. The replica parameter is added to documentation, schema, and values files. Corresponding Helm templates are updated to use this parameter for resource definitions, replacing hardcoded replica values with dynamic configuration.

Changes

Cohort / File(s) Change Summary
ClickHouse Keeper Replica Config Parameter
packages/apps/clickhouse/README.md, packages/apps/clickhouse/values.schema.json, packages/apps/clickhouse/values.yaml
Added clickhouseKeeper.replicas parameter (default 3) to documentation, schema, and values files for configuration.
Helm Templates: Dynamic Replica Usage
packages/apps/clickhouse/templates/chkeeper.yaml, packages/apps/clickhouse/templates/workloadmonitor.yaml
Replaced hardcoded replica values with the configurable .Values.clickhouseKeeper.replicas parameter in resource specs.
Zookeeper Nodes Dynamic List
packages/apps/clickhouse/templates/clickhouse.yaml
Changed static zookeeper node host to a dynamically generated list based on the replica count parameter.
Conditional Role ResourceNames
packages/apps/clickhouse/templates/dashboard-resourcemap.yaml
Conditionally added a keeper-suffixed resourceName to Role rules if keeper is enabled.
Dashboard Redis Command Removal
packages/apps/README.md
Removed a kubectl delete pod dashboard-redis-master-0 -n cozy-dashboard command from instructions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Helm Chart
    participant Kubernetes API

    User->>Helm Chart: Set clickhouseKeeper.replicas in values.yaml
    Helm Chart->>Kubernetes API: Deploy resources using .Values.clickhouseKeeper.replicas
    Kubernetes API->>Kubernetes API: Create Keeper, WorkloadMonitor, and Zookeeper nodes with specified replica count
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Suggested labels

enhancement, size:M, lgtm

Suggested reviewers

  • kvaps

Poem

In the stack where ClickHouse keeps its lair,
Now replicas are set with care.
No more hardcoded threes in sight,
Helm charts flex to user delight!
Keeper counts now dance and play,
Configurable, the Cozy way.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39adc16 and cffff6c.

📒 Files selected for processing (1)
  • packages/apps/clickhouse/README.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/apps/clickhouse/README.md
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch clickhouse-add-ch-keeper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @klinch0, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces support for ClickHouse Keeper within the ClickHouse Helm chart, allowing ClickHouse clusters to leverage ClickHouse Keeper for coordination. It also updates the underlying altinity-clickhouse-operator to a newer version, bringing in new features and CRD schema changes necessary for this integration.

Highlights

  • ClickHouse Keeper Deployment: I've added a new Helm template (chkeeper.yaml) to deploy ClickHouse Keeper instances as a standalone component, which can then be used by ClickHouse clusters for distributed coordination.
  • ClickHouse Integration: The main ClickHouse Helm chart (clickhouse.yaml) has been updated to allow ClickHouse clusters to connect to and utilize the deployed ClickHouse Keeper instances as their Zookeeper ensemble, enabling robust distributed operations.
  • Operator and Chart Upgrades: I've upgraded the altinity-clickhouse-operator Helm chart to version 0.25.2 and the clickhouse chart to 0.12.0. This operator upgrade includes new Custom Resource Definitions (CRDs) for ClickHouse Keeper installations and various schema enhancements for existing ClickHouse resources.
  • Configuration and Monitoring: New configuration parameters have been introduced in values.yaml and values.schema.json for managing ClickHouse Keeper deployments, including enabling/disabling it, setting resource limits, and defining replica counts. Additionally, the Grafana dashboard for ClickHouse Keeper has been updated to reflect new metric names and improve monitoring capabilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Signed-off-by: klinch0 <68821526+klinch0@users.noreply.github.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces ClickHouse Keeper support and upgrades the Altinity ClickHouse Operator. The changes are extensive, covering CRD updates, Helm chart modifications, and new Kubernetes resources for the keeper. My review focuses on the new keeper implementation. I've found a few issues related to resource configuration, port exposure, and schema definitions for the new ClickHouse Keeper component that need to be addressed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/apps/clickhouse/README.md (1)

56-64: Regenerate README to satisfy pre-commit hook

CI failed (readme-generator-for-helm) because the manual edit deviates from the auto-generated format.
Run make generate (or the repo-specific generator) and commit the resulting README to unblock the pipeline.

🧹 Nitpick comments (3)
packages/apps/clickhouse/values.yaml (1)

63-69: Clarify replica parameters to avoid ambiguity

With both a top-level .Values.replicas (ClickHouse) and .Values.clickhouseKeeper.replicas now present, it’s easy for chart consumers to mix them up.
Consider adding an inline comment that explicitly distinguishes database replicas from keeper replicas, e.g.

## @param clickhouseKeeper.replicas Number of ClickHouse **Keeper** replicas (quorum nodes), _not_ the main DB replicas

This tiny clarification will save future users a round-trip to the docs.

packages/apps/clickhouse/templates/chkeeper.yaml (1)

18-18: Render replicasCount explicitly as an integer to avoid YAML type drift

.Values.clickhouseKeeper.replicas may come through the values file as a quoted
string (e.g. "3"). Helm will render that verbatim, which makes the CR field
a string instead of an int and can cause Altinity-keeper admission to reject
the object.

-          replicasCount: {{ .Values.clickhouseKeeper.replicas }}
+          replicasCount: {{ int .Values.clickhouseKeeper.replicas }}
packages/apps/clickhouse/templates/clickhouse.yaml (1)

97-104: Reuse the already-derived $clusterDomain to keep FQDNs consistent

Earlier in the template you compute
$clusterDomain := (index $cozyConfig.data "cluster-domain") | default "cozy.local".
Here you silently switch to .Values.clusterDomain, which can diverge from the
lookup and break keeper discovery inside ClickHouse.

-        {{- $clusterDomain := .Values.clusterDomain }}
+        {{- /* Re-use the global value computed at the top of the file */ -}}
+        {{- $clusterDomain := $clusterDomain }}

Alternatively, drop the local assignment completely and reference the global
$clusterDomain directly in the host string.

Please verify that only one source of truth is used for the cluster-domain
throughout the chart.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6bceff and 39adc16.

📒 Files selected for processing (8)
  • packages/apps/README.md (0 hunks)
  • packages/apps/clickhouse/README.md (1 hunks)
  • packages/apps/clickhouse/templates/chkeeper.yaml (1 hunks)
  • packages/apps/clickhouse/templates/clickhouse.yaml (1 hunks)
  • packages/apps/clickhouse/templates/dashboard-resourcemap.yaml (1 hunks)
  • packages/apps/clickhouse/templates/workloadmonitor.yaml (1 hunks)
  • packages/apps/clickhouse/values.schema.json (1 hunks)
  • packages/apps/clickhouse/values.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/apps/README.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: kubernetes rbac rules with resourcenames work correctly for list/watch verbs. when resourcenames is ...
Learnt from: lllamnyp
PR: cozystack/cozystack#1161
File: packages/apps/virtual-machine/templates/dashboard-resourcemap.yaml:6-12
Timestamp: 2025-07-10T12:14:27.197Z
Learning: Kubernetes RBAC rules with resourceNames work correctly for list/watch verbs. When resourceNames is specified in an RBAC rule, it properly restricts access to only those named resources, even for list and watch operations. Examples: `kubectl get resource resourcename -w` watches for changes on a single resource, and `kubectl get resource --field-selector .metadata.name=resourcename` lists a specific resource. The Kubernetes API server correctly distinguishes such requests from their less specific counterparts.

Applied to files:

  • packages/apps/clickhouse/templates/dashboard-resourcemap.yaml
🪛 GitHub Actions: Pre-Commit Checks
packages/apps/clickhouse/README.md

[error] 62-62: Make generate step failed due to modifications in README.md by readme-generator-for-helm hook. Files were modified by this hook, causing the pipeline to fail with exit code 123.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
packages/apps/clickhouse/templates/dashboard-resourcemap.yaml (1)

25-28: YAML indentation ok – but beware empty list when keeper disabled

When clickhouseKeeper.enabled is false, the conditional leaves an empty line that is still a valid YAML element, so the list remains well-formed (- {{ .Release.Name }} only). No action required – just signalling I checked the indentation & templating.

Comment on lines +21 to 23
replicas: {{ .Values.clickhouseKeeper.replicas }}
minReplicas: 1
kind: clickhouse
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Lowering minReplicas to 1 may jeopardise keeper quorum

Keeper forms a Raft quorum (majority of replicas).
If HPA/WorkloadMonitor scales the StatefulSet below 3, the cluster can lose consensus and stall writes.

Confirm that WorkloadMonitor will never down-scale below a safe majority or set minReplicas: 3 instead.

-  minReplicas: 1
+  minReplicas: 3   # keep quorum

🏁 Script executed:

#!/bin/bash
set -e

echo "1) Locate the chart's values.yaml for clickhouseKeeper defaults"
fd values.yaml packages/apps/clickhouse

echo
echo "2) Extract clickhouseKeeper block from values.yaml"
rg -n "clickhouseKeeper" -n packages/apps/clickhouse/values.yaml -A 5 -B 2

echo
echo "3) Locate the WorkloadMonitor template"
fd workloadmonitor.yaml packages/apps/clickhouse/templates

echo
echo "4) Display the first 200 lines of workloadmonitor.yaml"
sed -n '1,200p' packages/apps/clickhouse/templates/workloadmonitor.yaml

Length of output: 2102


Ensure Keeper HPA doesn’t break Raft quorum
Keeper requires a majority of its replicas to stay online. With clickhouseKeeper.replicas = 3, setting minReplicas: 1 lets the HPA scale below quorum and stall writes. Update the keeper monitor in
packages/apps/clickhouse/templates/workloadmonitor.yaml:

--- a/packages/apps/clickhouse/templates/workloadmonitor.yaml
@@ spec:
-  minReplicas: 1
+  # guarantee a Raft majority
+  minReplicas: {{ .Values.clickhouseKeeper.replicas }}

This will keep the keeper pods ≥ the configured replica count and preserve quorum.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
replicas: {{ .Values.clickhouseKeeper.replicas }}
minReplicas: 1
kind: clickhouse
replicas: {{ .Values.clickhouseKeeper.replicas }}
# guarantee a Raft majority
minReplicas: {{ .Values.clickhouseKeeper.replicas }}
kind: clickhouse
🤖 Prompt for AI Agents
In packages/apps/clickhouse/templates/workloadmonitor.yaml around lines 21 to
23, the minReplicas value is set to 1, which can cause the Keeper HPA to scale
below the quorum needed for Raft consensus. Update minReplicas to be equal to
the configured clickhouseKeeper.replicas value to ensure the Keeper pods never
scale below the required quorum and maintain write availability.

Comment on lines +55 to +58
"replicas": {
"default": 3,
"description": "Number of keeper replicas",
"type": "number"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use integer type and add validation bounds

replicas should be an integer ≥ 1. Using "number" allows non-integer & negative values.

-        "replicas": {
-            "default": 3,
-            "description": "Number of keeper replicas",
-            "type": "number"
-        },
+        "replicas": {
+            "default": 3,
+            "description": "Number of keeper replicas",
+            "type": "integer",
+            "minimum": 1
+        },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"replicas": {
"default": 3,
"description": "Number of keeper replicas",
"type": "number"
"replicas": {
"default": 3,
"description": "Number of keeper replicas",
"type": "integer",
"minimum": 1
},
🤖 Prompt for AI Agents
In packages/apps/clickhouse/values.schema.json around lines 55 to 58, change the
type of the "replicas" property from "number" to "integer" and add validation
constraints to ensure the value is at least 1. This will prevent non-integer and
negative values from being accepted.

Signed-off-by: kklinch0 <kklinch0@gmail.com>
@klinch0 klinch0 merged commit bc22b22 into main Aug 7, 2025
3 checks passed
@klinch0 klinch0 deleted the clickhouse-add-ch-keeper branch August 7, 2025 11:26
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