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

pkg/ipnet: fix Unmarshal to match ParseCIDR output #1106

Closed
wants to merge 1 commit into from

Conversation

abhinavdahiya
Copy link
Contributor

@abhinavdahiya abhinavdahiya commented Jan 22, 2019

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 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,

_, 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,

var net ipnet.IPNet
json.Unmarshal([]byte(`"192.168.0.10/24"`), &net)
println(net.String()) // prints "192.168.0.10/24"

This PR 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

/cc @wking @crawford

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 22, 2019
@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 22, 2019
@crawford
Copy link
Contributor

Can you explain why we want this change? Please include that in the commit description.

@abhinavdahiya
Copy link
Contributor Author

abhinavdahiya commented Jan 24, 2019

@crawford
I have tried to provide more information on why with the updated message in 2963361

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
@openshift-ci-robot
Copy link
Contributor

@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.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 23, 2019
@openshift-ci-robot
Copy link
Contributor

@abhinavdahiya: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws-upgrade fe55507 link /test e2e-aws-upgrade
ci/prow/e2e-aws fe55507 link /test e2e-aws

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.

@abhinavdahiya
Copy link
Contributor Author

/close

@openshift-ci-robot
Copy link
Contributor

@abhinavdahiya: Closed this PR.

In response to this:

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants