-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
pkg/ipnet: fix Unmarshal to match ParseCIDR output #1106
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abhinavdahiya The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Can you explain why we want this change? Please include that in the commit description. |
740f836
to
2963361
Compare
The stdlib's implementation [1] of parsing cidr string into `net.IPNet` [2] converts cidrs like `192.168.0.10/24`, which are using an IP that only belongs to a network rather than using network IPs (usually the first IP in a network), to a `192.168.0.1/24`. This is more clearer from the comment [3], that `IP` field in `net.IPNet` is intended to be a network IP. example, ```go _, net, _ := net.ParseCIDR("192.168.0.10/24") println(net.String()) // prints "192.168.0.1/24" ``` As of master [4], installer's wrapper implementation for unmarshalling cidr from `JSON string` to `net.IPNet` actually keeps the non network IP. example, ```go var net ipnet.IPNet json.Unmarshal([]byte(`"192.168.0.10/24"`), &net) println(net.String()) // prints "192.168.0.10/24" ``` This commit fixes the json.Unmarshal for `pkg/ipnet/IPNet` to match behavior of `net.ParseCIDR` [1] https://golang.org/pkg/net/#ParseCIDR [2] https://golang.org/pkg/net/#IPNet [3] https://golang.org/src/net/ip.go?s=1063:1144#L28 [4] https://github.com/openshift/installer/blob/54737c4f9bcb8a73f1695e8c23d2c74394ae0af9/pkg/ipnet/ipnet.go
2963361
to
fe55507
Compare
@abhinavdahiya: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@abhinavdahiya: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/close |
@abhinavdahiya: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Moved into separate PR as this as not required for #1065 and @wking can reservations on this change #1065 (comment)
The stdlib's implementation [1] of parsing cidr string into
net.IPNet
[2] converts cidrs like192.168.0.10/24
,which are using an IP that only belongs to a network rather than using network IPs (usually the first IP in a network), to a
192.168.0.1/24
.This is more clearer from the comment [3], that
IP
field innet.IPNet
is intended to be a network IP.example,
As of master [4], installer's wrapper implementation for unmarshalling cidr from
JSON string
tonet.IPNet
actually keeps the non network IP.example,
This PR fixes the json.Unmarshal for
pkg/ipnet/IPNet
to match behavior ofnet.ParseCIDR
[1] https://golang.org/pkg/net/#ParseCIDR
[2] https://golang.org/pkg/net/#IPNet
[3] https://golang.org/src/net/ip.go?s=1063:1144#L28
[4] https://github.com/openshift/installer/blob/54737c4f9bcb8a73f1695e8c23d2c74394ae0af9/pkg/ipnet/ipnet.go
/cc @wking @crawford