我有一个configmap文件,定义如下
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-dashboard-cm-conf
namespace: {{ .Release.Namespace }}
data:
{{ (tpl (.Files.Glob "conf/*").AsConfig . ) | indent 2 }}正如您在上面看到的,它正在将"conf“文件夹的内容作为数据处理。但是,当我试图实现“注释”以触发"POD-restart“时,所有的问题都会被观察到,我的”部署文件“中有下面的行。
annotations:
checksum/config-map: {{ include (print .Template.BasePath "/dashboard-conf-map.yaml") . | sha256sum }}POD没有重新启动,即使更改了"conf“文件夹的内容&执行"helm升级”。
如果我使用一个简单的configmap,其数据定义如下,那么参数的更改和"helm升级“就会导致POD重新启动。
data:
parameter1: testparam1
parameter2: testparam2我在这里有以下问题
中所示
find dashboard/conf/ -type f -exec md5sum {} \; |md5sum
annotations:
checksum: {{ include (print .Template.BasePath "/logback-spring.xml") . | sha256sum }}我得到以下错误: YAML解析chart-2/charts/dashboar/templates/conf1/logback-spring.xml:错误--解封送处理JSON:同时解码JSON: json:无法将字符串解组为releaseutil.SimpleHead类型的Go值
checksum/config: {{ include (print .BasePath "../conf/values1.yaml") . | sha256sum }}
checksum/config: {{ include (print .Template.BasePath "/../../conf/values1.yaml") . | sha256sum }}
checksum/config: {{ include (print .Template.BasePath "/../conf/values1.yaml") . | sha256sum }} 错误调用包括:模板:没有与模板"gotpl“关联的模板"chart-2/charts/dashboard/templates../conf/values1.yaml”
错误调用包括:模板:没有与模板"gotpl“关联的模板"chart-2/charts/dashboard/templates/../conf/values1.yaml”
错误调用包括:模板:没有与模板"gotpl“关联的模板"chart-2/charts/dashboard/templates/../../conf/values1.yaml”
发布于 2020-12-12 12:45:17
include template function是一个Helm扩展,它执行一个命名的模板,就像标准的template指令一样,但将模板的内容作为字符串返回。它与读取文件无关。
要读取回文件,您需要使用top-level .Files object。这特别附带了一个警告,即它不能读取图表的templates目录中的文件;用.Template.BasePath作为文件名的前缀将不起作用,您需要将包含的文件移到其他地方。
假设您确实在主图表目录中创建了一个子目录conf:
Chart.yaml
values.yaml
conf/
logback.xml
templates/
configmap.yaml这里列出的许多函数-- .Files.Get、.Files.Glob.AsConfig、tpl --返回字符串,这样就可以将它们组合在一起。例如,您可以计算ConfigMap呈现的内容的校验和如下:
annotations:
checksum/config-map: {{ (tpl (.Files.Glob "conf/*").AsConfig . ) | sha256sum }}如果需要,您也可以在单个非YAML文件上执行此操作:.Files.Get返回一个字符串,因此
.Files.Get "conf/logback-spring.xml" | sha256sum.Files.Get的根路径是图表的根。您可以检索不在templates目录中的任何文件,但无法到达图表之外。
发布于 2022-08-25 15:09:49
如果你想用子图来做这件事。
kind: <ResourceKind> # Deployment, StatefulSet, etc
spec:
template:
metadata:
annotations:
checksum/config: {{ include ("mylibchart.configmap") . | sha256sum }}另一个选择是https://github.com/stakater/Reloader
您可以使用regex根据这个PR https://github.com/stakater/Reloader/pull/314选择配置。
https://stackoverflow.com/questions/65257220
复制相似问题