Skip to content

Commit

Permalink
fix clickhouse sharding bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
loomts committed Jan 11, 2025
1 parent f33ab86 commit 20e7108
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
4 changes: 2 additions & 2 deletions addons-cluster/clickhouse-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fullnameOverride: ""
mode: cluster

## Sharding configuration
shards: 2
shards: 1
sharding: true

## Number of ClickHouse replicas per shard to deploy
replicas: 1
replicas: 2

## ClickHouse per shard component configurations
cpu: 1
Expand Down
59 changes: 40 additions & 19 deletions addons/clickhouse/configs/00_default_overrides.xml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,52 @@
<!-- Cluster configuration - Any update of the shards and replicas requires helm upgrade -->
<remote_servers>
<default>
{{- range $.cluster.spec.componentSpecs }}
{{- $compIter := . }}
{{- $compName := "" }}
{{- if hasKey $compIter "componentDef" }}
{{- $compName = $compIter.componentDef }}
{{- else }}
{{- $compName = $compIter.componentDefRef }}
{{- end }}
{{- if or (eq $compName "clickhouse") (eq $compName "clickhouse-24") }}
{{- $newAPI := false }}
{{- range $key, $value := . }}
{{- if and (hasPrefix "ALL_SHARDS_POD_FQDN_LIST" $key) (ne $value "") }}
{{- $newAPI = true }}
<shard>
{{- $replicas := $compIter.replicas | int }}
{{- range $i, $_e := until $replicas }}
{{- range $_, $host := splitList "," $value }}
<replica>
<host>{{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }}</host>
<host>{{ $host }}</host>
{{- if $.component.tlsConfig }}
<port replace="replace" from_env="CLICKHOUSE_TCP_SECURE_PORT"/>
<secure>1</secure>
{{- else }}
<port replace="replace" from_env="CLICKHOUSE_TCP_PORT"/>
{{- end }}
</replica>
{{- end }}
{{- end }}
</shard>
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if not $newAPI }}
{{- range $.cluster.spec.componentSpecs }}
{{- $compIter := . }}
{{- $compName := "" }}
{{- if hasKey $compIter "componentDef" }}
{{- $compName = $compIter.componentDef }}
{{- else }}
{{- $compName = $compIter.componentDefRef }}
{{- end }}
{{- if or (eq $compName "clickhouse") (eq $compName "clickhouse-24") }}
<shard>
{{- $replicas := $compIter.replicas | int }}
{{- range $i, $_e := until $replicas }}
<replica>
<host>{{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }}</host>
{{- if $.component.tlsConfig }}
<port replace="replace" from_env="CLICKHOUSE_TCP_SECURE_PORT"/>
<secure>1</secure>
{{- else }}
<port replace="replace" from_env="CLICKHOUSE_TCP_PORT"/>
{{- end }}
</replica>
{{- end }}
</shard>
{{- end }}
{{- end }}
{{- end }}
</default>
</remote_servers>
{{- range $.cluster.spec.componentSpecs }}
Expand Down Expand Up @@ -88,11 +109,11 @@
<events>true</events>
<asynchronous_metrics>true</asynchronous_metrics>
</prometheus>
{{- if $.component.tlsConfig -}}
{{- $CA_FILE := getCAFile -}}
{{- $CERT_FILE := getCertFile -}}
{{- $KEY_FILE := getKeyFile }}
<!-- tls configuration -->
{{- if $.component.tlsConfig -}}
{{- $CA_FILE := "/etc/pki/tls/ca.pem" -}}
{{- $CERT_FILE := "/etc/pki/tls/cert.pem" -}}
{{- $KEY_FILE := "/etc/pki/tls/key.pem" }}
<protocols>
<prometheus_protocol>
<type>prometheus</type>
Expand Down
8 changes: 8 additions & 0 deletions addons/clickhouse/templates/cmpd-ch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ spec:
name: admin
optional: false
password: Required
- name: ALL_SHARDS_POD_FQDN_LIST
valueFrom:
componentVarRef:
compDef: clickhouse-24
optional: false
podFQDNs: Required
multipleClusterObjectOption:
strategy: individual
volumes:
- name: data
services:
Expand Down

0 comments on commit 20e7108

Please sign in to comment.