掌舵模板:如何将模板的结果分配给变量
helm template: how do i assign the result of a template to a variable
我正在尝试做类似的事情:
{{- $cassandrafullname := template "cassandra.fullname" . -}}
但我在干 运行:
时收到此错误
Error: UPGRADE FAILED: parse error in "cassandra/templates/service.yaml": template: cassandra/templates/service.yaml:1: unexpected <template> in command
我遇到这个问题的原因是因为我无法在范围内使用 template cassandra.fullname
,所以我试图将值放入变量中并在范围内使用它。因此,如果有解决方案,也将被接受!
Helm defines an include
function 与标准 template
相同,除了它 returns 渲染输出而不是输出它。你应该可以写
{{- $cassandrafullname := include "cassandra.fullname" . -}}
不幸的是,这不适用于 fromYaml
,因此您无法像往常一样将 yaml 结构读入管道操作。一个比较大的缺点。很多时候我需要将一个列表过滤到另一个列表中,但这对 helm 来说似乎是不可能的:
{{- define "sometpl" -}}
- bla: dibla
- oki: doki
{{- end -}}
---
{{- $v := include "sometpl" . | fromYaml }}
some: {{- $v | toYaml | nindent 2 }}
会给予
some:
Error: 'error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array
into Go value of type map[string]interface {}'
我正在尝试做类似的事情:
{{- $cassandrafullname := template "cassandra.fullname" . -}}
但我在干 运行:
时收到此错误Error: UPGRADE FAILED: parse error in "cassandra/templates/service.yaml": template: cassandra/templates/service.yaml:1: unexpected <template> in command
我遇到这个问题的原因是因为我无法在范围内使用 template cassandra.fullname
,所以我试图将值放入变量中并在范围内使用它。因此,如果有解决方案,也将被接受!
Helm defines an include
function 与标准 template
相同,除了它 returns 渲染输出而不是输出它。你应该可以写
{{- $cassandrafullname := include "cassandra.fullname" . -}}
不幸的是,这不适用于 fromYaml
,因此您无法像往常一样将 yaml 结构读入管道操作。一个比较大的缺点。很多时候我需要将一个列表过滤到另一个列表中,但这对 helm 来说似乎是不可能的:
{{- define "sometpl" -}}
- bla: dibla
- oki: doki
{{- end -}}
---
{{- $v := include "sometpl" . | fromYaml }}
some: {{- $v | toYaml | nindent 2 }}
会给予
some:
Error: 'error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array
into Go value of type map[string]interface {}'