Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argument and yaml parsing type errors #3005

Closed
arthurlm44 opened this issue Oct 4, 2017 · 12 comments
Closed

argument and yaml parsing type errors #3005

arthurlm44 opened this issue Oct 4, 2017 · 12 comments

Comments

@arthurlm44
Copy link

arthurlm44 commented Oct 4, 2017

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.

@bacongobbler
Copy link
Member

bacongobbler commented Oct 5, 2017

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. 😄

@hobti01
Copy link
Contributor

hobti01 commented Oct 5, 2017

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

@ljnelson
Copy link

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.

@bacongobbler
Copy link
Member

bacongobbler commented Oct 30, 2017

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

@fejta-bot
Copy link

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

@so0k
Copy link

so0k commented Jan 30, 2018

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

@fejta-bot
Copy link

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

@cgebe
Copy link

cgebe commented May 3, 2018

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}}

@ljnelson
Copy link

ljnelson commented May 3, 2018

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

@artushin
Copy link

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.

@ghost
Copy link

ghost commented Jun 12, 2019

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.

@bacongobbler
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants