Skip to content

Commit 24e43fc

Browse files
committed
fix(clickhouse): keep the Keeper name inside the StatefulSet volume-name limit
clickhouse-operator derives the Keeper config volume name as chk-<chk>-deploy-confd-<cluster>-<shard>-<replica>. The CHK is named <release>-keeper and Release.Name already carries the clickhouse- prefix, so an application name longer than 15 characters pushes that volume name past 63 characters: the StatefulSet is rejected, no Keeper pod appears, and the CHK still reports Completed. The CHK name is now shortened only when it would overflow, with a short hash of the release name so two long names stay distinct, and the ClickHouse zookeeper hosts are built from the same helper. Short names render exactly as before. Signed-off-by: Yan Bondarenko <[email protected]>
1 parent cd675e1 commit 24e43fc

4 files changed

Lines changed: 166 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- define "clickhouse.keeperName" -}}
2+
{{- $lastReplica := sub (int .Values.clickhouseKeeper.replicas) 1 -}}
3+
{{- $name := printf "%s-keeper" .Release.Name -}}
4+
{{- if gt (len (printf "chk-%s-deploy-confd-cluster1-0-%d" $name $lastReplica)) 63 -}}
5+
{{- $suffix := printf "-%s-keeper" (trunc 6 (sha256sum .Release.Name)) -}}
6+
{{- $room := sub 63 (len (printf "chk-%s-deploy-confd-cluster1-0-%d" $suffix $lastReplica)) -}}
7+
{{- $name = printf "%s%s" (trimSuffix "-" (trunc (int $room) .Release.Name)) $suffix -}}
8+
{{- end -}}
9+
{{- $name -}}
10+
{{- end -}}

‎packages/apps/clickhouse/templates/chkeeper.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
apiVersion: "clickhouse-keeper.altinity.com/v1"
55
kind: "ClickHouseKeeperInstallation"
66
metadata:
7-
name: "{{ .Release.Name }}-keeper"
7+
name: {{ include "clickhouse.keeperName" $ | quote }}
88
annotations:
99
prometheus.io/port: "7000"
1010
prometheus.io/scrape: "true"

‎packages/apps/clickhouse/templates/clickhouse.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ spec:
9494
zookeeper:
9595
nodes:
9696
{{- $replicas := int .Values.clickhouseKeeper.replicas }}
97-
{{- $release := .Release.Name }}
97+
{{- $keeper := include "clickhouse.keeperName" $ }}
9898
{{- $namespace := .Release.Namespace }}
9999
{{- $clusterDomain := .Values.clusterDomain }}
100100
{{- range $i := until $replicas }}
101-
- host: "chk-{{ $release }}-keeper-cluster1-0-{{ $i }}.{{ $namespace }}.svc.{{ $clusterDomain }}"
101+
- host: "chk-{{ $keeper }}-cluster1-0-{{ $i }}.{{ $namespace }}.svc.{{ $clusterDomain }}"
102102
port: 2181
103103
{{- end }}
104104
{{- end }}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
suite: keeper name budget
2+
3+
set:
4+
_cluster:
5+
cluster-domain: cluster.local
6+
clusterDomain: cluster.local
7+
8+
tests:
9+
- it: "keeps <release>-keeper for a short release name"
10+
release:
11+
name: ch-test
12+
namespace: tenant-test
13+
asserts:
14+
- equal:
15+
path: metadata.name
16+
value: ch-test-keeper
17+
template: templates/chkeeper.yaml
18+
documentSelector:
19+
path: kind
20+
value: ClickHouseKeeperInstallation
21+
- equal:
22+
path: spec.configuration.zookeeper.nodes[0].host
23+
value: chk-ch-test-keeper-cluster1-0-0.tenant-test.svc.cluster.local
24+
template: templates/clickhouse.yaml
25+
documentSelector:
26+
path: kind
27+
value: ClickHouseInstallation
28+
29+
- it: "keeps <release>-keeper when the confd volume name lands exactly on 63 characters"
30+
release:
31+
name: clickhouse-abcdefghijklmno
32+
namespace: tenant-test
33+
asserts:
34+
- equal:
35+
path: metadata.name
36+
value: clickhouse-abcdefghijklmno-keeper
37+
template: templates/chkeeper.yaml
38+
documentSelector:
39+
path: kind
40+
value: ClickHouseKeeperInstallation
41+
- equal:
42+
path: spec.configuration.zookeeper.nodes[2].host
43+
value: chk-clickhouse-abcdefghijklmno-keeper-cluster1-0-2.tenant-test.svc.cluster.local
44+
template: templates/clickhouse.yaml
45+
documentSelector:
46+
path: kind
47+
value: ClickHouseInstallation
48+
49+
- it: "shortens the name one character past the budget and keeps the ClickHouse side in step"
50+
release:
51+
name: clickhouse-abcdefghijklmnop
52+
namespace: tenant-test
53+
asserts:
54+
- equal:
55+
path: metadata.name
56+
value: clickhouse-abcdefgh-be3a98-keeper
57+
template: templates/chkeeper.yaml
58+
documentSelector:
59+
path: kind
60+
value: ClickHouseKeeperInstallation
61+
- matchRegex:
62+
path: metadata.name
63+
pattern: ^[a-z0-9-]{1,33}$
64+
template: templates/chkeeper.yaml
65+
documentSelector:
66+
path: kind
67+
value: ClickHouseKeeperInstallation
68+
- equal:
69+
path: spec.configuration.zookeeper.nodes[0].host
70+
value: chk-clickhouse-abcdefgh-be3a98-keeper-cluster1-0-0.tenant-test.svc.cluster.local
71+
template: templates/clickhouse.yaml
72+
documentSelector:
73+
path: kind
74+
value: ClickHouseInstallation
75+
- equal:
76+
path: spec.configuration.zookeeper.nodes[2].host
77+
value: chk-clickhouse-abcdefgh-be3a98-keeper-cluster1-0-2.tenant-test.svc.cluster.local
78+
template: templates/clickhouse.yaml
79+
documentSelector:
80+
path: kind
81+
value: ClickHouseInstallation
82+
83+
- it: "leaves the pod label, the scrape and the monitor on <release>-keeper when the name is shortened"
84+
release:
85+
name: clickhouse-abcdefghijklmnop
86+
namespace: tenant-test
87+
asserts:
88+
- equal:
89+
path: spec.templates.podTemplates[0].metadata.labels.app
90+
value: clickhouse-abcdefghijklmnop-keeper
91+
template: templates/chkeeper.yaml
92+
documentSelector:
93+
path: kind
94+
value: ClickHouseKeeperInstallation
95+
- equal:
96+
path: spec.selector.matchLabels.app
97+
value: clickhouse-abcdefghijklmnop-keeper
98+
template: templates/chkeeper.yaml
99+
documentSelector:
100+
path: kind
101+
value: VMPodScrape
102+
- equal:
103+
path: spec.selector.app
104+
value: clickhouse-abcdefghijklmnop-keeper
105+
template: templates/workloadmonitor.yaml
106+
documentSelector:
107+
path: metadata.name
108+
value: clickhouse-abcdefghijklmnop-keeper
109+
110+
- it: "does not end the truncated prefix with a dash"
111+
release:
112+
name: clickhouse-abcdefg-hijklmnop
113+
namespace: tenant-test
114+
templates:
115+
- templates/chkeeper.yaml
116+
documentSelector:
117+
path: kind
118+
value: ClickHouseKeeperInstallation
119+
asserts:
120+
- equal:
121+
path: metadata.name
122+
value: clickhouse-abcdefg-0c8860-keeper
123+
124+
- it: "fits a very long release name into the same budget"
125+
release:
126+
name: clickhouse-very-long-application-name-here
127+
namespace: tenant-test
128+
templates:
129+
- templates/chkeeper.yaml
130+
documentSelector:
131+
path: kind
132+
value: ClickHouseKeeperInstallation
133+
asserts:
134+
- equal:
135+
path: metadata.name
136+
value: clickhouse-very-lon-94e5b4-keeper
137+
138+
- it: "gives a two-digit replica index one more character of room"
139+
release:
140+
name: clickhouse-abcdefghijklmno
141+
namespace: tenant-test
142+
set:
143+
clickhouseKeeper:
144+
replicas: 11
145+
templates:
146+
- templates/chkeeper.yaml
147+
documentSelector:
148+
path: kind
149+
value: ClickHouseKeeperInstallation
150+
asserts:
151+
- equal:
152+
path: metadata.name
153+
value: clickhouse-abcdefg-8d42f8-keeper

0 commit comments

Comments
 (0)