I have simple helm chart. I have a labels:
block that I need to refer in a Deployment
Here's my 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. 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 }}
, where I can see the accountmasterdata.labels
values? And how to override those?
Thank you!
Iterating over a mapping is covered in the " Variables " documentation:
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:
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:
labels:
{{- range $name, $value := .Values.labels }}
{{ $name | quote }}: {{ $value | quote }}
{{- end -}}
And in the line where it says {{- include "accountmasterdata.labels". | nindent 4 }}, where I can see the accountmasterdata.labels values? 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:
{{- 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:
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 }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.