'helm trigger pod restart on parent-chart configmap change

I'm facing the problem that we use an umbrella helm chart to deploy our services but our services are contained in subcharts. But there are some global configmaps that multiple services are using which are deployed by the umbrella chart. So a simplified structure looks like this:

├── Chart.yaml
├── templates
│   ├──  global-config.yaml
├── charts
│   ├── subchart1
│   │   ├── Chart.yaml
│   │   ├──    templates
│   │   │   ├──      deployment1.yaml
│   ├──  subchart2
│   │   ├──    Chart.yaml
│   │   ├──    templates
│   │   │   ├──      deployment2.yaml
 ...

I what I need is to put a checksum of global-config.yaml in deployment1.yaml and deployment2.yaml as annotation like in https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments

The problem is that I can define a template like this in the umbrella chart:

{{- define "configmap.checksum" }}{{ include (print $.Template.BasePath "/global-config.yaml") . | sha256sum }}{{ end }}

and then use {{ include "configmap.checksum" . }} in the deployment yamls as templates are global. But $.Template.BasePath is parsed when the include happens so it actually points to the template directory of the subchart where it is included. I have played around with '..' and the Files. and with passing another context in the template and also in the include like passing the global context $ but none of them were successful as I ways always locked in the specific subchart at rendering time.

Is there a solution to this or a different approach to solve this? Or is this something that cannot be done in helm? But I'm grateful for any solution



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source