Skip to content

Commit

Permalink
chore: migrate api from 0.7 to 0.9 for clickhouse addon (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Sep 12, 2024
1 parent ba0acf2 commit 5aa9fc9
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 190 deletions.
11 changes: 5 additions & 6 deletions addons-cluster/clickhouse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ type: application

version: 1.0.0-alpha.0

appVersion: 22.9.4
appVersion: 24.3.10

dependencies:
- name: kblib
version: 0.1.1
repository: file://../kblib
alias: extra


home: https://clickhouse.com/
icon: https://bitnami.com/assets/stacks/clickhouse/img/clickhouse-stack-220x234.png
keywords:
- database
- sharding
- database
- sharding

maintainers:
- name: Nash Tsai
url: https://github.com/apecloud/kubeblocks/deploy
- name: ApeCloud
url: https://kubeblocks.io/
129 changes: 129 additions & 0 deletions addons-cluster/clickhouse/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,132 @@ Create the name of the service account to use
{{- define "clickhouse-cluster.serviceAccountName" -}}
{{- default (printf "kb-%s" (include "clustername" .)) .Values.serviceAccount.name }}
{{- end }}

{{/*
Define clickhouse componentSpec with ComponentDefinition.
*/}}
{{- define "clickhouse-ch-component" -}}
- name: clickhouse
componentDef: clickhouse-24
replicas: {{ $.Values.clickhouse.replicaCount | default 2 }}
serviceAccountName: {{ include "clickhouse-cluster.serviceAccountName" $ }}
{{- with $.Values.clickhouse.tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.clickhouse.resources }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.clickhouse.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.clickhouse.persistence.data.size }}
{{- end }}

{{/*
Define clickhouse keeper componentSpec with ComponentDefinition.
*/}}
{{- define "clickhouse-keeper-component" -}}
- name: ch-keeper
componentDef: ch-keeper-24
replicas: {{ .Values.keeper.replicaCount }}
{{- with .Values.clickhouse.tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.keeper.resources }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.keeper.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.keeper.persistence.data.size }}
{{- end }}

{{/*
Define clickhouse shardingComponentSpec with ComponentDefinition.
*/}}
{{- define "clickhouse-sharding-component" -}}
- name: shard
shards: {{ .Values.shardCount }}
template:
name: clickhouse
componentDef: clickhouse-24
replicas: {{ $.Values.clickhouse.replicaCount | default 2 }}
serviceAccountName: {{ include "clickhouse-cluster.serviceAccountName" $ }}
{{- with $.Values.clickhouse.tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.clickhouse.resources }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.clickhouse.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.clickhouse.persistence.data.size }}
{{- end }}

{{/*
Define clickhouse componentSpec with compatible ComponentDefinition API
*/}}
{{- define "clickhouse-nosharding-component" -}}
{{- range $i := until (.Values.shardCount | int) }}
- name: shard-{{ $i }}
componentDef: clickhouse-24
replicas: {{ $.Values.clickhouse.replicaCount | default 2 }}
disableExporter: false
serviceAccountName: {{ include "clickhouse-cluster.serviceAccountName" $ }}
{{- with $.Values.clickhouse.tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.clickhouse.resources }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.clickhouse.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.clickhouse.persistence.data.size }}
{{- end }}
{{- end }}
95 changes: 17 additions & 78 deletions addons-cluster/clickhouse/templates/cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,79 +1,18 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: {{ include "clustername" . }}
labels: {{ include "clickhouse-cluster.labels" . | nindent 4 }}
spec:
terminationPolicy: {{ $.Values.extra.terminationPolicy }}
affinity:
{{- with $.Values.topologyKeys }}
topologyKeys: {{ . | toYaml | nindent 6 }}
{{- end }}
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
{{- include "kblib.clusterCommon" . }}
{{- if eq (.Values.shardCount | int) 1 }}
clusterDefinitionRef: clickhouse
topology: clickhouse-cluster
{{- end }}
componentSpecs:
{{- range $i := until (.Values.shardCount|int) }}
- name: shard-{{ $i }}
componentDef: clickhouse
monitor: {{ $.Values.monitor.enabled }}
replicas: {{ $.Values.clickhouse.replicaCount | default 2 }}
serviceAccountName: {{ include "clickhouse-cluster.serviceAccountName" $ }}
{{- with $.Values.clickhouse.tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.clickhouse.resources }}
resources:
limits:
cpu: {{ $.Values.clickhouse.limits.cpu | quote }}
memory: {{ $.Values.clickhouse.limits.memory | quote }}
requests:
cpu: {{ $.Values.clickhouse.requests.cpu | quote }}
memory: {{ $.Values.clickhouse.requests.memory | quote }}
{{- end }}
{{- if $.Values.clickhouse.persistence.enabled }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.clickhouse.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.clickhouse.persistence.data.size }}
{{- end }}
{{- end }}
{{- if (gt ($.Values.shardCount|int) 1) }}
- {{- if $.Values.useClickHouseKeeper }}
name: ch-keeper
componentDef: clickhouse-keeper
{{- else }}
name: zookeeper
componentDef: zookeeper
{{- end }}
monitor: {{ $.Values.monitor.enabled }}
replicas: {{ $.Values.keeper.replicaCount }}
{{- with .tolerations }}
tolerations: {{ .| toYaml | nindent 8 }}
{{- end }}
{{- with $.Values.keeper.resources }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
{{- if $.Values.keeper.persistence.enabled }}
volumeClaimTemplates:
- name: data
spec:
storageClassName: {{ $.Values.keeper.persistence.data.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $.Values.keeper.persistence.data.size }}
{{- end }}
{{- end }}
{{- include "clickhouse-keeper-component" . | nindent 4 }}
{{- if eq (.Values.shardCount | int) 1 }}
{{- include "clickhouse-ch-component" . | nindent 4 }}
{{- end }}
{{- if gt (.Values.shardCount | int) 1 }}
{{- if not .Values.sharding.enabled }}
{{- include "clickhouse-nosharding-component" . | nindent 4 }}
{{- else }}
shardingSpecs:
{{- include "clickhouse-sharding-component" . | nindent 4 }}
{{- end }}
{{- end }}
10 changes: 8 additions & 2 deletions addons-cluster/clickhouse/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ clickhouse:
persistence:
## @param clickhouse[*].persistence.enabled Enable persistence using Persistent Volume Claims
##
enabled: false
enabled: true
## `data` volume settings
##
data:
Expand Down Expand Up @@ -162,7 +162,7 @@ keeper:
# memory: 128Mi

persistence:
enabled: false
enabled: true
data:
storageClassName:
size: 8Gi
Expand Down Expand Up @@ -283,3 +283,9 @@ fullnameOverride: ""
# The RBAC permission used by cluster component pod, now include event.create
serviceAccount:
name: ""

extra:
rbacEnabled: false

sharding:
enabled: false
2 changes: 1 addition & 1 deletion addons/clickhouse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type: application

version: 1.0.0-alpha.0

appVersion: 22.9.4
appVersion: 24.3.10

home: https://clickhouse.com/
icon: https://bitnami.com/assets/stacks/clickhouse/img/clickhouse-stack-220x234.png
Expand Down
20 changes: 4 additions & 16 deletions addons/clickhouse/configs/00_default_overrides.xml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,25 @@
<!-- Cluster configuration - Any update of the shards and replicas requires helm upgrade -->
<remote_servers>
<default>
{{- range $.cluster.spec.componentSpecs }}
{{ $compIter := . }}
{{- if eq $compIter.componentDefRef "clickhouse" }}
<shard>
{{- $replicas := $compIter.replicas | int }}
{{- range $i, $_e := until $replicas }}
{{- range $_, $host := splitList "," .CLICKHOUSE_POD_FQDN_LIST }}
<replica>
<host>{{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }}</host>
<host>{{ $host }}</host>
<port>9000</port>
</replica>
{{- end }}
</shard>
{{- end }}
{{- end }}
</default>
</remote_servers>
{{- range $.cluster.spec.componentSpecs }}
{{ $compIter := . }}
{{- if or (eq $compIter.componentDefRef "zookeeper") (eq $compIter.componentDefRef "ch-keeper") }}
<!-- Zookeeper configuration -->
<zookeeper>
{{- $replicas := $compIter.replicas | int }}
{{- range $i, $_e := until $replicas }}
{{- range $_, $host := splitList "," .CH_KEEPER_POD_FQDN_LIST }}
<node>
<host>{{ $clusterName }}-{{ $compIter.name }}-{{ $i }}.{{ $clusterName }}-{{ $compIter.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }}</host>
<host>{{ $host }}</host>
<port>2181</port>
</node>
{{- end }}
</zookeeper>
{{- end }}
{{- end }}
<!-- Prometheus metrics -->
<prometheus>
<endpoint>/metrics</endpoint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<listen_host>0.0.0.0</listen_host>
<keeper_server>
<tcp_port from_env="CLICKHOUSE_KEEPER_TCP_PORT"></tcp_port>
<server_id>1</server_id>
<server_id from_env="CH_KEEPER_ID"></server_id>
<log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
<coordination_settings>
Expand All @@ -13,11 +13,10 @@
<raft_logs_level>warning</raft_logs_level>
</coordination_settings>
<raft_configuration>
{{- $replicas := $.component.replicas | int }}
{{- range $i, $e := until $replicas }}
{{- range $id, $host := splitList "," .CH_KEEPER_POD_FQDN_LIST }}
<server>
<id>{{ $i | int | add1 }}</id>
<hostname>{{ $clusterName }}-{{ $.component.name }}-{{ $i }}.{{ $clusterName }}-{{ $.component.name }}-headless.{{ $namespace }}.svc.{{- $.clusterDomain }}</hostname>
<id>{{ $id }}</id>
<hostname>{{ $host }}</hostname>
<port from_env="CLICKHOUSE_KEEPER_RAFT_PORT"></port>
</server>
{{- end }}
Expand Down
28 changes: 28 additions & 0 deletions addons/clickhouse/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
name: clickhouse
labels:
{{- include "clickhouse.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
topologies:
- name: standalone
components:
- name: clickhouse
compDef: clickhouse-24
- name: clickhouse-cluster
components:
- name: clickhouse
compDef: clickhouse-24
- name: ch-keeper
compDef: ch-keeper-24
orders:
provision:
- ch-keeper
- clickhouse
Loading

0 comments on commit 5aa9fc9

Please sign in to comment.