-
Notifications
You must be signed in to change notification settings - Fork 10
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
add ipv6 support to update-ips #2450
Conversation
458dd44
to
63a2874
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.
Nice work! The changes look good but since the number of kubectl
and dig
calls have changed you will have to update the mocked kubectl
and dig
calls in the tests.
I would like to see tests for both with and without ipv6 results as well.
bin/update-ips.bash
Outdated
@@ -294,13 +324,17 @@ process_ips_to_cidrs() { | |||
|
|||
for ip in "${@}"; do | |||
for cidr in "${old_cidrs[@]}"; do | |||
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ .*/32 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then | |||
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ .*/32 ]] && ! [[ "${cidr}" =~ .*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then |
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.
Is this going to do the right thing with an IPv6 address like 2001:db8::/32
?
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.
It should stay the way it is.
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 mean, when cidr=2001:db8::/32
then ! [[ "${cidr}" =~ .*/32 ]]
→ ! [[ /32 == /32 ]]
→ ! true
→ false
and then the condition stops there. I assume that's only meant to happen for IPv4 /32
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.
Hmm... I might be missing the issue here, but wouldn't that mean that the cidr just doesn't get processed, and therefore it gets added the way it is, which i think the behavior we want at that point ?
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.
given old_cidrs=(127.0.0.0/8 2001:db8::/32 fe80::/10)
and ips=(127.0.0.1 2001:db8::1 fe80::d309:087a:7c4f:3aaf)
the function outputs
0.0.0.0/0
2001:db8::1/128
fe80::/10
wouldn't the expected be
0.0.0.0/0
2001:db8::/32
fe80::/10
?
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.
Yes, this is wrong. This should catch single IP CIDRs only, with the introduction of IPv6 .*/32
is not doing that anymore.
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 like this
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ .*/32 ]] && ! [[ "${cidr}" =~ .*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then | |
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ [0-9.]*/32 ]] && ! [[ "${cidr}" =~ [0-9a-f:]*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then |
Alternatively, but probably more work, only dealing with IPv6-mapped IPv4 addresses would need only a single /128
comparison.
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.
That looks good, will add it.
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.
Just minor things left to fix up, nice work!
I would have liked to see a test of maximal run dualStack
as well but if you feel that you are about to claw your eyes out seeing another bats run then I'm fine with you skipping it for now. 😄 There is some work needed to be done here to make it easier to test.
bin/update-ips.bash
Outdated
@@ -294,13 +329,17 @@ process_ips_to_cidrs() { | |||
|
|||
for ip in "${@}"; do | |||
for cidr in "${old_cidrs[@]}"; do | |||
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ .*/32 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then | |||
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ [0-9.].*/32 ]] && ! [[ "${cidr}" =~ [0-9a-f:].*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then |
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.
[0-9.].*
only ensures the first thing is a number or .
, while [0-9.]*
only matches numbers and literal .
.
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ [0-9.].*/32 ]] && ! [[ "${cidr}" =~ [0-9a-f:].*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then | |
if [[ "${cidr}" != "" ]] && [[ "${cidr}" != "set-me" ]] && ! [[ "${cidr}" =~ [0-9.]*/32 ]] && ! [[ "${cidr}" =~ [0-9a-f:]*/128 ]] && check_ip_in_cidr "${ip}" "${cidr}"; then |
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.
After you have fixed the thing pointed out by @Zash this LGTM, great work!
Warning
This is a public repository, ensure not to disclose:
What kind of PR is this?
Required: Mark one of the following that is applicable:
Optional: Mark one or more of the following that are applicable:
Important
Breaking changes should be marked
kind/admin-change
orkind/dev-change
depending on typeCritical security fixes should be marked with
kind/security
What does this PR do / why do we need this PR?
Adds support for IPv6 to update-ips script.
update-ips
script #2342Information to reviewers
Checklist