Ricky18
Ricky18

Reputation: 45

Helm chart Error can't evaluate field Values in type interface {} at .Values.agent.admin_group

I having hard time looping over array values in values.yaml. The Error some kind of syntax/yaml structure related error but the message is so cryptic I have no idea what the issue is: My values.yaml file:

agent:
 namespace: "" <values are subject to change>
 enabled: true
 admin_group:
   - "TEST_GROUP_1"
   - "TEST_GROUP_2"

my template are:

{{- if .Values.agent.enabled }}
kind: Rolebinding
apiVersion: rbac.authorization.k8s.io/v1
subjects:
  {{- range .Values.agent.admin_group }}
  - kind: group
    apiGroup: rbac. authorization.k8s.io
    name: {{ .Values.agent.admin_group }}
  {{- end}}
roleRef:
  apigroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
{{- end -}}

I would also like to create multiple groups based on the array values of admin_group:

{{- if .Values.agent.enabled }}
{{- range .Values.agent.admin_group }}
kind: Sync
apiVersion: group.xxx.com/v1alpha1
metadata:
  name: group-sync-{{ .Values.agent.namespace }}
  namespace: {{ .Values.agent.namespace }}
spec:
  domain: external
  group: {{ .Values.agent.admin_group }}
{{- end }}
{{- end -}}

Really appreciate the help. Happy Holidays!!!

Upvotes: 0

Views: 1577

Answers (1)

larsks
larsks

Reputation: 312770

Your problem is with the body of your range loops. When you write this:

{{- range .Values.agent.admin_group }}
...
{{- end}}

Then you're redefining the meaning of .. Within the loop, . refers to each successive value produced by the range operator. When you write .Values.agent.admin_group inside the loop, you're getting an error because the list items don't have a .Values field (because they're strings). You want to write:

{{- range .Values.agent.admin_group }}
- kind: group
  apiGroup: rbac. authorization.k8s.io
  name: {{ . | quote }}
{{- end}}

And similarly in your Sync template.

You can find the relevant documentation here which includes a number of examples (both on that page and on the subsequence page about variables).

Upvotes: 2

Related Questions