-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix: Workaround Go Inet marshal bug #410
Conversation
6e5f973
to
1dba1a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this works, but I'll let @shimonp21 verify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
Just thinking we should maybe add a test that covers the marshal/unmarshal behavior for all the types to make sure this fix works as expected, doesn't regress and that there aren't other similar bugs lurking in other types.
schema/inet.go
Outdated
@@ -146,6 +153,22 @@ func maybeGetIPv4(input string, ip net.IP) net.IP { | |||
return ip.To4() | |||
} | |||
|
|||
// workaround this Golang bug: https://github.com/golang/go/issues/35727 | |||
func (dst *Inet) UnmarshalJSON(b []byte) error { | |||
tmp := inetIntermidate{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tmp := inetIntermidate{} | |
tmp := inetIntermediate{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. Let's sync on this online?
@shimonp21 this now works. @hermanschaaf added tests. |
schema/inet_test.go
Outdated
} | ||
|
||
// workaround this Golang bug: https://github.com/golang/go/issues/35727 | ||
if len(r.IPNet.Mask) != len(r2.IPNet.Mask) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why compare lengths here, and not the values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we compare the values in the line before that. the bug was that the bytes are in different length. I can also add a byte comparision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. No all good, just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but good call. Added more thorugh tests and also checked that it failed before the fix and after
schema/inet.go
Outdated
return err | ||
} | ||
*dst = Inet{Status: tmp.Status} | ||
dst.Status = tmp.Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this line?
@@ -12,6 +13,12 @@ type InetTransformer interface { | |||
TransformInet(*Inet) interface{} | |||
} | |||
|
|||
// workaround this Golang bug: https://github.com/golang/go/issues/35727 | |||
type inetWrapper struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment that this is only used in Unmarshal.
Maybe order structs so that exported struct Inet
is at the top.
6192d8d
to
552ede9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving at @yevgenypats request.
We may still have a bug in handling ipv6 though - testing that right now
🤖 I have created a release *beep* *boop* --- ## [1.5.3](v1.5.2...v1.5.3) (2022-11-15) ### Bug Fixes * Workaround Go Inet marshal bug ([#410](#410)) ([bd7718c](bd7718c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Fix nasty bug triggered by Go bug
golang/go#35727
@shimonp21 can you please confirm this solves the bug triggered by the k8s cidr plugin.