[英]Pass an entire yaml from values.yaml to templates in helm
I am trying to pass entire set of yamls from values.yaml
in helm to the templates
, so that whatever yaml inputs I pass in the values.yaml section goes in the templates yaml as it is:我正在尝试将 helm 中的
values.yaml
中的整套 yaml 传递给templates
,以便我在 values.yaml 部分中传递的任何 yaml 输入都会按原样进入模板 yaml:
For example:例如:
values.yaml
...
...
metallbConfig: |-
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
creationTimestamp: null
name: peer1
namespace: metallb-system
spec:
holdTime: 3s
keepaliveTime: 0s
myASN: 64026
passwordSecret: {}
peerASN: 65227
peerAddress: 10.252.254.194
status: {}
templates/resources.yaml
: templates/resources.yaml
:
{{ toYaml .Values.metallbConfig }}
Essentially what I want to achieve is whole BGPPeer
section to be present in the resources.yaml
when I deploy the chart.基本上我想要实现的是整个
BGPPeer
部分在我部署图表时出现在resources.yaml
中。
Currently I am getting this error:目前我收到此错误:
# helm template metallbcnf . --output-dir outputs --debug
...
...
Error: YAML parse error on metallb/templates/resources.yaml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead
helm.go:84: [debug] error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead
Kindly help me resolve the same.请帮我解决同样的问题。
values.yaml file contains a string instead of a valid YAML object. You need to convert the string to a YAML object before passing it to the template. values.yaml 文件包含一个字符串,而不是有效的 YAML object。在将字符串传递给模板之前,您需要将该字符串转换为 YAML object。
If you want to embed the yaml entirely, you don't need the |-
如果你想完全嵌入 yaml,你不需要
|-
For example, I have this in values.yaml
例如,我在
values.yaml
中有这个
...
probes:
livenessProbe:
httpGet:
path: /ping
port: 80
initialDelaySeconds: 15
periodSeconds: 60
successThreshold: 1
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /ping
port: 80
initialDelaySeconds: 15
periodSeconds: 60
successThreshold: 1
timeoutSeconds: 5
failureThreshold: 3
...
Then use this in my helm deployment:然后在我的 helm 部署中使用它:
apiVersion: apps/v1
kind: Deployment
...
spec:
...
template:
...
spec:
...
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag}}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- toYaml .Values.probes | nindent 10 }}
...
...
You'll notice I need to be explicit about the indenting using nindent
otherwise helm just pastes in the yaml as in the values.yaml
which breaks the parsing您会注意到我需要明确说明使用
nindent
的缩进,否则 helm 会像 values.yaml 那样粘贴到values.yaml
中,这会破坏解析
Your string is already syntactically correct YAML (hopefully.) and you can just write it out as-is.您的字符串在语法上已经正确 YAML (希望如此。)您可以按原样写出来。
toYaml
will add additional quoting to turn it into specifically a YAML string and you don't want that. toYaml
将添加额外的引号以将其专门转换为 YAML 字符串,而您不希望这样。
---
{{ .Values.metallbConfig }}
{{/* without toYaml */}}
(I'd consider it a little unusual to deposit an entire Kube.netes YAML object in Helm values, especially as an opaque string. Consider moving this into its own file in the templates
directory and using templating only for the specific fields that need to be customized.) (我认为将整个 Kube.netes YAML object 存放在 Helm 值中有点不寻常,尤其是作为不透明字符串。考虑将其移动到
templates
目录中它自己的文件中,并仅对需要的特定字段使用模板可定制。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.