Skip to content

Commit

Permalink
feat: compute ConfigMap checksum only over .data content
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiburjack committed Nov 29, 2024
1 parent abf681d commit 7cebaa1
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 10 deletions.
12 changes: 11 additions & 1 deletion production/helm/loki/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

{{/*
Expand Down Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/templates/read/deployment-read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/templates/read/statefulset-read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 7cebaa1

Please sign in to comment.