From 20e7108bcc8327226b4167d4bb4f73559009af3a Mon Sep 17 00:00:00 2001 From: loomt Date: Thu, 9 Jan 2025 10:30:34 +0800 Subject: [PATCH] fix clickhouse sharding bootstrap --- addons-cluster/clickhouse-cluster/values.yaml | 4 +- .../configs/00_default_overrides.xml.tpl | 59 +++++++++++++------ addons/clickhouse/templates/cmpd-ch.yaml | 8 +++ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/addons-cluster/clickhouse-cluster/values.yaml b/addons-cluster/clickhouse-cluster/values.yaml index 8ed98955f..3c6771999 100644 --- a/addons-cluster/clickhouse-cluster/values.yaml +++ b/addons-cluster/clickhouse-cluster/values.yaml @@ -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 diff --git a/addons/clickhouse/configs/00_default_overrides.xml.tpl b/addons/clickhouse/configs/00_default_overrides.xml.tpl index 707257b82..9470395e9 100644 --- a/addons/clickhouse/configs/00_default_overrides.xml.tpl +++ b/addons/clickhouse/configs/00_default_overrides.xml.tpl @@ -27,20 +27,14 @@ - {{- 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 }} - {{- $replicas := $compIter.replicas | int }} - {{- range $i, $_e := until $replicas }} + {{- range $_, $host := splitList "," $value }} - {{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }} + {{ $host }} {{- if $.component.tlsConfig }} 1 @@ -48,10 +42,37 @@ {{- end }} - {{- end }} + {{- end }} - {{- 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") }} + + {{- $replicas := $compIter.replicas | int }} + {{- range $i, $_e := until $replicas }} + + {{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }} + {{- if $.component.tlsConfig }} + + 1 + {{- else }} + + {{- end }} + + {{- end }} + + {{- end }} + {{- end }} + {{- end }} {{- range $.cluster.spec.componentSpecs }} @@ -88,11 +109,11 @@ true true - {{- if $.component.tlsConfig -}} - {{- $CA_FILE := getCAFile -}} - {{- $CERT_FILE := getCertFile -}} - {{- $KEY_FILE := getKeyFile }} + {{- if $.component.tlsConfig -}} + {{- $CA_FILE := "/etc/pki/tls/ca.pem" -}} + {{- $CERT_FILE := "/etc/pki/tls/cert.pem" -}} + {{- $KEY_FILE := "/etc/pki/tls/key.pem" }} prometheus diff --git a/addons/clickhouse/templates/cmpd-ch.yaml b/addons/clickhouse/templates/cmpd-ch.yaml index 5cc171e4c..7a87b11a3 100644 --- a/addons/clickhouse/templates/cmpd-ch.yaml +++ b/addons/clickhouse/templates/cmpd-ch.yaml @@ -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: