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

chartutil.ReadValues unmarshals numbers into json.Number refs #1707 #6888

Conversation

osdrv
Copy link
Contributor

@osdrv osdrv commented Nov 5, 2019

This change is a second attempt to fix the aforementioned problem. The
first one (#6032) caused a major regression in numeric values #6708.
The new approach takes the experience of the failed attempt under
consideration and introduces some deeper-level changes to the rendering
engine. The proposed change overloads all defined template functions and
converts json.Number arguments in runtime before passing it over to the
rendering functions.

The rest of the description is preserved from the original ticket:

This change is an attempt to address the common problem of json number
unmarshalling where any number is converted into a float64 and represented in a
scientific notation on a marshall call. This behavior breaks things like: chart
versions and image tags if not converted to yaml strings explicitly.

An example of this behavior: k8s failure to fetch an image tagged with a big
number like:
$IMAGE:20190612073634
after a few steps of yaml re-rendering turns into:
$IMAGE:2.0190612073634e+13

Example issue: #1707

This commit forces yaml parser to use JSON modifiers and explicitly enables
interface{} unmarshalling instead of float64. The change introduced might be
breaking so should be processed with an extra care.

Due to the fact helm mostly deals with human-produced data (charts), we have a
decent level of confidence this change looses no functionality helm users rely
upon (the scientific notation).

Relevant doc: https://golang.org/pkg/encoding/json/#Decoder.UseNumber

Signed-off-by: Oleg Sidorov me@whitebox.io

@helm-bot helm-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 5, 2019
@bacongobbler
Copy link
Member

bacongobbler commented Nov 5, 2019

thanks @icanhazbroccoli. Because we're now in the final release candidate stages before we release Helm 3, we are only looking at major regressions or "[bugfix] now or forever hold your peace" fixes for Helm 3. Since this is a progressive bugfix that can be addressed in a feature release, this won't be in the 3.0.0 release. We will take a closer look at this proposal for 3.1.0 after Helm 3 has been released. Just letting you know that it'll take a while before we get around to reviewing this. Thanks!

@bacongobbler bacongobbler added this to the 3.1.0 milestone Nov 5, 2019
@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from ad555c2 to 7a46ac5 Compare November 5, 2019 21:10
@osdrv
Copy link
Contributor Author

osdrv commented Nov 5, 2019

@bacongobbler totally makes sense to me, thanks for the heads up!

@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch 2 times, most recently from c07f7e9 to fb9ec86 Compare November 13, 2019 18:32
@mattfarina mattfarina modified the milestones: 3.1.0, 3.0.1 Nov 25, 2019
@mattfarina mattfarina modified the milestones: 3.0.1, 3.1.0 Dec 5, 2019
@mattfarina
Copy link
Collaborator

Moving this back to 3.1.0 milestone. I see that makes use of the "C" import and I think this is the first time this is being done in Helm. We need to discuss this in further detail. I've added it to the agenda for the Helm developer call.

@osdrv
Copy link
Contributor Author

osdrv commented Dec 5, 2019

@mattfarina thanks a lot for keeping me posted. That totally makes sense. Please give me a heads up if my presence is wanted. Thank you!

@technosophos
Copy link
Member

This was discussed in this morning's Helm Dev Call, and we'll follow up on it.

@bacongobbler bacongobbler modified the milestones: 3.1.0, 3.2.0 Feb 6, 2020
@thomasfulton
Copy link

@technosophos @icanhazbroccoli Just wondering if there is any ETA on when this fix will be released?

@technosophos
Copy link
Member

I have not heard any more than what I posted last time. But this PR does need a quick rebase.

@osdrv
Copy link
Contributor Author

osdrv commented Feb 17, 2020

@technosophos Will rebase it somewhere this week.

@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from fb9ec86 to 17f2d70 Compare February 19, 2020 19:00
@osdrv
Copy link
Contributor Author

osdrv commented Feb 19, 2020

@technosophos rebase looks fine, no explosions.

@thomasfulton would it be too much of a favor to ask you to build Helm from this dev branch and confirm it solves the problem you have in mind?

@kostyaplis
Copy link

@icanhazbroccoli
I went ahead and performed make build from icanhazbroccoli:icanhazbroccoli/chartutil-no-scientific-notation-v2 branch.
However I'm still getting scientific notation issue.

values.yaml:

image:
  tag: 1234567
$ ./bin/helm version
version.BuildInfo{Version:"v3.1+unreleased", GitCommit:"17f2d703484841ee8adf6db0469cc49db563803e", GitTreeState:"clean", GoVersion:"go1.13.6"}
$ ./bin/helm install test -f values.yaml repo/chart --dry-run --debug

Produced following output (redacted for brevity):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
    version: "1.234567e+06" # we use version: {{ .Values.image.tag | quote }} 
spec:
  template:
    metadata:
      labels:
        app: test
        version: "1.234567e+06"
    spec:
      containers:
        - name: test
          image: "repo/test:1.234567e+06"
          imagePullPolicy: IfNotPresent

@osdrv
Copy link
Contributor Author

osdrv commented Mar 30, 2020

@kostyaplis it's super nice of you, thanks a lot. I'll have a look at it some time soon, I expected a slightly different result. Thank you.

@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from 17f2d70 to 5da63ca Compare March 31, 2020 19:12
@osdrv
Copy link
Contributor Author

osdrv commented Mar 31, 2020

@kostyaplis hey mate, once again: I appreciate you taking a moment to try this and for pointing me out to the issue. Indeed, one more component (loader) required an identical patch we applied before and without this one I managed to reproduce the problem. I've updated the branch and it renders as expected on my local machine. If it's not too much of a bother, please give it a try yourself. Thanks!

@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from 5da63ca to 6086ef3 Compare March 31, 2020 19:38
@kostyaplis
Copy link

kostyaplis commented Apr 4, 2020

Hi @icanhazbroccoli
Getting same results as before

./bin/helm version
version.BuildInfo{Version:"v3.1+unreleased", GitCommit:"6086ef398ba87ec833dc0a8081386c3bb8accc11", GitTreeState:"clean", GoVersion:"go1.13.6"}
./bin/helm install test -f values.yaml /path/to/chart --debug --dry-run
USER-SUPPLIED VALUES:
image:
  tag: 123456789

COMPUTED VALUES:
image:
  pullPolicy: IfNotPresent
  repository: test
  tag: 123456789

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
    version: "1.23456789e+08"
spec:
  template:
    metadata:
      labels:
        app: test
        version: "1.23456789e+08"
    spec:
        containers:
          - name: test
            image: "test/test:1.23456789e+08"

@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from 6086ef3 to d2b9519 Compare April 4, 2020 17:04
@osdrv
Copy link
Contributor Author

osdrv commented Apr 4, 2020

@kostyaplis your example was super helpful: it seems i missed the CLI value parser :-( Got it patched as well. Thank you!

@kostyaplis
Copy link

Confirm that I'm getting correct results (--dry-run at least) with d2b9519 build

@technosophos
Copy link
Member

Okay, at this point things are looking solid with this PR. Two questions of the core maintainers:

a) @mattfarina did you have any issues with the present version here?
b) Are there any compatibility breakers if we switch to this method of handling numerics? (e.g. is there anything that worked before, but will not if we apply this patch?)

@technosophos technosophos removed this from the 3.2.0 milestone Apr 15, 2020
@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from d2b9519 to 5e300ec Compare April 16, 2020 11:29
@osdrv
Copy link
Contributor Author

osdrv commented Apr 16, 2020

Please excuse some extra noise folks, the force-pushed change contains no new functional changes: mainly some naming corrections and extra comments to make the reflect code more human-readable.

This change is a second attempt to fix the aforementioned problem. The
first one (helm#6032) caused a major regression in numeric values helm#6708.
The new approach takes the experience of the failed attempt under
consideration and introduces some deeper-level changes to the rendering
engine. The proposed change overloads all defined template functions and
converts json.Number arguments in runtime.

The rest of the description is preserved from the original ticket:

This change is an attempt to address the common problem of json number
unmarshalling where any number is converted into a float64 and represented in a
scientific notation on a marshall call. This behavior breaks things like: chart
versions and image tags if not converted to yaml strings explicitly.

An example of this behavior: k8s failure to fetch an image tagged with a big
number like:
  `$IMAGE:20190612073634`
after a few steps of yaml re-rendering turns into:
  `$IMAGE:2.0190612073634e+13`

Example issue: helm#1707

This commit forces yaml parser to use JSON modifiers and explicitly enables
interface{} unmarshalling instead of float64. The change introduced might be
breaking so should be processed with an extra care.

Due to the fact helm mostly dals with human-produced data (charts), we have a
decent level of confidence this change looses no functionality helm users rely
upon (the scientific notation).

Relevant doc: https://golang.org/pkg/encoding/json/#Decoder.UseNumber

Signed-off-by: Oleg Sidorov <me@whitebox.io>
@osdrv osdrv force-pushed the icanhazbroccoli/chartutil-no-scientific-notation-v2 branch from 5e300ec to d53993f Compare April 16, 2020 14:23
@kostyaplis
Copy link

@icanhazbroccoli is there anything I can help to get this merged?
We are using ${SHA1:0:7} to tag our dev/stage images, it happens sometimes that first seven chars are all digits, so this still biting us occasionally.

@osdrv
Copy link
Contributor Author

osdrv commented May 4, 2020

@kostyaplis thanks for the heads up! I'm afraid I have no data about it. The pr was de-tagged some time ago, which looks like the core team has some concerns (which is totally understandable in the light of the added C dependency). Tagging @technosophos.

@kostyaplis
Copy link

@icanhazbroccoli Actually, I don't observe an issue anymore with Helm 3.2.0
Tested just now:
2.16.7 - fails
3.2.0 - numeric values interpreted correctly and image deployed successfully.
There were some Go deps updates for 3.2.0, so maybe thats fixed it...

@osdrv
Copy link
Contributor Author

osdrv commented May 13, 2020

@kostyaplis frankly, this surprises me as I replayed the test you provided (ensuring make clean && make build) and it gives me different results. It would be great to double-check the version that gives the right output is tagged 3.2.0 (no stale builds or something).

@bacongobbler
Copy link
Member

Perhaps it may be worth going back to the base case to determine if the issue is still present in Helm 3.3.0 before considering moving forward with this PR. Do you agree @icanhazbroccoli?

@osdrv
Copy link
Contributor Author

osdrv commented Aug 23, 2020

@bacongobbler please sorry for my late reply. Totally agree. Let me close the PR for now.

@osdrv osdrv closed this Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants