From 7cebaa169778edb1806297b163eededee5d299d7 Mon Sep 17 00:00:00 2001 From: Kai Burjack Date: Thu, 28 Nov 2024 13:02:50 +0100 Subject: [PATCH] feat: compute ConfigMap checksum only over .data content --- production/helm/loki/templates/_helpers.tpl | 12 +++++++++++- .../templates/admin-api/deployment-admin-api.yaml | 2 +- .../loki/templates/backend/statefulset-backend.yaml | 2 +- .../gateway/deployment-gateway-enterprise.yaml | 2 +- .../templates/gateway/deployment-gateway-nginx.yaml | 2 +- .../helm/loki/templates/read/deployment-read.yaml | 2 +- .../helm/loki/templates/read/statefulset-read.yaml | 2 +- .../loki/templates/single-binary/statefulset.yaml | 2 +- .../table-manager/deployment-table-manager.yaml | 2 +- .../helm/loki/templates/write/statefulset-write.yaml | 2 +- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/production/helm/loki/templates/_helpers.tpl b/production/helm/loki/templates/_helpers.tpl index 29fdc3aa12747..acc66905ddc23 100644 --- a/production/helm/loki/templates/_helpers.tpl +++ b/production/helm/loki/templates/_helpers.tpl @@ -1083,7 +1083,7 @@ enableServiceLinks: false {{- end }} {{- define "loki.config.checksum" -}} -checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} +checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- end -}} {{/* @@ -1120,3 +1120,13 @@ Return the appropriate apiVersion for HorizontalPodAutoscaler. {{- print "autoscaling/v2beta1" -}} {{- end -}} {{- end -}} + +{{/* +compute a ConfigMap or Secret checksum only based on its .data content. +This function needs to be called with a context object containing the following keys: +- ctx: the current Helm context (what '.' is at the call site) +- name: the file name of the ConfigMap or Secret +*/}} +{{- define "loki.configMapOrSecretContentHash" -}} +{{ get (include (print .ctx.Template.BasePath .name) .ctx | fromYaml) "data" | toYaml | sha256sum }} +{{- end }} diff --git a/production/helm/loki/templates/admin-api/deployment-admin-api.yaml b/production/helm/loki/templates/admin-api/deployment-admin-api.yaml index 2d356882204b6..c5e97dd004c0a 100644 --- a/production/helm/loki/templates/admin-api/deployment-admin-api.yaml +++ b/production/helm/loki/templates/admin-api/deployment-admin-api.yaml @@ -32,7 +32,7 @@ spec: {{- if .Values.useExternalConfig }} checksum/config: {{ .Values.externalConfigVersion }} {{- else }} - checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- end}} {{- with .Values.adminApi.annotations }} {{- toYaml . | nindent 8 }} diff --git a/production/helm/loki/templates/backend/statefulset-backend.yaml b/production/helm/loki/templates/backend/statefulset-backend.yaml index c20ce9f9a0552..bf2e18da80b4a 100644 --- a/production/helm/loki/templates/backend/statefulset-backend.yaml +++ b/production/helm/loki/templates/backend/statefulset-backend.yaml @@ -47,7 +47,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/gateway/deployment-gateway-enterprise.yaml b/production/helm/loki/templates/gateway/deployment-gateway-enterprise.yaml index eb089a1a60cfd..22bf5c1fd6183 100644 --- a/production/helm/loki/templates/gateway/deployment-gateway-enterprise.yaml +++ b/production/helm/loki/templates/gateway/deployment-gateway-enterprise.yaml @@ -32,7 +32,7 @@ spec: {{- if .Values.useExternalConfig }} checksum/config: {{ .Values.externalConfigVersion }} {{- else }} - checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- end}} {{- with .Values.enterpriseGateway.annotations }} {{- toYaml . | nindent 8 }} diff --git a/production/helm/loki/templates/gateway/deployment-gateway-nginx.yaml b/production/helm/loki/templates/gateway/deployment-gateway-nginx.yaml index 2b2d4c7bd7bb7..94562ad165c97 100644 --- a/production/helm/loki/templates/gateway/deployment-gateway-nginx.yaml +++ b/production/helm/loki/templates/gateway/deployment-gateway-nginx.yaml @@ -30,7 +30,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/gateway/configmap-gateway.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/gateway/configmap-gateway.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/read/deployment-read.yaml b/production/helm/loki/templates/read/deployment-read.yaml index 245119cb44dca..f024a40fc6d5f 100644 --- a/production/helm/loki/templates/read/deployment-read.yaml +++ b/production/helm/loki/templates/read/deployment-read.yaml @@ -33,7 +33,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/read/statefulset-read.yaml b/production/helm/loki/templates/read/statefulset-read.yaml index 9d4213b174588..93527f9d616da 100644 --- a/production/helm/loki/templates/read/statefulset-read.yaml +++ b/production/helm/loki/templates/read/statefulset-read.yaml @@ -47,7 +47,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/single-binary/statefulset.yaml b/production/helm/loki/templates/single-binary/statefulset.yaml index 4acd406b9cfa5..54f3d925404db 100644 --- a/production/helm/loki/templates/single-binary/statefulset.yaml +++ b/production/helm/loki/templates/single-binary/statefulset.yaml @@ -41,7 +41,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/table-manager/deployment-table-manager.yaml b/production/helm/loki/templates/table-manager/deployment-table-manager.yaml index e3f6d0d94a696..770629be95bd2 100644 --- a/production/helm/loki/templates/table-manager/deployment-table-manager.yaml +++ b/production/helm/loki/templates/table-manager/deployment-table-manager.yaml @@ -21,7 +21,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/production/helm/loki/templates/write/statefulset-write.yaml b/production/helm/loki/templates/write/statefulset-write.yaml index 4d6183b291c13..fc3b301354db8 100644 --- a/production/helm/loki/templates/write/statefulset-write.yaml +++ b/production/helm/loki/templates/write/statefulset-write.yaml @@ -47,7 +47,7 @@ spec: template: metadata: annotations: - checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} + checksum/config: {{ include "loki.configMapOrSecretContentHash" (dict "ctx" . "name" "/config.yaml") }} {{- with .Values.loki.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }}