-
Notifications
You must be signed in to change notification settings - Fork 3
agent: don't discard network status on IPv4-only route lookup failure #233
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
Open
sebastian-pf9
wants to merge
1
commit into
main
Choose a base branch
from
claude/byoh-ipv6-gaps-0a5ef2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ package registration | |
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
|
|
@@ -14,6 +15,26 @@ import ( | |
| infrastructurev1beta1 "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/apis/infrastructure/v1beta1" | ||
| ) | ||
|
|
||
| func noDefaultRoute() (net.IP, error) { | ||
| return nil, fmt.Errorf("no default route") | ||
| } | ||
|
|
||
| func fixedDefaultRoute(ip string) func() (net.IP, error) { | ||
| return func() (net.IP, error) { return net.ParseIP(ip), nil } | ||
| } | ||
|
|
||
| func fakeInterfaces(ifaces []netInterface, err error) func() ([]netInterface, error) { | ||
| return func() ([]netInterface, error) { return ifaces, err } | ||
| } | ||
|
|
||
| func addrOf(ip string) net.Addr { | ||
| parsed := net.ParseIP(ip) | ||
| if parsed.To4() != nil { | ||
| return &net.IPNet{IP: parsed, Mask: net.CIDRMask(24, 32)} | ||
| } | ||
| return &net.IPNet{IP: parsed, Mask: net.CIDRMask(64, 128)} | ||
| } | ||
|
|
||
| func getMockFile(targetOs string) ([]byte, error) { | ||
| out := fmt.Sprintf(`NAME="Ubuntu" | ||
| VERSION="20.04.4 LTS (Focal Fossa)" | ||
|
|
@@ -107,6 +128,70 @@ var _ = Describe("Host Registrar Tests", func() { | |
| }) | ||
| }) | ||
|
|
||
| Context("When computing network status", func() { | ||
| It("Should mark the default interface via an IPv4 default route", func() { | ||
| hr := HostRegistrar{} | ||
| ifaces := []netInterface{ | ||
| {Name: "eth0", Flags: net.FlagUp, MACAddr: "aa:bb:cc:dd:ee:ff", Addrs: []net.Addr{addrOf("192.168.1.10")}}, | ||
| } | ||
| status := hr.getNetworkStatus(fixedDefaultRoute("192.168.1.10"), noDefaultRoute, fakeInterfaces(ifaces, nil)) | ||
|
|
||
| Expect(status).To(HaveLen(1)) | ||
| Expect(status[0].IsDefault).To(BeTrue()) | ||
| Expect(hr.ByoHostInfo.DefaultNetworkInterfaceName).To(Equal("eth0")) | ||
| }) | ||
|
|
||
| It("Should mark the default interface via an IPv6-only default route", func() { | ||
| hr := HostRegistrar{} | ||
| ifaces := []netInterface{ | ||
| {Name: "eth0", Flags: net.FlagUp, MACAddr: "aa:bb:cc:dd:ee:ff", Addrs: []net.Addr{addrOf("2001:db8::10")}}, | ||
| } | ||
| status := hr.getNetworkStatus(noDefaultRoute, fixedDefaultRoute("2001:db8::10"), fakeInterfaces(ifaces, nil)) | ||
|
|
||
| Expect(status).To(HaveLen(1)) | ||
| Expect(status[0].IsDefault).To(BeTrue()) | ||
| Expect(hr.ByoHostInfo.DefaultNetworkInterfaceName).To(Equal("eth0")) | ||
| }) | ||
|
|
||
| It("Should mark the default interface on a dual-stack host via either family's route", func() { | ||
| hr := HostRegistrar{} | ||
| ifaces := []netInterface{ | ||
| { | ||
| Name: "eth0", | ||
| Flags: net.FlagUp, | ||
| MACAddr: "aa:bb:cc:dd:ee:ff", | ||
| Addrs: []net.Addr{addrOf("192.168.1.10"), addrOf("2001:db8::10")}, | ||
| }, | ||
| } | ||
| status := hr.getNetworkStatus(fixedDefaultRoute("192.168.1.10"), fixedDefaultRoute("2001:db8::10"), fakeInterfaces(ifaces, nil)) | ||
|
|
||
| Expect(status).To(HaveLen(1)) | ||
| Expect(status[0].IsDefault).To(BeTrue()) | ||
| Expect(status[0].IPAddrs).To(ConsistOf("192.168.1.10/24", "2001:db8::10/64")) | ||
| Expect(hr.ByoHostInfo.DefaultNetworkInterfaceName).To(Equal("eth0")) | ||
| }) | ||
|
|
||
| It("Should still report interfaces when neither family has a default route", func() { | ||
| hr := HostRegistrar{} | ||
| ifaces := []netInterface{ | ||
| {Name: "eth0", Flags: net.FlagUp, MACAddr: "aa:bb:cc:dd:ee:ff", Addrs: []net.Addr{addrOf("2001:db8::10")}}, | ||
| } | ||
| status := hr.getNetworkStatus(noDefaultRoute, noDefaultRoute, fakeInterfaces(ifaces, nil)) | ||
|
|
||
| Expect(status).To(HaveLen(1)) | ||
| Expect(status[0].IsDefault).To(BeFalse()) | ||
| Expect(status[0].IPAddrs).To(ConsistOf("2001:db8::10/64")) | ||
| Expect(hr.ByoHostInfo.DefaultNetworkInterfaceName).To(BeEmpty()) | ||
| }) | ||
|
|
||
| It("Should return an empty status when interface enumeration itself fails", func() { | ||
| hr := HostRegistrar{} | ||
| status := hr.getNetworkStatus(fixedDefaultRoute("192.168.1.10"), noDefaultRoute, fakeInterfaces(nil, fmt.Errorf("boom"))) | ||
|
|
||
| Expect(status).To(BeEmpty()) | ||
| }) | ||
| }) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please rewrite this as table driven non-ginkgo unit tests? I find this format time consuming in terms of evaluating all the test cases. |
||
|
|
||
| Context("When the OS family is detected", func() { | ||
| It("Should return debian when dpkg is on PATH", func() { | ||
| family := GetOSFamily(func(file string) (string, error) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
This feels like an anti pattern. I think
GetNetowrkStatusshould accept an interface (Go, not network interface). And the implementations of the interface are something like: