Repository navigation
Description
Output of helm version:
version.BuildInfo{Version:"v3.0.0-rc.3", GitCommit:"2ed206799b451830c68bff30af2a52879b8b937a", GitTreeState:"clean", GoVersion:"go1.13.4"}
When app version is a commit sha, it gets converted to a scientific notation. See below for more details on how to reproduce and about the issue:
$ helm create test-dummy
$ # change appVersion to 72225e2
$ vi test-dummy/Chart.yaml
$ cat test-dummy/Chart.yaml
apiVersion: v2
name: test-dummy
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 72225e2
$ helm package test-dummy
Successfully packaged chart and saved it to: /Users/karuppiahoss/oss/helm-issues/issue-6833/dummy-repo-local/test-dummy-0.1.0.tgz
$ # check Chart.yaml contents in tar ball
$ vi test-dummy-0.1.0.tgz
Chart.yaml contents in packaged tar ball will look like this:
apiVersion: v2
appVersion: "7.2225e+06"
description: A Helm chart for Kubernetes
name: test-dummy
type: application
version: 0.1.0
And then in repository index:
$ helm repo index .
$ # a part of the index
$ cat index.yaml
apiVersion: v1
entries:
test-dummy:
- apiVersion: v2
appVersion: "7.2225e+06"
created: "2019-11-09T13:07:38.472282+05:30"
description: A Helm chart for Kubernetes
digest: 626ec3a02750e500a386d80b053f6f66eef40354a45e8ad18b7ddc8426314037
name: test-dummy
type: application
urls:
- test-dummy-0.1.0.tgz
version: 0.1.0
generated: "2019-11-09T13:07:38.471001+05:30"
while adding repo and doing search
$ # host index.yaml using https://www.npmjs.com/package/serve
$ serve
$ # in another tab
$ helm repo add local http://localhost:5000
$ helm search repo test
helm search repo test
NAME CHART VERSION APP VERSION DESCRIPTION
local/test-dummy 0.1.0 7.2225e+06 A Helm chart for Kubernetes
I expected the search to show 72225e2, and that happens only when I put double quotes around 72225e2. Found the issue when checking #6849 . I think the lint and package should give error when it detects numbers instead of string in appVersion field in the yaml. According to yaml spec, the above is a number.
In helm, instead of erroring out for the number, the number is converted to a string somehow.
Activity
[-]Helm3: App Version as commit sha getting converted to scientific notation[/-][+]Helm3: when App Version is a commit sha, it's getting converted to scientific notation[/+]jabielecki commentedon Nov 10, 2019
Replicates on
masterNot only
appVersionbut alsoversionhas this behavior.jabielecki commentedon Nov 10, 2019
Gulp. Every string unmarshalled with sigs.k8s.io/yaml has this behavior, the behavior is intentional per this comment in their source. Still, this looks like a bug to me.
Package yaml.v2 doesn't do such manipulations.
bacongobbler commentedon Nov 12, 2019
The behavior is correct. If you provide
72225e2as a field value, the type is ambiguous. Once the field is read, it is cast into the inferred type.72225e2happens to be a number represented in scientific notation. To fix this, wrap the string in quotes. That way the YAML parser will treat it as a string.We should probably ask
helm createto wrap the string fields in quotes. That way these fields are treated as strings.In other words, the output of
helm create test's Chart.yaml should be changed from this:to this:
karuppiah7890 commentedon Nov 12, 2019
I would still say it's a bug that we are not raising an error when people mention it as number. And instead silently convert it into a string
There's no ambiguity in the type. According to yaml spec it's a number. Like @jabielecki mentioned, in
sigs.k8s.io/yamlpackage, it is intentionally converted to string. I would highly recommend to error out in such cases, for all the fields inChart.yamlmetadata which are strings. That way, people will be educated to put double quotes around it even if they are removed, and that should be good enoughAs currently this can lead to a bad
appVersionvalue due to automatic conversionbacongobbler commentedon Nov 12, 2019
Yeah. We could probably do a type check when loading charts with incorrect fields. I'm surprised the YAML parser doesn't do that already.
karuppiah7890 commentedon Nov 13, 2019
I mean, yeah, for some reason the boolean / number field in the yaml is coerced to string when the target (struct type) is a string. Not sure about the pros of it, but in this case, it's not good for us, as it indirectly affects the repo index, search info.
karuppiah7890 commentedon Dec 10, 2019
@bacongobbler I don't think wrapping in quotes is possible as mentioned here - #6921 (comment) . I mean, yaml lib takes code and converts it into yaml string, and if it knows that the value looks like a string, it will not put quotes around it, but if it looks like
"72225e2", then it will put quotes around it, so that later it is read as"72225e2"which is the right thing. But we can check it out. If it's possible. For now I'm not going to do that. Instead I'm going to try to do a type checkkaruppiah7890 commentedon Dec 15, 2019
I have created a PR for showing the issue in
lint. But I think even during package, if linting itself fails, package should also fail. Currently that's the case, for now, I have started with raising PR only for linting side.packagesubcommand still might need a fix is my opinion. All thoughts welcome 😄cc @bacongobbler @jabielecki
karuppiah7890 commentedon Dec 16, 2019
Can we add
v2andv3label? #6922[hotfix] Wrap commit sha in quotes to avoid parsing errors
mbelang commentedon Jun 15, 2020
I remember that --set-string in helm v2 was doing the trick but in my case I cannot really predict the structure of my values.yml file as it is generated via a bunch of conditions in the CI. I use the short sha in multiple places.
Anyways, all that being said, I recently migrated from helm2 to helm3 and I didn't change anything in the input values.yaml file. If I run with v2, no problem, I run with v3,
72225e2get converted to float notation.Is there progress on this?
bacongobbler commentedon Jun 15, 2020
have you tried the workaround provided in #6921 (comment)?
Nobody has worked on this since it was opened, AFAIK. Feel free to take a crack at this.
mbelang commentedon Jun 16, 2020
@bacongobbler that was my bet but since I use that field in a generated file it is a bit 💩 to fix 😂