sprig icon indicating copy to clipboard operation
sprig copied to clipboard

in helm: want to catch errors from getHostByName to define actions

Open ns-kvaradhan opened this issue 4 years ago • 3 comments

I am following up form a request to the helm guys in https://github.com/helm/helm/issues/9737 Here, I am using

rbi-env [ingress✗]➜ helm version
version.BuildInfo{Version:"v3.5.4", GitCommit:"1b5edb69df3d3a08df77c9902dc17af864ff05d1", GitTreeState:"dirty", GoVersion:"go1.16.3"}

I would like to use the following:

  {{- if getHostByName .Values.hostName }}
  annotations:
    kubernetes.io/ingress.global-static-ip-name: {{ .Values.hostName | quote }}
  {{- end }}

Which works when .Values.hostname is resolvable, but throws up an error, when it fails:

foo [ingress✗]➜ helm template bar --set hostName=asd.ldsjf.com
Error: template: bar/templates/ingress.yaml:1:9: executing "bar/templates/ingress.yaml" at <getHostByName .Values.hostName>: error calling getHostByName: invalid argument to Intn

Use --debug flag to render out invalid YAML

I see this comment in the sprig code: https://github.com/Masterminds/sprig/blob/3ac42c7bc5e4be6aa534e036fb19dde4a996da2e/network.go#L9-L10

Any chance I can get a fix for me to try this out?

Thanks,

Kannan

ns-kvaradhan avatar May 25 '21 18:05 ns-kvaradhan

We also have a use case that it should not stop/exit when/if Host is not resolvable. Achieved by returning nil

addrs, err := net.LookupHost(name) if err != nil { return "", nil }

riccardo32 avatar Jun 01 '21 08:06 riccardo32

There is actually a Rhttps://github.com/Masterminds/sprig/issues/302 #279 that has the fixes for this issue.

ns-kvaradhan avatar Jun 03 '21 06:06 ns-kvaradhan

Created PR for this - https://github.com/Masterminds/sprig/pull/319

riccardo32 avatar Nov 18 '21 11:11 riccardo32