-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(#23388): Add a preferred address family option for network-interface #23389
Conversation
As some services might not support IPv6, nomad needs a way to expose service on IPv4 instead of IPv6
Hi @guifran001, thank you for the PR! We have a near-term priority on evaluating and improving IPv6 in Nomad, so your contribution is timely. :)
I do think this is preferable, because some users/environments may actually want to use IPv6, which in some cases is hard to accomplish at the moment. I'd suggest validating that the user input is one of these two constants: https://github.com/hashicorp/nomad/blob/v1.8.1/nomad/structs/structs.go#L2728-L2729 to be able to error early on bad input before the client agent gets up and running. It looks like you have already found the constant(s), since you check for one here. If the value is an empty string, we should default to the current behavior. Aside from that, I think most of your approach would only need minor tweaking. Let me know how it goes, and if you'd like any assistance with it! |
Removed ignore-ipv6 option and add this option instead has it allows to specifically use IPv6 too
Hi @gulducat, I have refactor to add a I have sorted both Tell me if it makes sense or if you want me to refactor / improve my code. |
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.
Hey thanks! I have this on my list to review more thoroughly soon. So far I've only kicked the tires a bit to see the scope of what's covered here, found a couple little discrepancies. I'll get back to you sometime this week with more details!
Co-authored-by: Daniel Bennett <dbennett@hashicorp.com>
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.
Hey this is great, thanks! I have just a few comments for ya.
I'm going to be out most of next week, so I might not be able to get back to you until after that. If you make changes before then, I'll try to pass to a teammate, or if you're ok waiting then I will check in after I get back!
Removed relic of the past Added unit test Improve readibility and remove duplicated code
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 the review. I was in an hurry when I did it. Sorry for all the relics that were still there
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.
Huge improvement! And almost done, I think. Just need a little documentation, a concern with the test, and one of the relics is still hanging around.
client/fingerprint/network_test.go
Outdated
if strings.ToUpper(net.CIDR) == strings.ToUpper(tc.expectedCIDR) { | ||
t.Errorf("Expected CIDR %s; got %s", tc.expectedCIDR, net.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.
Wouldn't this be an error if the CIDR
s are not equal? also the error output shows net.IP
which confused me for a sec.
if strings.ToUpper(net.CIDR) == strings.ToUpper(tc.expectedCIDR) { | |
t.Errorf("Expected CIDR %s; got %s", tc.expectedCIDR, net.IP) | |
if strings.ToUpper(net.CIDR) != strings.ToUpper(tc.expectedCIDR) { | |
t.Errorf("Expected CIDR %s; got %s", tc.expectedCIDR, net.CIDR) |
that causes the test to fail:
=== RUN TestNetworkFingerPrint_default_device/Loopback_IPv6
network_test.go:343: Expected CIDR 2001:DB8::/48; got 2001:db8::/128
=== RUN TestNetworkFingerPrint_default_device/Loopback_IPv4
network_test.go:343: Expected CIDR 127.0.0.1/8; got 127.0.0.0/32
=== RUN TestNetworkFingerPrint_default_device/Loopback_No_preferred_address_family
network_test.go:343: Expected CIDR 2001:DB8::/48; got 2001:db8::/128
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 catch!
I'm a bit confused about how CIDR 127.0.0.1/8
result in IP address 127.0.0.0
instead of 127.0.0.1
I'm going to compare the IP instead of the CIDR. In the end, we want to make sure they are on the expected family.
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.
looks like 127.0.0.0
is coming from the test NetworkInterfaceDetectorOnlyLo
's usage of net.ParseCIDR
It returns the IP address and the network implied by the IP and prefix length. For example, ParseCIDR("192.0.2.1/24") returns the IP address 192.0.2.1 and the network 192.0.2.0/24.
the mockish test interface implementation is only using the IPNet
and discarding IP
.
I agree using the IP for this test is fine, since it does confirm the by-family sorting behavior we're expecting to see. 👍
- Fix a bug in a unit test: comparison was inverted and it was hiding another bug - add preferred_address_family option documentation - remove relics
This looks great @guifran001! Just one more bit of bookkeeping that I forgot to mention: In the repo root, run
(or something like that) Then I'll merge this in, so it can go out with the 1.8.2 release soon! |
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.
Thanks for the contribution @guifran001! 🎉
As some services might not support IPv6, nomad
needs a way to expose service on IPv4 instead of IPv6
see #23388 for more details
This pr adds a
ignore-ipv6
option to nomad to ignore IPv6 addresses.If preferred, I could change to code to add a
-preferred-ip-family
instead.