首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Helmfile模板值文件并得到“tpl函数执行过程中的错误”

使用Helmfile模板值文件并得到“tpl函数执行过程中的错误”
EN

Stack Overflow用户
提问于 2020-10-03 15:24:59
回答 1查看 3.2K关注 0票数 0

我使用helmfile来安装我的Helm图表和其他依赖关系图。我希望在值文件中使用模板化的值。

解决的问题来看,它看起来像是支持值文件中的模板。但是,我使用以下文件进行了测试:helmfile.yaml

代码语言:javascript
复制
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

代码语言:javascript
复制
controller:
  tcp:
    1936: "my_namespace/my-service:{{ .Values.my.port }}"

如果我运行helmfile template,我会

代码语言:javascript
复制
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

如果我内联这些值,它就能工作。

代码语言:javascript
复制
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 }}"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-08 01:58:57

我知道答案了。从地狱档案的文件来看,

您可以在helmfile.yaml和values.yaml.gotmpl (模板头盔值文件)中使用go的文本/模板表达式。values.yaml引用将逐字使用。换句话说:对于以.gotmpl结尾的值文件,将为普通值文件(以.yaml结尾)呈现模板表达式,内容将按原样使用。

因此,在这种情况下,应该将values.yaml重命名为values.yaml.gotmpl,以便helmfile将文件解释为go模板。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64185839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档