Home > Blockchain >  Helm template not able to read ip address - can't evaluate field ipAddress in type string
Helm template not able to read ip address - can't evaluate field ipAddress in type string

Time:05-03

I am trying to create a helm template for Istio's ServiceEntry which has a list of addresses for static ip addresses. In values.yaml, I have

- name: test-se
  namespace: test-se-ns
  egressUrls: 
  - mydbhost.com
  port: 32306
  protocol: TCP
  ipAddress: 10.2.2.2

In the .tpl file I am trying to add the value of ipAddress to a list

  {{- with .ipAddress }}
  addresses: 
  - {{ .ipAddress | quote }}
  {{- end }}

Always fails with exception

templates/_service_entry.tpl:18:13: executing "common.serviceentry.tpl" at <.ipAddress>: can't evaluate field ipAddress in type string

Any idea what I am doing wrong?

CodePudding user response:

when you use with in Helm, you change the scope of the ., so Helm looks for an object and not a string, you can read more about it in the docs.

but anyway, I think that in your case, you need to use range instead of with, you can see an example here

CodePudding user response:

If you use with you make the thing that you have used as with the context inside that block.

So, use the dot to refer to it.

{{- with .ipAddress }}
addresses: 
  - {{ . | quote }}
{{- end }}

From the docs:

{{with pipeline}} T1 {{end}}
    If the value of the pipeline is empty, no output is generated;
    otherwise, dot is set to the value of the pipeline and T1 is
    executed.

In this case, an if seems also fitting, since you do not much with the new context.

{{- if .ipAddress }}
addresses: 
  - {{ .ipAddress | quote }}
{{- end }}
  • Related