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

Fix confusing error msg invalid cidr #638

Conversation

maiqueb
Copy link
Contributor

@maiqueb maiqueb commented Jun 22, 2021

By wrapping the error msg we ended up actually duplicating the exact same msg net.ParseCIDR replies, as seen in its implementation - [0] & [1]

This PR makes the error msg less confusing.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1897431

[0] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/net.go#L540
[1] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/ip.go#L739

@mccv1r0
Copy link
Member

mccv1r0 commented Jun 22, 2021

You pasted the same link twice:

[0] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/net.go#L540
[1] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/net.go#L540

@maiqueb
Copy link
Contributor Author

maiqueb commented Jun 23, 2021

You pasted the same link twice:

[0] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/net.go#L540
[1] - https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/net/net.go#L540

Good catch. Corrected the second link.

@maiqueb maiqueb force-pushed the fix-confusing-error-msg-invalid-cidr branch from a819b97 to fc3c05e Compare June 23, 2021 10:28
@mccv1r0
Copy link
Member

mccv1r0 commented Jun 23, 2021

/lgtm

maiqueb added 3 commits June 25, 2021 11:24
Signed-off-by: Miguel Duarte Barroso <[email protected]>
Signed-off-by: Miguel Duarte Barroso <[email protected]>
@maiqueb maiqueb force-pushed the fix-confusing-error-msg-invalid-cidr branch from fc3c05e to b370fa0 Compare June 25, 2021 12:23
plugins/ipam/static/main.go Show resolved Hide resolved
@@ -193,6 +193,10 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
// args IP overwrites IP, so clear IPAM Config
n.IPAM.Addresses = make([]Address, 0, len(n.Args.A.IPs))
for _, addr := range n.Args.A.IPs {
_, _, err := net.ParseCIDR(addr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string-format IP(or CIDR) will be parsed later, so why we check this twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the way I found of indicating which parameter was the offending one (the string format CIDR validation will be performed for cni args / ipam config later on, and its impossible to know the parameter name by then).

But I agree with you - IMO, just saying we expect CIDR notation should be enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, since the parse and validation already done here, could we append a parsed Address instead of a single string to avoid this to be parsed later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely fond of how it looks, but have provided a new commit w/ this change.

Let me know if that's OK.

This commit addresses the scenarios when the invalid CIDR is
provisioned via:
- CNI_ARGS
- RuntimeConfig

Signed-off-by: Miguel Duarte Barroso <[email protected]>
With this patch, when the IPs are provisioned via CNI args or via
`RuntimeConfig` the CIDR is only parsed once.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
@maiqueb maiqueb force-pushed the fix-confusing-error-msg-invalid-cidr branch from b370fa0 to 8ab2336 Compare August 24, 2021 11:21
@maiqueb maiqueb requested a review from mars1024 August 24, 2021 11:22
@maiqueb
Copy link
Contributor Author

maiqueb commented Aug 24, 2021

@mars1024 also, for whatever reason, CI stopped running the tests automatically; it complains a maintainer must approve testing for it.

Can you grant it ?

Copy link

@dougbtv dougbtv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements, I think with this error messaging, it's more actionable for a user (they now can see that we're saying "hey, a.b.c.d that's not in CIDR format, you should change it." instead of just "this is wrong: a.b.c.d." (which doesn't tell us it's in the wrong format)

@maiqueb
Copy link
Contributor Author

maiqueb commented Sep 15, 2021

@mars1024 also, for whatever reason, CI stopped running the tests automatically; it complains a maintainer must approve testing for it.

Can you grant it ?

ping @mars1024

Copy link
Member

@mars1024 mars1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm, thanks! Errors seem more pointed!

@mccv1r0
Copy link
Member

mccv1r0 commented Sep 15, 2021

/lgtm

@mars1024 mars1024 merged commit a6b5412 into containernetworking:master Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants