helm icon indicating copy to clipboard operation
helm copied to clipboard

argument and yaml parsing type errors

Open arthurlm44 opened this issue 9 years ago • 12 comments

Since upgrading to helm 2.6.1, from 2.5.1 I've been encountering this issue:

Error: render error in "instastage/templates/service.yaml": template: instastage/templates/service.yaml:1:5: executing "instastage/templates/service.yaml" at <eq .Values.replicaCo...>: error calling eq: incompatible types for comparison

The helm command is:

helm install --debug --dry-run --set replicaCount=1,anotherVar=someothervalue ~/workspace/charts/mychart

and the chart starts with:

{{if eq .Values.replicaCount 1.0}}

This worked fine in 2.5.1 but is broken in 2.6.1

I've tried from file via -f flag but get the same type error.

Strings are parsed fine, but integers (which used to be automatically converted to floats, which in itself was a bug) are no longer coming in as either integers or floats and vice-versa.

I've attempted to pass ints, and floats and have attempted int and float comparison to no avail.

arthurlm44 avatar Oct 04 '17 23:10 arthurlm44

To give others some background on why the chart uses a float-point value instead of an int, it's due to some issues with the --set parser with ints being converted to scientific notation in some cases as seen in #1707.

We've attempted a multitude of --set attempts over slack with @arthurlm44 yesterday afternoon:

--set replicaCount=1
--set replicaCount=1.0
--set replicaCount="1.0"
--set replicaCount=1\.0
--set replicaCount="1\.0"
--set replicaCount=\"1.0\"

None of the above worked. Regardless of the argument whether replica count should be an integer or not, we should find a way to parse floating point values and document it.

The ugly workaround is to use a literal string for now.

{{ if eq .Values.replicaCount "one" -}}
replicas: 1
{{- else -}}
replicas: 0
{{- end }}

It's funny to think how only 2 and a third pods would be deployed, though. 😄

bacongobbler avatar Oct 05 '17 15:10 bacongobbler

I have a related issue without using set, Helm v2.6.2. Thanks for the hints here to get a workaround.

Does not work: values.yaml

replicas: 1

templates/test.yaml

{{- if gt .Values.replicas 1 }}
Greater than one
{{- end }}

Output:

$ helm install --debug --dry-run my-chart
...
Error: render error in "my-chart/templates/test.yaml": template: my-chart/templates/test.yaml:1:7: executing "my-chart/templates/test.yaml" at <gt .Values.replicas ...>: error calling gt: incompatible types for comparison

Does work: values.yaml

replicas: 2

templates/test.yaml

{{- if gt .Values.replicas 1.0 }}
Greater than one
{{- end }}
$ helm install --debug --dry-run my-chart
...
---
# Source: my-chart/templates/test.yaml

Greater than one

hobti01 avatar Oct 05 '17 23:10 hobti01

This just occurred to me out of the blue and I thought I'd at least capture it here. Would something like this work:

--set replicaCount="!!int '1.0'"

…? !!int applied to a YAML scalar is supposed to coerce it.

ljnelson avatar Oct 30 '17 16:10 ljnelson

Assuming https://github.com/ghodss/yaml supports it, yes. Most parsers don't support every part of the YAML spec.

bacongobbler avatar Oct 30 '17 16:10 bacongobbler

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jan 28 '18 19:01 fejta-bot

Still facing this issue, helm 2.7.2 - workaround using float works

so0k avatar Jan 30 '18 17:01 so0k

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten /remove-lifecycle stale

fejta-bot avatar Mar 01 '18 18:03 fejta-bot

same as @hobti01

issue still occurs - v2.9.0:

Error: render error in "server/templates/deployment.yaml": template: server/templates/deployment.yaml:36:7: executing "server/templates/deployment.yaml" at <gt .Values.replicaCo...>: error calling gt: incompatible types for comparison
{{- if gt .Values.replicaCount 1 }}
                 ...
{{- end}}

cgebe avatar May 03 '18 12:05 cgebe

Out of curiosity, could you try --set replicaCount="!!int '1'"?

ljnelson avatar May 03 '18 16:05 ljnelson

To clarify the workaround from @so0k, if doing something like {{- if eq .Values.replicas 1.0 }}, the second arg should be the float so that you don't have to cast .Values.replicas.

artushin avatar Apr 10 '19 18:04 artushin

I got around this by piping the variables to int64.

For instance, to check whether my hpa's max number of replicas was less than or equal to the number of credentials I had, I did this:

{{ le (.Values.hpa.maxReplicas | int64) (len .Values.app.credentials | int64) }}

This workaround isn't pretty, but it works for me.

ghost avatar Jun 12 '19 22:06 ghost

given that there hasn't been any activity in the last 3 years to address this since it was first opened, I'm going to close this as community members have found workarounds to the issue, and that seems to solve the problem.

bacongobbler avatar May 14 '20 20:05 bacongobbler