sprig
sprig copied to clipboard
in helm: want to catch errors from getHostByName to define actions
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
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 }
There is actually a Rhttps://github.com/Masterminds/sprig/issues/302 #279 that has the fixes for this issue.
Created PR for this - https://github.com/Masterminds/sprig/pull/319