Interview Prep/Helm/Templating: Go Templates & Sprig

How do you add a checksum annotation so pods restart when a ConfigMap changes?

IntermediateConceptTemplating: Go Templates & Sprig
Answer

Changing a ConfigMap does not restart pods that consume it via envFrom or files mounted as env. Hash the rendered ConfigMap into the pod template so any change alters the template and triggers a rollout:

spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/frontend-configmap.yaml") . | sha256sum }}

Use the same trick for Secrets the chart renders. Do not hash an externally managed Secret this way; it is not in the chart.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig