Coder Social home page Coder Social logo

Comments (7)

alvaroaleman avatar alvaroaleman commented on June 17, 2024 1

Created evanphx/json-patch#189 to ask about the possibilities and stance there

from controller-runtime.

alvaroaleman avatar alvaroaleman commented on June 17, 2024

/kind bug

That's not good. The actual patch generation is here:

return jsonpatch.CreateMergePatch(originalJSON, modifiedJSON)
which calls into this lib: https://github.com/evanphx/json-patch

I would assume the root of the problem is that the int64 ends up getting converted to a float64 and the float64 can not represent the difference. We can try to open an issue in the json-patch repo to see if this can be fixed.

from controller-runtime.

jfremy avatar jfremy commented on June 17, 2024

/kind bug

That's not good. The actual patch generation is here:

return jsonpatch.CreateMergePatch(originalJSON, modifiedJSON)

which calls into this lib: https://github.com/evanphx/json-patch
I would assume the root of the problem is that the int64 ends up getting converted to a float64 and the float64 can not represent the difference. We can try to open an issue in the json-patch repo to see if this can be fixed.

I filled the bug here because I’m not sure this can be really considered a bug in json-patch.
There is no integer type in the JSON format, just numbers. RFC-8259 says that implementations can set limits on precision and cite float64 as a good compromise.
Since json-patch does not have any type info, it unmarshals to map[string]interface{} which means that the golang json unmarshaler uses the “default” behavior (number -> float64). Which is how we end up with this.

from controller-runtime.

alvaroaleman avatar alvaroaleman commented on June 17, 2024

@jfremy actually on second thought I am unsure if this is solveable at all. Because at the end of the day, patch or not, this will get serialized to json and sent to the apiserver. At that point, the golang json (de-)serializer will end up truncating portions of large int64s. So the only ways on how this could be fixed that I can think of are:

  1. Use a different marshaller in the k8s apiserver and here that doesn't always use float64s to represent numbers
  2. Change the stdlib marshallers behavior to not always use float64 for numbers
  3. Change the job api to represent this as a string

All of these do not seem very practical unfortunately. Do you have other ideas? And out of curiosity, in what context did you run into this?

It might be worth reporting this in kubernetes/kubernetes btw, as this issue doesn't seem specific to controller-runtime.

from controller-runtime.

jfremy avatar jfremy commented on June 17, 2024

I have a CRD where I store a "seed" in an int64 (so I can end up with values in the whole int64 range).
I had an API server update call that was working fine and when I switched to patch (using MergeFrom), it stopped working.
That's how I ended up discovering the issue.

Regarding the scope of the issue, I think it is limited to MergeFrom / controller-runtime and does not impact the API server:

I've seen the API server handle updates with large int64 correctly so that part seems to work.
I'll look into the support for json patch and see if it works too to confirm - that's easy to test

Using the apimachinery json decoder in the jsonpatch library would likely fix the issue - but I do not believe json-patch supports setting a custom json decoder

from controller-runtime.

alvaroaleman avatar alvaroaleman commented on June 17, 2024

Yeah you are right, it actually works correctly in the golang json marshaller, seems I didn't look correctly yesterday.

But that just brings us back to square zero, we need a fix in json-patch or a different patch lib.

from controller-runtime.

jfremy avatar jfremy commented on June 17, 2024

Unfortunately, I agree. I don't see a way to fix it that does not imply modifying json-patch or switching to a different library that does what we want

from controller-runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.