helm trigger pod restart on parent-chart configmap change

helm trigger pod restart on parent-chart configmap change

我面临的问题是我们使用伞舵图来部署我们的服务,但我们的服务包含在子图中。但是有一些全局配置映射被多个服务使用,它们是由伞形图部署的。所以简化的结构如下所示:

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

我需要的是将 global-config.yaml 的校验和放入 deployment1.yamldeployment2.yaml 作为注释,如 https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments

问题是我可以在伞形图中定义这样的模板:

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

然后在部署 yaml 中使用 {{ include "configmap.checksum" . }},因为模板是全局的。但是 $.Template.BasePath 在包含发生时被解析,所以它实际上指向包含它的子图的模板目录。我玩过“..”和文件。并在模板和包含中传递另一个上下文,例如传递全局上下文 $ 但其中 none 是成功的,因为我总是在渲染时锁定在特定子图中。

是否有解决此问题的方法或其他方法?或者这是无法在掌舵下完成的事情?但我很感激任何解决方案

我找到了一个变通方法,它要求您将全局 ConfigMap 的内容重构到伞形图中的模板中。您将无法在 ConfigMap 中使用伞形图中的常规值,否则在尝试在子图中呈现模板时会出现错误;您将不得不使用全局值。

{{/*
Create the contents of the global-config ConfigMap
*/}}
{{- define "my-umbrella-chart.global-config-contents" -}}
spring.activemq.user={{ .Values.global.activeMqUsername | quote }}
spring.activemq.password={{ .Values.global.activeMqPassword | quote }}
jms.destinations.itemCreationQueue={{ .Release.Namespace }}-itemCreationQueue
{{- end }}
kind: ConfigMap
apiVersion: v1
metadata:
  name: global-config
data:
  {{- include "my-umbrella-chart.global-config-contents" . | nindent 2 }}

然后在 deployment1.yamldeployment2.yaml 中添加 my-umbrella-chart.global-config-contents 的校验和作为注释,如下所示:

annotations:
  # Automatically roll deployment when the configmap contents changes
  checksum/global-config: {{ include "my-umbrella-chart.global-config-contents" . | sha256sum }}