使用 Helmfile 模板值文件并获得 "error during tpl function execution"
Templating value file using Helmfile and got "error during tpl function execution"
我正在使用 helmfile
安装我的 Helm 图表和其他依赖图表。
我想在值文件中使用模板值。
从 this 已解决的问题来看,似乎支持值文件中的模板。但是,我使用以下文件进行了测试:
helmfile.yaml
:
environments:
default:
values:
- my:
port: 8080
---
repositories:
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
namespace: haproxy-ingress
chart: incubator/haproxy-ingress
version: 0.0.27
values:
- values.yaml
values.yaml
:
controller:
tcp:
1936: "my_namespace/my-service:{{ .Values.my.port }}"
如果我 运行 helmfile template
,我会得到
COMBINED OUTPUT:
Error: template: haproxy-ingress/templates/tcp-configmap.yaml:16:31: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <tpl $value $>: error calling tpl: error during tpl function execution for "my_namespace/my-service:{{ .Values.my.port }}": template: haproxy-ingress/templates/tcp-configmap.yaml:1:34: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <.Values.my.port>: nil pointer evaluating interface {}.port
Use --debug flag to render out invalid YAML
如果我内联这些值,它会起作用
environments:
default:
values:
- my:
port: 8080
---
repositories:
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
namespace: haproxy-ingress
chart: incubator/haproxy-ingress
version: 0.0.27
values:
- controller:
tcp:
1936: "my_namespace/my-service:{{ .Values.my.port }}"
我得到了答案。来自 helmfile 的文档,
You can use go's text/template expressions in helmfile.yaml and values.yaml.gotmpl (templated helm values files). values.yaml references will be used verbatim.
In other words:
for value files ending with .gotmpl, template expressions will be rendered
for plain value files (ending in .yaml), content will be used as-is
因此,对于这种情况,values.yaml
应该重命名为 values.yaml.gotmpl
以便 helmfile 将文件解释为 go 模板。
我正在使用 helmfile
安装我的 Helm 图表和其他依赖图表。
我想在值文件中使用模板值。
从 this 已解决的问题来看,似乎支持值文件中的模板。但是,我使用以下文件进行了测试:
helmfile.yaml
:
environments:
default:
values:
- my:
port: 8080
---
repositories:
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
namespace: haproxy-ingress
chart: incubator/haproxy-ingress
version: 0.0.27
values:
- values.yaml
values.yaml
:
controller:
tcp:
1936: "my_namespace/my-service:{{ .Values.my.port }}"
如果我 运行 helmfile template
,我会得到
COMBINED OUTPUT:
Error: template: haproxy-ingress/templates/tcp-configmap.yaml:16:31: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <tpl $value $>: error calling tpl: error during tpl function execution for "my_namespace/my-service:{{ .Values.my.port }}": template: haproxy-ingress/templates/tcp-configmap.yaml:1:34: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <.Values.my.port>: nil pointer evaluating interface {}.port
Use --debug flag to render out invalid YAML
如果我内联这些值,它会起作用
environments:
default:
values:
- my:
port: 8080
---
repositories:
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
namespace: haproxy-ingress
chart: incubator/haproxy-ingress
version: 0.0.27
values:
- controller:
tcp:
1936: "my_namespace/my-service:{{ .Values.my.port }}"
我得到了答案。来自 helmfile 的文档,
You can use go's text/template expressions in helmfile.yaml and values.yaml.gotmpl (templated helm values files). values.yaml references will be used verbatim. In other words: for value files ending with .gotmpl, template expressions will be rendered for plain value files (ending in .yaml), content will be used as-is
因此,对于这种情况,values.yaml
应该重命名为 values.yaml.gotmpl
以便 helmfile 将文件解释为 go 模板。