-
Notifications
You must be signed in to change notification settings - Fork 116
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
OCPBUGS-39403 - Fix parseIPList
to Continue Processing After Invalid IPs and Return Valid IPs
#621
base: master
Are you sure you want to change the base?
Conversation
Hi @mJace. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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-sigs/prow repository. |
/assign |
parseIPList
to Continue Processing After Invalid IPs and Return Valid IPsparseIPList
to Continue Processing After Invalid IPs and Return Valid IPs
@mJace : would it be possible for you to provide some unit tests for this change? |
/assign |
80ce105
to
51aad66
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@alebedev87 |
return list | ||
|
||
if len(invalidIPs) > 0 { | ||
log.V(7).Info("parseIPList found invalid IP/CIDR items", "invalidIPs", invalidIPs) |
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 would keep the log line up at line 391 where you find an invalid IP, e.g. log it for each invalid ip. Then you don't need the invalidIPs slice, nor to take a len later.
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.
Thank you for your advice.
/ok-to-test |
51aad66
to
31fdfe8
Compare
/retest-required |
/retest |
validIPs = append(validIPs, ip) | ||
} else { | ||
// Log invalid IP/CIDR | ||
log.V(0).Info("parseIPList found invalid IP/CIDR", ip) |
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.
Since this changes behavior, we need to make sure this error is noticed, and indicate that the invalid IP is now ignored. Something like this:
log.V(0).Info("parseIPList found invalid IP/CIDR", ip) | |
log.Error("error parsing IP list, ignoring invalid IP/CIDR", ip) |
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 added a customErr for IP/CIDR since only net.parseCIDR
returns err
.
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 wondering whether this one should be an error, taking into account that now we don't stop the parsing and there can be some valid IPs still. I think that the error would make more sense down the code where we find that the list is empty. However in the similar conditions in the same function (when we return ""
) we use log.V(7).Info()
. So it seems to be inconsistent.
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.
@alebedev87 That’s why I use log.V(0).Info at the beginning.
I reviewed all scenarios that call log.Error() in template_helper.go
, and they all return "" immediately.
Since, in this case, we will continue parsing the rest of the IP, is it okay to use log.Info but at a higher log level?
If yes, what level should I use here?
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.
The default log level is 2 so if we want this message to be visible it has to be <= 2
. From what I can see in template_helper.go
the log level 0
is what's used in similar cases (example) - when the user needs to be informed but the flow may continue. Similarly, looking at the other functions - failing the parsing with an error if the list of valid IPs/CIDRs is empty seems to be the way to go.
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.
Btw the condition about the trimmer list being compared to the given list doesn't seem to use the right logging level:
if trimmedList != list {
log.V(7).Info("parseIPList leading/trailing spaces found")
return ""
}
I would prefer it to be a level 0
too as we want the user to see this.
@@ -1061,7 +1112,7 @@ func TestParseIPList(t *testing.T) { | |||
} | |||
return | |||
} | |||
if got != tc.input { | |||
if got != tc.expectedReturn { |
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.
Followup to https://github.com/openshift/router/pull/621/files#r1815351390.
if got != tc.expectedReturn { | |
if expectedEmpty && got != "" || got != tc.expectedReturn { |
@@ -1061,7 +1112,7 @@ func TestParseIPList(t *testing.T) { | |||
} | |||
return | |||
} | |||
if got != tc.input { | |||
if got != tc.expectedReturn { | |||
t.Errorf("Failure: expected %q, got %q", tc.input, got) |
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.
t.Errorf("Failure: expected %q, got %q", tc.input, got) | |
if expectedEmpty { | |
log.Errorf("Failure: expected none, got %q", got) | |
} else { | |
t.Errorf("Failure: expected %q, got %q", tc.expectedReturn, got) | |
} |
1e3bc18
to
09efe4a
Compare
aeb7e77
to
4a700ef
Compare
@candita so the test function is now as following,
or do you think it is ok to make it more simple?
|
/retest |
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 think it's close to LGTM. I just wanted to discuss this thread and I agree with Candace that this if
should be changed to be more straightforward.
expectedEmpty: true, | ||
name: "Wrong IPv4 in an IPs only list", | ||
input: "192.168.1.0 2001:0db8:85a3:0000:0000:8a2e:0370:7334 172.16.14.10/24 2001:0db8:85a3::8a2e:370:10/64 64:ff9b::192.168.0.1 10.", | ||
expectedEmpty: false, |
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.
When expectedEmpty
is false
it can be skipped from the test struct, similar to the other tests which were modified above.
Sorry for the double post of the review, some buggy behavior from github. |
4a700ef
to
81ad24e
Compare
/retest |
1 similar comment
/retest |
@mJace: all tests passed! Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
Summary
This PR updates the
parseIPList
function to handle IP lists containing invalid IPs or CIDRs more gracefully. Previously, the function would return an empty string as soon as it encountered an invalid IP or CIDR. This update ensures that the function will now continue processing the rest of the list and return a space-separated string of all valid IPs and CIDRs.Changes
parseIPList
to:Benefits
Additional Notes