From 0a90c71d36154d1e136816341151644ffafe50d8 Mon Sep 17 00:00:00 2001 From: jtomaszon Date: Sat, 6 Jun 2026 11:15:42 +0000 Subject: [PATCH 1/2] fix(helm): wire watchNamespaces value into operator ConfigMap The configs.files.config.yaml.watch.namespaces.include field was hardcoded to [] in values.yaml and the ConfigMap template rendered it directly with no way to override it via a top-level Helm value. This patch introduces a top-level watchNamespaces value and a new configmap-files helper that deep-copies configs.files, patches the nested watch.namespaces.include in-place, then delegates to the existing configmap-data helper for rendering. Fixes #1919 --- .../templates/_helpers.tpl | 22 +++++++++++++++++++ ...nfigMap-etc-clickhouse-operator-files.yaml | 2 +- deploy/helm/clickhouse-operator/values.yaml | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/deploy/helm/clickhouse-operator/templates/_helpers.tpl b/deploy/helm/clickhouse-operator/templates/_helpers.tpl index f2d1aee2b..4cdabde82 100644 --- a/deploy/helm/clickhouse-operator/templates/_helpers.tpl +++ b/deploy/helm/clickhouse-operator/templates/_helpers.tpl @@ -122,3 +122,25 @@ null {{- tpl (toYaml (dict $k $v)) $root }} {{ end }} {{- end }} + +{{/* +altinity-clickhouse-operator.configmap-files merges watchNamespaces into the +operator config before rendering the ConfigMap data block. + +This exists because configs.files.config.yaml.watch.namespaces.include is +deep inside a nested structure — Helm's values merge cannot target it +directly. Instead we deepCopy the files map, patch the nested value in-place, +and pass the result to configmap-data. + +Arguments (list): root context, configs.files, watchNamespaces list +*/}} +{{- define "altinity-clickhouse-operator.configmap-files" -}} +{{- $root := index . 0 -}} +{{- $files := deepCopy (index . 1) -}} +{{- $watchNamespaces := index . 2 -}} +{{- if $watchNamespaces -}} + {{- $namespaces := index (index (index $files "config.yaml") "watch") "namespaces" -}} + {{- $_ := set $namespaces "include" $watchNamespaces -}} +{{- end -}} +{{- include "altinity-clickhouse-operator.configmap-data" (list $root $files) -}} +{{- end -}} diff --git a/deploy/helm/clickhouse-operator/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml b/deploy/helm/clickhouse-operator/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml index bc6d21dd1..df1886ac3 100644 --- a/deploy/helm/clickhouse-operator/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml +++ b/deploy/helm/clickhouse-operator/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml @@ -11,4 +11,4 @@ metadata: namespace: {{ include "altinity-clickhouse-operator.namespace" . }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} annotations: {{ include "altinity-clickhouse-operator.annotations" . | nindent 4 }} -data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.files) | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-files" (list . .Values.configs.files .Values.watchNamespaces) | nindent 2 }} diff --git a/deploy/helm/clickhouse-operator/values.yaml b/deploy/helm/clickhouse-operator/values.yaml index b7579fce9..c5ca1a8bd 100644 --- a/deploy/helm/clickhouse-operator/values.yaml +++ b/deploy/helm/clickhouse-operator/values.yaml @@ -147,6 +147,11 @@ podAnnotations: prometheus.io/scrape: 'true' clickhouse-operator-metrics/port: '9999' clickhouse-operator-metrics/scrape: 'true' +# watchNamespaces -- namespaces where the operator watches for ClickHouseInstallation resources. +# If empty, the operator watches only its own namespace (or all namespaces when running in kube-system). +# Use [".*"] to watch all namespaces. +# Example: watchNamespaces: ["clickhouse", "my-other-namespace"] +watchNamespaces: [] # nameOverride -- override name of the chart nameOverride: "" # fullnameOverride -- full name of the chart. From 4e726f7471bb3de403505af7bf035e601d50a41e Mon Sep 17 00:00:00 2001 From: Javier Tomas Zon Date: Thu, 2 Jul 2026 11:43:17 +0000 Subject: [PATCH 2/2] fix(helm): generate watchNamespaces ConfigMap wiring from the generator Address review: the previous change hand-edited the generated ConfigMap-etc-clickhouse-operator-files.yaml. Instead, special-case the etc-clickhouse-operator-files ConfigMap in update_configmap_resource() so generate_helm_chart.sh emits the configmap-files helper (which wires watchNamespaces into watch.namespaces.include). Re-running the generator now reproduces the committed template. README values table regenerated by helm-docs. --- deploy/helm/clickhouse-operator/README.md | 1 + dev/generate_helm_chart.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deploy/helm/clickhouse-operator/README.md b/deploy/helm/clickhouse-operator/README.md index 8e9cfa4ca..a18123bc0 100644 --- a/deploy/helm/clickhouse-operator/README.md +++ b/deploy/helm/clickhouse-operator/README.md @@ -138,4 +138,5 @@ crdHook: | serviceMonitor.operatorMetrics.scrapeTimeout | string | `""` | | | tolerations | list | `[]` | tolerations for scheduler pod assignment, check `kubectl explain pod.spec.tolerations` for details | | topologySpreadConstraints | list | `[]` | | +| watchNamespaces | list | `[]` | namespaces where the operator watches for ClickHouseInstallation resources. If empty, the operator watches only its own namespace (or all namespaces when running in kube-system). Use [".*"] to watch all namespaces. Example: watchNamespaces: ["clickhouse", "my-other-namespace"] | diff --git a/dev/generate_helm_chart.sh b/dev/generate_helm_chart.sh index 8a0664efa..f519a210a 100755 --- a/dev/generate_helm_chart.sh +++ b/dev/generate_helm_chart.sh @@ -290,7 +290,14 @@ function update_configmap_resource() { yq e -i '.metadata.namespace |= "{{ include \"altinity-clickhouse-operator.namespace\" . }}"' "${file}" yq e -i '.metadata.labels |= "{{ include \"altinity-clickhouse-operator.labels\" . | nindent 4 }}"' "${file}" yq e -i '.metadata.annotations |= "{{ include \"altinity-clickhouse-operator.annotations\" . | nindent 4 }}"' "${file}" - yq e -i '.data |= "{{ include \"altinity-clickhouse-operator.configmap-data\" (list . .Values.configs.'"${camel_cased_name}"') | nindent 2 }}"' "${file}" + if [ "${name}" = "etc-clickhouse-operator-files" ]; then + # The operator config ConfigMap needs watchNamespaces wired in. Use the + # configmap-files helper (which patches watch.namespaces.include from the + # top-level watchNamespaces value) instead of the generic configmap-data. + yq e -i '.data |= "{{ include \"altinity-clickhouse-operator.configmap-files\" (list . .Values.configs.files .Values.watchNamespaces) | nindent 2 }}"' "${file}" + else + yq e -i '.data |= "{{ include \"altinity-clickhouse-operator.configmap-data\" (list . .Values.configs.'"${camel_cased_name}"') | nindent 2 }}"' "${file}" + fi if [ -z "${data}" ]; then yq e -i '.configs.'"${camel_cased_name}"' |= null' "${values_yaml}"