From 22d0927be65d4dd147f71bf880a31c8604d29e1c Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 28 Jan 2024 01:32:25 +0100 Subject: [PATCH] update helm chart generator to treat config.yaml as yaml in values Signed-off-by: Chris --- deploy/helm/templates/_helpers.tpl | 16 ++++++++++++ ...p-etc-clickhouse-operator-confd-files.yaml | 2 +- ...etc-clickhouse-operator-configd-files.yaml | 2 +- ...nfigMap-etc-clickhouse-operator-files.yaml | 2 +- ...-clickhouse-operator-templatesd-files.yaml | 2 +- ...-etc-clickhouse-operator-usersd-files.yaml | 2 +- .../ServiceAccount-clickhouse-operator.yaml | 1 - deploy/helm/values.yaml | 26 ++----------------- dev/generate_helm_chart.sh | 10 ++++--- 9 files changed, 30 insertions(+), 33 deletions(-) diff --git a/deploy/helm/templates/_helpers.tpl b/deploy/helm/templates/_helpers.tpl index b0ac1a4e7..9d6fc81fa 100644 --- a/deploy/helm/templates/_helpers.tpl +++ b/deploy/helm/templates/_helpers.tpl @@ -81,3 +81,19 @@ metadata: labels: {{- include "altinity-clickhouse-operator.labels" . | nindent 4 }} {{- end }} + +{{/* +*/}} +{{- define "altinity-clickhouse-operator.configmap-data" }} +{{- $root := index . 0 }} +{{- $data := index . 1 }} +{{- if not $data -}} +null +{{ end }} +{{- range $k, $v := $data }} +{{- if not (kindIs "string" $v) }} +{{- $v = toYaml $v }} +{{- end }} +{{- tpl (toYaml (dict $k $v)) $root }} +{{ end }} +{{- end }} diff --git a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-confd-files.yaml b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-confd-files.yaml index 59402ed51..5e737e5d8 100644 --- a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-confd-files.yaml +++ b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-confd-files.yaml @@ -10,4 +10,4 @@ metadata: name: {{ printf "%s-confd-files" (include "altinity-clickhouse-operator.fullname" .) }} namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} -data: {{ tpl (toYaml .Values.configs.confdFiles) . | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.confdFiles) | nindent 2 }} diff --git a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-configd-files.yaml b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-configd-files.yaml index b2ccdad10..2a4615eb3 100644 --- a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-configd-files.yaml +++ b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-configd-files.yaml @@ -10,4 +10,4 @@ metadata: name: {{ printf "%s-configd-files" (include "altinity-clickhouse-operator.fullname" .) }} namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} -data: {{ tpl (toYaml .Values.configs.configdFiles) . | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.configdFiles) | nindent 2 }} diff --git a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml index b8f3491dd..49a71235d 100644 --- a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml +++ b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-files.yaml @@ -10,4 +10,4 @@ metadata: name: {{ printf "%s-files" (include "altinity-clickhouse-operator.fullname" .) }} namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} -data: {{ tpl (toYaml .Values.configs.files) . | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.files) | nindent 2 }} diff --git a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-templatesd-files.yaml b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-templatesd-files.yaml index 20b81d51f..ba41cd85f 100644 --- a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-templatesd-files.yaml +++ b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-templatesd-files.yaml @@ -10,4 +10,4 @@ metadata: name: {{ printf "%s-templatesd-files" (include "altinity-clickhouse-operator.fullname" .) }} namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} -data: {{ tpl (toYaml .Values.configs.templatesdFiles) . | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.templatesdFiles) | nindent 2 }} diff --git a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-usersd-files.yaml b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-usersd-files.yaml index fb5928d96..42d44037d 100644 --- a/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-usersd-files.yaml +++ b/deploy/helm/templates/generated/ConfigMap-etc-clickhouse-operator-usersd-files.yaml @@ -10,4 +10,4 @@ metadata: name: {{ printf "%s-usersd-files" (include "altinity-clickhouse-operator.fullname" .) }} namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} -data: {{ tpl (toYaml .Values.configs.usersdFiles) . | nindent 2 }} +data: {{ include "altinity-clickhouse-operator.configmap-data" (list . .Values.configs.usersdFiles) | nindent 2 }} diff --git a/deploy/helm/templates/generated/ServiceAccount-clickhouse-operator.yaml b/deploy/helm/templates/generated/ServiceAccount-clickhouse-operator.yaml index 3bc8d89af..803619f97 100644 --- a/deploy/helm/templates/generated/ServiceAccount-clickhouse-operator.yaml +++ b/deploy/helm/templates/generated/ServiceAccount-clickhouse-operator.yaml @@ -13,7 +13,6 @@ metadata: namespace: {{ .Release.Namespace }} labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }} annotations: {{ toYaml .Values.serviceAccount.annotations | nindent 4 }} - # Template Parameters: # # NAMESPACE=kube-system diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml index 4a97e2da9..4f8736753 100644 --- a/deploy/helm/values.yaml +++ b/deploy/helm/values.yaml @@ -169,7 +169,7 @@ configs: files: - config.yaml: |- + config.yaml: # IMPORTANT # This file is auto-generated # Do not edit this file - all changes would be lost @@ -196,7 +196,6 @@ configs: # Regexp is applicable. #namespaces: ["dev", "test"] namespaces: [] - clickhouse: configuration: ################################################ @@ -254,7 +253,6 @@ configs: network: # Default host_regexp to limit network connectivity from outside hostRegexpTemplate: "(chi-{chi}-[^.]+\\d+-\\d+|clickhouse\\-{chi})\\.{namespace}\\.svc\\.cluster\\.local$" - ################################################ ## ## Configuration restart policy section @@ -279,19 +277,15 @@ configs: - settings/max_concurrent_queries: "no" - settings/models_config: "no" - settings/user_defined_executable_functions_config: "no" - - zookeeper/*: "yes" - - files/*.xml: "yes" - files/config.d/*.xml: "yes" - files/config.d/*dict*.xml: "no" - - profiles/default/background_*_pool_size: "yes" - profiles/default/max_*_for_server: "yes" - version: "21.*" rules: - settings/logger: "yes" - ################################################# ## ## Access to ClickHouse instances @@ -313,7 +307,6 @@ configs: username: "" password: "" rootCA: "" - # Location of the k8s Secret with username and password to be used by the operator to connect to ClickHouse instances. # Can be used instead of explicitly specified username and password available in sections: # - clickhouse.access.username @@ -325,10 +318,9 @@ configs: # Empty `namespace` means that k8s secret would be looked in the same namespace where operator's pod is running. namespace: "" # Empty `name` means no k8s Secret would be looked for - name: "{{ include "altinity-clickhouse-operator.fullname" . }}" + name: '{{ include "altinity-clickhouse-operator.fullname" . }}' # Port where to connect to ClickHouse instances to port: 8123 - # Timeouts used to limit connection and queries from the operator to ClickHouse instances # Specified in seconds. timeouts: @@ -336,13 +328,11 @@ configs: connect: 1 # Timout to perform SQL query from the operator to ClickHouse instances. In seconds. query: 4 - ################################################# ## ## Metrics collection ## ################################################ - metrics: # Timeouts used to limit connection and queries from the metrics exporter to ClickHouse instances # Specified in seconds. @@ -351,7 +341,6 @@ configs: # Upon reaching this timeout metrics collection is aborted and no more metrics are collected in this cycle. # All collected metrics are returned. collect: 9 - ################################################ ## ## Template(s) management section @@ -364,12 +353,10 @@ configs: # - ReadOnStart. Accept CHIT updates on the operators start only. # - ApplyOnNextReconcile. Accept CHIT updates at all time. Apply news CHITs on next regular reconcile of the CHI policy: ApplyOnNextReconcile - # Path to the folder where ClickHouseInstallation templates .yaml manifests are located. # Templates are added to the list of all templates and used when CHI is reconciled. # Templates are applied in sorted alpha-numeric order. path: templates.d - ################################################ ## ## Reconcile section @@ -380,7 +367,6 @@ configs: runtime: # Max number of concurrent CHI reconciles in progress reconcileCHIsThreadsNumber: 10 - # The operator reconciles shards concurrently in each CHI with the following limitations: # 1. Number of shards being reconciled (and thus having hosts down) in each CHI concurrently # can not be greater than 'reconcileShardsThreadsNumber'. @@ -393,7 +379,6 @@ configs: reconcileShardsThreadsNumber: 5 # Max percentage of concurrent shard reconciles within one CHI in progress reconcileShardsMaxConcurrencyPercent: 50 - # Reconcile StatefulSet scenario statefulSet: # Create StatefulSet scenario @@ -406,7 +391,6 @@ configs: # 2. delete - delete newly created problematic StatefulSet and follow 'abort' path afterwards. # 3. ignore - ignore an error, pretend nothing happened, continue reconcile and move on to the next StatefulSet. onFailure: ignore - # Update StatefulSet scenario update: # How many seconds to wait for created/updated StatefulSet to be 'Ready' @@ -423,7 +407,6 @@ configs: # Follow 'abort' path afterwards. # 3. ignore - ignore an error, pretend nothing happened, continue reconcile and move on to the next StatefulSet. onFailure: abort - # Reconcile Host scenario host: # Whether the operator during reconcile procedure should wait for a ClickHouse host: @@ -435,7 +418,6 @@ configs: exclude: true queries: true include: false - ################################################ ## ## Annotations management section @@ -450,7 +432,6 @@ configs: include: [] # Exclude annotations from the following list: exclude: [] - ################################################ ## ## Labels management section @@ -479,7 +460,6 @@ configs: # LabelClusterScopeCycleIndex # LabelClusterScopeCycleOffset appendScope: "no" - ################################################ ## ## StatefulSet management section @@ -487,7 +467,6 @@ configs: ################################################ statefulSet: revisionHistoryLimit: 0 - ################################################ ## ## Pod management section @@ -499,7 +478,6 @@ configs: # SIGTERM and SIGKILL during Pod termination process. # Increase this number is case of slow shutdown. terminationGracePeriod: 30 - ################################################ ## ## Log parameters section diff --git a/dev/generate_helm_chart.sh b/dev/generate_helm_chart.sh index 02966fd86..309ee2e60 100755 --- a/dev/generate_helm_chart.sh +++ b/dev/generate_helm_chart.sh @@ -229,8 +229,12 @@ function update_configmap_resource() { data=$(yq e '.data' "${file}") if [ "${name}" = "etc-clickhouse-operator-files" ]; then - readonly search='name: "clickhouse-operator"' - readonly replace='name: "{{ include "altinity-clickhouse-operator.fullname" . }}"' + local search='name: "clickhouse-operator"' + local replace="name: '{{ include \"altinity-clickhouse-operator.fullname\" . }}'" + data=${data/"${search}"/"${replace}"} + + search='config.yaml: |' + replace='config.yaml:' data=${data/"${search}"/"${replace}"} fi @@ -241,7 +245,7 @@ function update_configmap_resource() { yq e -i '.metadata.name |= "{{ printf \"%s-'"${name_suffix}"'\" (include \"altinity-clickhouse-operator.fullname\" .) }}"' "${file}" yq e -i '.metadata.namespace |= "{{ .Release.Namespace }}"' "${file}" yq e -i '.metadata.labels |= "{{ include \"altinity-clickhouse-operator.labels\" . | nindent 4 }}"' "${file}" - yq e -i '.data |= "{{ tpl (toYaml .Values.configs.'"${cameled_name}"') . | nindent 2 }}"' "${file}" + yq e -i '.data |= "{{ include \"altinity-clickhouse-operator.configmap-data\" (list . .Values.configs.'"${cameled_name}"') | nindent 2 }}"' "${file}" if [ -z "${data}" ]; then yq e -i '.configs.'"${cameled_name}"' |= null' "${values_yaml}"