Comments (7)
Created evanphx/json-patch#189 to ask about the possibilities and stance there
from controller-runtime.
/kind bug
That's not good. The actual patch generation is here:
controller-runtime/pkg/client/patch.go
Line 136 in 2154ffb
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.
/kind bug
That's not good. The actual patch generation is here:
controller-runtime/pkg/client/patch.go
Line 136 in 2154ffb
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.
@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:
- Use a different marshaller in the k8s apiserver and here that doesn't always use float64s to represent numbers
- Change the stdlib marshallers behavior to not always use float64 for numbers
- 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.
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:
- golang json will do the "right" thing when marshaling/unmarshaling to/from typed objects
- Kubernetes seems to have an overloaded json decoder that when decoding json numbers tries to decode as int64 first and float64 if it did not succeed (https://github.com/kubernetes/apimachinery/blob/master/pkg/util/json/json.go).
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.
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.
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)
- Enhancement of Authentication and Authorization Filters to Allow Custom Configurations and Stability Improvements HOT 4
- Data race with various client APIs HOT 3
- Allow to ignore globalPredicates for specific resources HOT 1
- Undefined SwitchMetric Error with client-go 0.30.0 in Go Vet HOT 9
- Use setup-envtest from (test) code HOT 18
- Semantic version is incorrect for setup-envtest HOT 3
- Default Liveness and Readiness endpoints return 404
- Optimize patches returned by Defaulter
- DefaultLabelSelector overrides ByObject.Label in DefaultNamespaces
- Does controller-runtime support that multiple controllers share one Manager and use different clients(RBAC)? HOT 6
- Add a way to grab the controller name out of the reconcile context HOT 1
- failed to install setup-envtest HOT 1
- How to change DefaultNamespaces at runtime HOT 3
- Reconcile is triggered after status update HOT 4
- Upgrade problem (v0.15.2->v0.17.3): configuring namespace HOT 2
- [BUG]: goroutine leak when `leaderelection.NewLeaderElector` return error
- [issue] regarding horizontal scaling for operators
- [bug] setup-envtest unable to find version for linux HOT 8
- go install fails with "zip: not a valid zip file" error message HOT 1
- setup-envtest is stuck and fails to download any k8s version HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from controller-runtime.