Skip to content

Commit 11b9f18

Browse files
feat: add clickhouse-cluster helm chart
1 parent f08fa9e commit 11b9f18

14 files changed

Lines changed: 729 additions & 10 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,17 @@ jobs:
176176
run: helm version
177177

178178
- name: Check helmchart generated
179-
run: make generate-helmchart-ci && git diff --exit-code dist/chart/
179+
run: make generate-helmchart-ci && git diff --exit-code dist/chart/ dist/chart-cluster/
180180

181181
- name: Build Helm Chart Dependencies
182182
run: make build-helmchart-dependencies
183183

184184
- name: Lint Helm Chart
185185
run: helm lint ./dist/chart
186186

187+
- name: Lint Cluster Helm Chart
188+
run: make lint-cluster-chart
189+
187190
compat-e2e-test:
188191
runs-on: [ubuntu-latest]
189192
strategy:

.github/workflows/release.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,16 @@ jobs:
7272
run: helm version
7373
- name: Set VERSION
7474
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
75-
- name: Package helm chart
75+
- name: Log in registry
76+
run: helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
77+
- name: Package operator helm chart
7678
run: make package-helmchart
7779
- name: Build and push helm OCI image
78-
run: |
79-
helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
80-
make push-helmchart
80+
run: make push-helmchart
81+
- name: Package cluster chart
82+
run: make package-cluster-chart
83+
- name: Build and push cluster chart OCI image
84+
run: make push-cluster-chart
8185

8286
create-release:
8387
runs-on: ubuntu-latest
@@ -105,6 +109,8 @@ jobs:
105109
run: helm version
106110
- name: Package helm chart
107111
run: make package-helmchart
112+
- name: Package cluster chart
113+
run: make package-cluster-chart
108114

109115
- name: Log in to the Container registry
110116
uses: docker/login-action@v4
@@ -168,4 +174,5 @@ jobs:
168174
files: |
169175
dist/clickhouse-operator.yaml
170176
clickhouse-operator-helm-${{env.VERSION}}.tgz
177+
clickhouse-cluster-helm-${{env.VERSION}}.tgz
171178
clickhouse-operator_${{env.VERSION}}_*.tar.gz

Makefile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ generate-helmchart: kubebuilder kustomize ## Generate helm charts
196196
rm .github/workflows/test-chart.yml dist/install-helm.yaml
197197

198198
.PHONY: generate-helmchart-ci
199-
generate-helmchart-ci: generate-helmchart ## Generate helm charts and reset some files that will always generate diff
199+
generate-helmchart-ci: generate-helmchart generate-cluster-chart ## Generate helm charts and reset some files that will always generate diff
200200
git checkout dist/chart/templates/cert-manager/
201201
git checkout dist/chart/templates/manager/
202202

@@ -212,6 +212,35 @@ package-helmchart: build-helmchart-dependencies ## Package helm chart. It will b
212212
push-helmchart: package-helmchart ## Push helm image. It will be pushed to the ${IMAGE_REPO}/(helmchart name, same as in Chart.yaml)
213213
helm push clickhouse-operator-helm-${VERSION}.tgz oci://$(IMAGE_REPO)
214214

215+
##@ Cluster Helm Chart
216+
217+
CLUSTER_CHART_DIR := dist/chart-cluster
218+
GEN_CLUSTER_CHART ?= $(LOCALBIN)/gen-cluster-chart
219+
220+
.PHONY: gen-cluster-chart-bin
221+
gen-cluster-chart-bin: $(LOCALBIN) ## Build the cluster-chart generator binary.
222+
go build -o $(GEN_CLUSTER_CHART) ./tools/gen-cluster-chart
223+
224+
.PHONY: generate-cluster-chart
225+
generate-cluster-chart: manifests gen-cluster-chart-bin ## Generate cluster chart values.yaml from CRDs.
226+
$(GEN_CLUSTER_CHART) \
227+
-clickhouse-crd config/crd/bases/clickhouse.com_clickhouseclusters.yaml \
228+
-keeper-crd config/crd/bases/clickhouse.com_keeperclusters.yaml \
229+
-out $(CLUSTER_CHART_DIR)
230+
231+
.PHONY: package-cluster-chart
232+
package-cluster-chart: ## Package cluster chart. It will be saved as clickhouse-cluster-helm-$(VERSION).tgz
233+
helm package --version ${VERSION} --app-version v${VERSION} $(CLUSTER_CHART_DIR)
234+
235+
.PHONY: push-cluster-chart
236+
push-cluster-chart: package-cluster-chart ## Push cluster chart. It will be pushed to ${IMAGE_REPO}/clickhouse-cluster-helm
237+
helm push clickhouse-cluster-helm-${VERSION}.tgz oci://$(IMAGE_REPO)
238+
239+
.PHONY: lint-cluster-chart
240+
lint-cluster-chart: ## Lint + dry-render cluster chart.
241+
helm lint $(CLUSTER_CHART_DIR)
242+
helm template test $(CLUSTER_CHART_DIR) > /dev/null
243+
215244
##@ Build
216245

217246
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ For users who want to quickly try the operator:
5252
```
5353

5454
2. Deploy a sample cluster:
55-
```sh
56-
kubectl apply -f https://raw.githubusercontent.com/ClickHouse/clickhouse-operator/refs/heads/main/examples/minimal.yaml
57-
```
55+
- Using raw manifests:
56+
```sh
57+
kubectl apply -f https://raw.githubusercontent.com/ClickHouse/clickhouse-operator/refs/heads/main/examples/minimal.yaml
58+
```
59+
- Using the helm chart:
60+
```sh
61+
helm install ch oci://ghcr.io/clickhouse/clickhouse-cluster-helm \
62+
--create-namespace \
63+
-n clickhouse
64+
```
5865

5966
3. Verify the deployment:
6067
```sh

dist/chart-cluster/.helmignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Patterns to ignore when building Helm packages.
2+
# Operating system files
3+
.DS_Store
4+
5+
# Version control directories
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.hg/
10+
.hgignore
11+
.svn/
12+
13+
# Backup and temporary files
14+
*.swp
15+
*.tmp
16+
*.bak
17+
*.orig
18+
*~
19+
20+
# IDE and editor-related files
21+
.idea/
22+
.vscode/
23+
24+
# Helm chart artifacts
25+
dist/chart/*.tgz

dist/chart-cluster/Chart.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v2
2+
name: clickhouse-cluster-helm
3+
type: application
4+
version: 0.0.1
5+
appVersion: "latest"
6+
kubeVersion: ">= 1.28.0-0"
7+
description: |
8+
Chart that deploys a ClickHouse cluster and a Keeper via the ClickHouse Operator.
9+
Install the operator chart first (oci://ghcr.io/clickhouse/clickhouse-operator-helm).
10+
This chart only renders ClickHouseCluster + KeeperCluster CRs and relies on the operator's reconcilers
11+
to do the actual provisioning.
12+
keywords:
13+
- database
14+
- clickhouse
15+
- keeper
16+
maintainers:
17+
- name: ClickHouse Team
18+
email: operator@clickhouse.com
19+
home: https://github.com/ClickHouse/clickhouse-operator
20+
icon: "https://clickhouse.com/docs/img/clickhouse-operator-logo.svg"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{- $ch := .Values.clickhouse.enabled }}
2+
{{- $kp := .Values.keeper.enabled }}
3+
ClickHouse cluster {{ .Release.Name }} installed in namespace {{ .Release.Namespace }}.
4+
5+
{{ if $ch }}ClickHouseCluster: {{ include "clickhouse-cluster.clickhouse.name" . }}{{ end }}
6+
{{ if $kp }}KeeperCluster: {{ include "clickhouse-cluster.keeper.name" . }}{{ end }}
7+
8+
Watch reconciliation:
9+
10+
kubectl -n {{ .Release.Namespace }} get clickhousecluster,keepercluster -w
11+
{{ if $ch }}
12+
ClickHouseCluster status:
13+
14+
kubectl -n {{ .Release.Namespace }} describe clickhousecluster {{ include "clickhouse-cluster.clickhouse.name" . }}
15+
{{ end }}{{ if $kp }}
16+
KeeperCluster status:
17+
18+
kubectl -n {{ .Release.Namespace }} describe keepercluster {{ include "clickhouse-cluster.keeper.name" . }}
19+
{{ end }}
20+
NOTE: this chart only renders CRs. The ClickHouse Operator must be installed
21+
separately. Match --version with this chart for guaranteed compatibility:
22+
23+
helm install clickhouse-operator oci://ghcr.io/clickhouse/clickhouse-operator-helm \
24+
--version {{ .Chart.Version }} --create-namespace -n clickhouse-operator-system
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "clickhouse-cluster.chart-name" -}}
5+
{{ trimSuffix "-helm" .Chart.Name }}
6+
{{- end }}
7+
8+
{{/*
9+
Fully-qualified release-scoped name used as the base of all CR names.
10+
If the release name already contains the chart name, just use the release name.
11+
*/}}
12+
{{- define "clickhouse-cluster.fullname" -}}
13+
{{- $name := include "clickhouse-cluster.chart-name" . }}
14+
{{- if contains $name .Release.Name }}
15+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
18+
{{- end }}
19+
{{- end }}
20+
21+
{{/*
22+
ClickHouseCluster CR name. Respects clickhouse.meta.name.
23+
*/}}
24+
{{- define "clickhouse-cluster.clickhouse.name" -}}
25+
{{- if .Values.clickhouse.meta.name }}
26+
{{- .Values.clickhouse.meta.name | trunc 63 | trimSuffix "-" }}
27+
{{- else }}
28+
{{- include "clickhouse-cluster.fullname" . | trunc 63 | trimSuffix "-" }}
29+
{{- end }}
30+
{{- end }}
31+
32+
{{/*
33+
KeeperCluster CR name. Respects keeper.meta.name. Defaults to fullname.
34+
*/}}
35+
{{- define "clickhouse-cluster.keeper.name" -}}
36+
{{- if .Values.keeper.meta.name }}
37+
{{- .Values.keeper.meta.name | trunc 63 | trimSuffix "-" }}
38+
{{- else }}
39+
{{- (include "clickhouse-cluster.fullname" .) | trunc 63 | trimSuffix "-" }}
40+
{{- end }}
41+
{{- end }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{- if .Values.clickhouse.enabled -}}
2+
apiVersion: clickhouse.com/v1alpha1
3+
kind: ClickHouseCluster
4+
metadata:
5+
name: {{ include "clickhouse-cluster.clickhouse.name" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
app.kubernetes.io/name: clickhouse
9+
app.kubernetes.io/component: clickhouse-cluster
10+
{{- with .Values.clickhouse.meta.labels }}
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
{{- with .Values.clickhouse.meta.annotations }}
14+
annotations:
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
spec:
18+
{{- /* Chart-provided defaults: image tag falls back to chart appVersion. User values override. */}}
19+
{{- $defaults := dict "containerTemplate" (dict "image" (dict "tag" .Chart.AppVersion)) }}
20+
{{- $spec := mergeOverwrite $defaults (deepCopy (.Values.clickhouse.spec | default dict)) }}
21+
{{- /* Auto-wire keeperClusterRef when keeper is enabled in-chart and user did not pin one. */}}
22+
{{- if and .Values.keeper.enabled (not (hasKey $spec "keeperClusterRef")) }}
23+
{{- $_ := set $spec "keeperClusterRef" (dict "name" (include "clickhouse-cluster.keeper.name" .)) }}
24+
{{- end }}
25+
{{- toYaml $spec | nindent 2 }}
26+
{{- end }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- if .Values.keeper.enabled -}}
2+
apiVersion: clickhouse.com/v1alpha1
3+
kind: KeeperCluster
4+
metadata:
5+
name: {{ include "clickhouse-cluster.keeper.name" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
app.kubernetes.io/name: keeper
9+
app.kubernetes.io/component: keeper-cluster
10+
{{- with .Values.keeper.meta.labels }}
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
{{- with .Values.keeper.meta.annotations }}
14+
annotations:
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
spec:
18+
{{- /* Chart-provided defaults: image tag falls back to chart appVersion. User values override. */}}
19+
{{- $defaults := dict "containerTemplate" (dict "image" (dict "tag" .Chart.AppVersion)) }}
20+
{{- $spec := mergeOverwrite $defaults (deepCopy (.Values.keeper.spec | default dict)) }}
21+
{{- toYaml $spec | nindent 2 }}
22+
{{- end }}

0 commit comments

Comments
 (0)