-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Better interface selection heuristic #3546
Merged
Merged
Changes from 2 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"log" | ||
"net" | ||
|
||
sockaddr "github.com/hashicorp/go-sockaddr" | ||
"github.com/hashicorp/nomad/client/config" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
@@ -167,47 +168,25 @@ func (f *NetworkFingerprint) createNetworkResources(throughput int, intf *net.In | |
return nwResources, nil | ||
} | ||
|
||
// Checks if the device is marked UP by the operator | ||
func (f *NetworkFingerprint) isDeviceEnabled(intf *net.Interface) bool { | ||
return intf.Flags&net.FlagUp != 0 | ||
} | ||
|
||
// Checks if the device has any IP address configured | ||
func (f *NetworkFingerprint) deviceHasIpAddress(intf *net.Interface) bool { | ||
addrs, err := f.interfaceDetector.Addrs(intf) | ||
return err == nil && len(addrs) != 0 | ||
} | ||
|
||
func (n *NetworkFingerprint) isDeviceLoopBackOrPointToPoint(intf *net.Interface) bool { | ||
return intf.Flags&(net.FlagLoopback|net.FlagPointToPoint) != 0 | ||
} | ||
|
||
// Returns the interface with the name passed by user | ||
// If the name is blank then it iterates through all the devices | ||
// and finds one which is routable and marked as UP | ||
// It excludes PPP and lo devices unless they are specifically asked | ||
// Returns the interface with the name passed by user. If the name is blank, we | ||
// use the interface attached to the default route. | ||
func (f *NetworkFingerprint) findInterface(deviceName string) (*net.Interface, error) { | ||
var interfaces []net.Interface | ||
var err error | ||
|
||
if deviceName != "" { | ||
return f.interfaceDetector.InterfaceByName(deviceName) | ||
} | ||
|
||
var intfs []net.Interface | ||
|
||
if intfs, err = f.interfaceDetector.Interfaces(); err != nil { | ||
return nil, err | ||
} | ||
// If we aren't given a device, look it up by using the interface with the default route | ||
if deviceName == "" { | ||
ri, err := sockaddr.NewRouteInfo() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, intf := range intfs { | ||
if f.isDeviceEnabled(&intf) && !f.isDeviceLoopBackOrPointToPoint(&intf) && f.deviceHasIpAddress(&intf) { | ||
interfaces = append(interfaces, intf) | ||
defaultIfName, err := ri.GetDefaultInterfaceName() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if defaultIfName == "" { | ||
return nil, fmt.Errorf("no network_interface given and failed to determine interface attached to default route") | ||
} | ||
deviceName = defaultIfName | ||
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. Much nicer now 👍 |
||
} | ||
|
||
if len(interfaces) == 0 { | ||
return nil, nil | ||
} | ||
return &interfaces[0], nil | ||
return f.interfaceDetector.InterfaceByName(deviceName) | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -49,11 +49,12 @@ client { | |
- `meta` `(map[string]string: nil)` - Specifies a key-value map that annotates | ||
with user-defined metadata. | ||
|
||
- `network_interface` `(string: "lo | lo0")` - Specifies the name of the | ||
interface to force network fingerprinting on. This defaults to the loopback | ||
interface. All addresses on the interface are fingerprinted except the ones | ||
which are scoped local for IPv6. When allocating ports for tasks, the | ||
scheduler will choose from the IPs of the fingerprinted interface. | ||
- `network_interface` `(string: varied)` - Specifies the name of the interface | ||
to force network fingerprinting on. When run in dev mode, this is defaulted | ||
to the machine's loopback interface. If not in dev mode, the interface attached | ||
to the default route is used. All addresses on the interface are fingerprinted | ||
except those that are scoped local for IPv6. When allocating ports for tasks, | ||
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. suggesting a small rewrite for brevity and continuity.
|
||
the scheduler will choose from the IPs of the fingerprinted interface. | ||
|
||
- `network_speed` `(int: 0)` - Specifies an override for the network link speed. | ||
This value, if set, overrides any detected or defaulted link speed. Most | ||
|
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.
🤔 We could
WARN
andcontinue
here, but after peeking at theAddrs(...)
code it seems like all of the errors it returns indicate pretty bad syscall failures. Seems like just bailing is probably safest as users can manually set this anyway.