Skip to content

Commit

Permalink
fix(kubernetes platform): Implement improvements to the Pod recreatio…
Browse files Browse the repository at this point in the history
…n on Helm release upgrades (#5525)

* Add podRollmeAnnotation option

Signed-off-by: MOZGIII <[email protected]>

* Correct the comments at labels

Signed-off-by: MOZGIII <[email protected]>

* Generate the Kubernetes YAMLs

Signed-off-by: MOZGIII <[email protected]>

* Extract the configTemplateChecksumAnnotation to shared templates

Signed-off-by: MOZGIII <[email protected]>

* Update the generated Kubernetes YAMLs

Signed-off-by: MOZGIII <[email protected]>

* Correct the global default assignment logic at libvector.rollmeAnnotation

Signed-off-by: MOZGIII <[email protected]>

* Add the values checksum annotation

Signed-off-by: MOZGIII <[email protected]>

* Update the generated Kubernetes YAMLs

Signed-off-by: MOZGIII <[email protected]>

* Aggregate all of the reroll related annotations into libvector.rerollAnnotations

Signed-off-by: MOZGIII <[email protected]>

* Update the generated Kubernetes YAMLs

Signed-off-by: MOZGIII <[email protected]>

* Evaluate the config for sha256sum calculation

Signed-off-by: MOZGIII <[email protected]>

* Disable podValuesChecksumAnnotation by default

Signed-off-by: MOZGIII <[email protected]>

* Update the generated Kubernetes YAMLs

Signed-off-by: MOZGIII <[email protected]>
  • Loading branch information
MOZGIII authored Dec 16, 2020
1 parent a3a5fb2 commit 1713011
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 12 deletions.
4 changes: 1 addition & 3 deletions distribution/helm/vector-agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ spec:
template:
metadata:
annotations:
{{- if not .Values.externalConfigMap }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}
{{- include "libvector.rerollAnnotations" . | nindent 8 }}
{{- include "libvector.metricsPrometheusPodAnnotations" . | nindent 8 }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
Expand Down
12 changes: 12 additions & 0 deletions distribution/helm/vector-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ serviceAccount:
# template.
name: ""

# Add an annotation to the `Pod`s managed by `DaemonSet` with a random value,
# generated at Helm Chart template evaluation time.
# Enabling this will cause the `Pod`s to be recreated every time the value
# changes - effectively restarting them on each update.
podRollmeAnnotation: false

# Add an annotation to the `Pod`s managed by `DaemonSet` with a checksum of
# the Helm release values (as in `values.yaml` content and `--set` flags).
# Enabling this will cause the `Pod`s to be recreated every time values
# change.
podValuesChecksumAnnotation: false

# Annotations to add to the `Pod`s managed by `DaemonSet`.
podAnnotations: {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ spec:
template:
metadata:
annotations:
{{- if not .Values.externalConfigMap }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}
{{- include "libvector.rerollAnnotations" . | nindent 8 }}
{{- include "libvector.metricsPrometheusPodAnnotations" . | nindent 8 }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
Expand Down
12 changes: 12 additions & 0 deletions distribution/helm/vector-aggregator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ serviceAccount:
# template.
name: ""

# Add an annotation to the `Pod`s managed by `StatefulSet` with a random value,
# generated at Helm Chart template evaluation time.
# Enabling this will cause the `Pod`s to be recreated every time the value
# changes - effectively restarting them on each update.
podRollmeAnnotation: false

# Add an annotation to the `Pod`s managed by `StatefulSet` with a checksum of
# the Helm release values (as in `values.yaml` content and `--set` flags).
# Enabling this will cause the `Pod`s to be recreated every time values
# change.
podValuesChecksumAnnotation: false

# Annotations to add to the `Pod`s managed by `StatefulSet`.
podAnnotations: {}

Expand Down
5 changes: 3 additions & 2 deletions distribution/helm/vector-shared/templates/_labels.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Common labels
Common labels.
*/}}
{{- define "libvector.labels" -}}
helm.sh/chart: {{ include "libvector.chart" . }}
Expand All @@ -12,7 +13,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
Selector labels.
*/}}
{{- define "libvector.selectorLabels" -}}
app.kubernetes.io/name: {{ include "libvector.name" . }}
Expand Down
49 changes: 49 additions & 0 deletions distribution/helm/vector-shared/templates/_reroll.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Rollme annotation.
*/}}
{{- define "libvector.rollmeAnnotation" -}}
{{- $global := default (dict) .Values.global }}
{{- $global := default (dict) $global.vector }}
{{- $enabled := .Values.podRollmeAnnotation }}
{{- if hasKey $global "podRollmeAnnotation" }}
{{- $enabled = $global.podRollmeAnnotation }}
{{- end }}
{{- if $enabled }}
rollme: {{ randAlphaNum 5 | quote }}
{{- end }}
{{- end }}

{{/*
`ConfigMap` template checksum annotation.
*/}}
{{- define "libvector.configTemplateChecksumAnnotation" -}}
{{- if not .Values.externalConfigMap }}
checksum/config: {{ tpl (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}
{{- end }}

{{/*
Values checksum annotation.
*/}}
{{- define "libvector.valuesChecksumAnnotation" -}}
{{- $global := default (dict) .Values.global }}
{{- $global := default (dict) $global.vector }}
{{- $enabled := .Values.podValuesChecksumAnnotation }}
{{- if hasKey $global "podValuesChecksumAnnotation" }}
{{- $enabled = $global.podValuesChecksumAnnotation }}
{{- end }}
{{- if $enabled }}
checksum/values: {{ toJson .Values | sha256sum }}
{{- end }}
{{- end }}

{{/*
All reroll annotations.
*/}}
{{- define "libvector.rerollAnnotations" -}}
{{- include "libvector.configTemplateChecksumAnnotation" . }}
{{- include "libvector.valuesChecksumAnnotation" . }}
{{- include "libvector.rollmeAnnotation" . }}
{{- end }}
10 changes: 10 additions & 0 deletions distribution/helm/vector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
# # Sets common environment variables for use in all `Pod`s.
# commonEnvKV:
# LOG: info
# # Add an annotation with a random value generated at Helm Chart template
# # evaluation time to the managed `Pod`s.
# # Enabling this will cause the `Pod`s to be recreated every time the value
# # changes - effectively restarting them on each update.
# podRollmeAnnotation: true
# # Add an annotation with a checksum of the Helm release values (as
# in `values.yaml` content and `--set` flags).
# # Enabling this will cause the `Pod`s to be recreated every time values
# # change.
# podValuesChecksumAnnotation: true

vector-agent:
# See the possible settings at the `vector-agent` chart.
Expand Down
3 changes: 2 additions & 1 deletion distribution/kubernetes/vector-agent/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ spec:
template:
metadata:
annotations:
checksum/config: 3dac4d3f040851abd23fb5bf6d48a5babbd001e35aaa5465fa23e45816918c14

checksum/config: 75958f6034a2d836d57468a572df3af05ea5d4eaf4b8b5cbd6371e6ec319a696

labels:
app.kubernetes.io/name: vector-agent
Expand Down
3 changes: 2 additions & 1 deletion distribution/kubernetes/vector-aggregator/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ spec:
template:
metadata:
annotations:
checksum/config: f21e03060de6e60eeda4b7d6cbc3121890b76a4b3618f30fded3a8a4eb226c24

checksum/config: 2e32b2eca9854ebc0d3877ff9cb719ac16698a6e976a05151945729a41eb058d

labels:
app.kubernetes.io/name: vector-aggregator
Expand Down
6 changes: 4 additions & 2 deletions distribution/kubernetes/vector-all/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ spec:
template:
metadata:
annotations:
checksum/config: 4f9264d4d898bb5c5b1070e48a32fc42a233596993e7b9622cc673bd42df9466

checksum/config: fa3deb906e02ab211d86aa37249d2f7d73dce9e771d68ed0679c7a0cab9eb54c

labels:
app.kubernetes.io/name: vector-agent
Expand Down Expand Up @@ -323,7 +324,8 @@ spec:
template:
metadata:
annotations:
checksum/config: f21e03060de6e60eeda4b7d6cbc3121890b76a4b3618f30fded3a8a4eb226c24

checksum/config: a67c40b917e758700bf0df9b0719a84da8ee3828ec3a5d651baf78dcb02fb68a

labels:
app.kubernetes.io/name: vector-aggregator
Expand Down

0 comments on commit 1713011

Please sign in to comment.