fix(chart): Fix gitops-incompatible random rolling (#20184)

This patch reworks the Pod rolling mechanism, which is supposed to update Pods
with each migration run, but since the it generates a new random value on each
helm execution, this will constantly roll all pods in a GitOps driven deployment,
which reconciles the helm release.

This is resolved by fixing the upgrade to the `.Release.Revision`, which should
stay identical, unless config or helm release version have been changed. Further
it introduces automatic rolls based on adjustments to the environment variables
and secrets.

The implementation uses a helper template, following the 1-2-N rule, and omitting
code duplication.

References:
https://helm.sh/docs/chart_template_guide/builtin_objects/
https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
lolsob-rspec
Sheogorath 2022-11-10 19:10:38 +01:00 committed by GitHub
parent 677e9fa297
commit c7effae6d4
4 changed files with 19 additions and 8 deletions

View File

@ -51,6 +51,15 @@ app.kubernetes.io/name: {{ include "mastodon.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }} {{- end }}
{{/*
Rolling pod annotations
*/}}
{{- define "mastodon.rollingPodAnnotations" -}}
rollme: {{ .Release.Revision | quote }}
checksum/config-secrets: {{ include ( print $.Template.BasePath "/secrets.yaml" ) . | sha256sum | quote }}
checksum/config-configmap: {{ include ( print $.Template.BasePath "/configmap-env.yaml" ) . | sha256sum | quote }}
{{- end }}
{{/* {{/*
Create the name of the service account to use Create the name of the service account to use
*/}} */}}

View File

@ -16,11 +16,11 @@ spec:
template: template:
metadata: metadata:
annotations: annotations:
{{- with .Values.podAnnotations }} {{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
# roll the pods to pick up any db migrations # roll the pods to pick up any db migrations or other changes
rollme: {{ randAlphaNum 5 | quote }} {{- include "mastodon.rollingPodAnnotations" . | nindent 8 }}
labels: labels:
{{- include "mastodon.selectorLabels" . | nindent 8 }} {{- include "mastodon.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: sidekiq app.kubernetes.io/component: sidekiq

View File

@ -14,10 +14,12 @@ spec:
app.kubernetes.io/component: streaming app.kubernetes.io/component: streaming
template: template:
metadata: metadata:
{{- with .Values.podAnnotations }}
annotations: annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
# roll the pods to pick up any db migrations or other changes
{{- include "mastodon.rollingPodAnnotations" . | nindent 8 }}
labels: labels:
{{- include "mastodon.selectorLabels" . | nindent 8 }} {{- include "mastodon.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: streaming app.kubernetes.io/component: streaming

View File

@ -19,8 +19,8 @@ spec:
{{- with .Values.podAnnotations }} {{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
# roll the pods to pick up any db migrations # roll the pods to pick up any db migrations or other changes
rollme: {{ randAlphaNum 5 | quote }} {{- include "mastodon.rollingPodAnnotations" . | nindent 8 }}
labels: labels:
{{- include "mastodon.selectorLabels" . | nindent 8 }} {{- include "mastodon.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: web app.kubernetes.io/component: web