[英]Helm - How to add a label block through values.yaml
I have simple helm chart.我有简单的掌舵图。 I have a labels:
block that I need to refer in a Deployment
我有一个labels:
我需要在Deployment
中引用的块
Here's my values.yaml
这是我的values.yaml
labels:
app: test-app
group: test-group
provider: test-provider
And in the templates/deployment.yaml
I need to add the above whole labels
block.在templates/deployment.yaml
中,我需要添加上面的整个labels
块。 So I did;所以我做了;
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ include "accountmasterdata.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{ .Values.labels | nindent 4 }}
{{- include "accountmasterdata.labels" . | nindent 4 }}
But I get the following error但我收到以下错误
wrong type for value;价值类型错误; expected string;预期的字符串; got map[string]interface {}得到地图[字符串]接口{}
Can someone help me with two things:有人可以帮我做两件事:
How can I solve this issue我该如何解决这个问题
And in the line where it says {{- include "accountmasterdata.labels". | nindent 4 }}
在它说{{- include "accountmasterdata.labels". | nindent 4 }}
{{- include "accountmasterdata.labels". | nindent 4 }}
{{- include "accountmasterdata.labels". | nindent 4 }}
, where I can see the accountmasterdata.labels
values? {{- include "accountmasterdata.labels". | nindent 4 }}
,我在哪里可以看到accountmasterdata.labels
值? And how to override those?以及如何覆盖那些?
Thank you!谢谢!
Iterating over a mapping is covered in the " Variables " documentation: “ Variables ”文档中介绍了迭代映射:
For data structures that have both a key and a value, we can use range to get both.对于同时具有键和值的数据结构,我们可以使用范围来获取两者。 For example, we can loop through.Values.favorite like this:例如,我们可以像这样循环 through.Values.favorite:
apiVersion: v1 kind: ConfigMap metadata: name: {{.Release.Name }}-configmap data: myvalue: "Hello World" {{- range $key, $val:=.Values.favorite }} {{ $key }}: {{ $val | quote }} {{- end }}
So in your template, you would handle the value of .Values.labels
like this:因此,在您的模板中,您将像这样处理.Values.labels
的值:
labels:
{{- range $name, $value := .Values.labels }}
{{ $name | quote }}: {{ $value | quote }}
{{- end -}}
And in the line where it says {{- include "accountmasterdata.labels".在它说 {{- include "accountmasterdata.labels" 的行中。 | | nindent 4 }}, where I can see the accountmasterdata.labels values? nindent 4 }},在哪里可以看到 accountmasterdata.labels 值? And how to override those?以及如何覆盖那些?
Is this a template you are writing?这是您正在编写的模板吗? If so, where have you defined these values?如果是这样,您在哪里定义这些值? Presumably in your templates/
directory there exists a file that includes something like:大概在您的templates/
目录中存在一个包含以下内容的文件:
{{- define "accountmasterdata.labels" -}}
...
{{- end -}}
The contents of that block are what will get inserted at the point of reference.该块的内容是将在参考点插入的内容。
Lastly, in your template you have:最后,在您的模板中,您有:
namespace: {{ .Values.namespace }}
But you probably want to use .Release.Namespace
instead:但是您可能想改用.Release.Namespace
:
namespace: {{ .Release.Namespace | quote }}
With the above changes in place, I end up with:完成上述更改后,我最终得到:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ include "accountmasterdata.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- range $name, $value := .Values.labels }}
{{ $name | quote }}: {{ $value | quote }}
{{- end -}}
{{- include "accountmasterdata.labels" . | nindent 4 }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.