-
Notifications
You must be signed in to change notification settings - Fork 228
Refactor: Use the netlink
library instead of exec'ing out to ip
#279
Conversation
docs/cli/ignite/ignite_create.md
Outdated
@@ -14,8 +14,9 @@ the flags for this command. | |||
|
|||
If the name flag (-n, --name) is not specified, | |||
the VM is given a random name. Using the copy files | |||
flag (-f, --copy-files), additional files can be added to | |||
the VM during creation with the syntax /host/path:/vm/path. | |||
flag (-f, --copy-files), additional files/directories |
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.
make tidy
added this?
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, that's fine to include here, just forgot to update the docs in an earlier PR where I changed this 😅
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.
Great work @alexeldeib! 🎉
I added some minor design changes that will simplify the code and prevent excess lookups by interface names. After those have been addressed, looks like we're ready to merge!
docs/cli/ignite/ignite_create.md
Outdated
@@ -14,8 +14,9 @@ the flags for this command. | |||
|
|||
If the name flag (-n, --name) is not specified, | |||
the VM is given a random name. Using the copy files | |||
flag (-f, --copy-files), additional files can be added to | |||
the VM during creation with the syntax /host/path:/vm/path. | |||
flag (-f, --copy-files), additional files/directories |
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, that's fine to include here, just forgot to update the docs in an earlier PR where I changed this 😅
pkg/container/network.go
Outdated
return err | ||
} | ||
|
||
return setLinkUp(tapName) | ||
return setLinkUp(handle, tapName) |
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 should likely call handle.LinkSetUp(tuntap)
here and get rid of setLinkUp
entirely
pkg/container/network.go
Outdated
return err | ||
} | ||
|
||
return setLinkUp(bridgeName) | ||
return handle.LinkSetUp(bridge) |
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 like this, we don't need setLinkUp
anymore
pkg/container/network.go
Outdated
func setLinkUp(adapterName string) error { | ||
_, err := util.ExecuteCommand("ip", "link", "set", adapterName, "up") | ||
return err | ||
func setLinkUp(handle *netlink.Handle, adapterName string) error { |
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.
Can be removed in favor of handle.LinkSetUp
pkg/container/network.go
Outdated
la.Name = bridgeName | ||
bridge := &netlink.Bridge{LinkAttrs: la} | ||
err := netlink.LinkAdd(bridge) | ||
if err != nil { |
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.
Concatenate into if err := netlink.LinkAdd(bridge); err != nil {
pkg/container/network.go
Outdated
return nil, err | ||
} | ||
|
||
if err := createBridge(bridgeName); err != nil { | ||
if err := createBridge(handle, bridgeName); err != nil { |
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.
Return the *netlink.Bridge
from createBridge
pkg/container/network.go
Outdated
return nil, err | ||
} | ||
|
||
if err := createTAPAdapter(handle, tapName); err != nil { |
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.
Return the *netlink.Tuntap
from createTAPAdapter
pkg/container/network.go
Outdated
return nil, err | ||
} | ||
|
||
if err := connectAdapterToBridge(tapName, bridgeName); err != nil { | ||
if err := connectAdapterToBridge(handle, tapName, bridgeName); err != nil { |
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.
Using the Bridge
and Tuntap
devices returned above, call handle.LinkSetMaster
here instead of connectAdapterToBridge
pkg/container/network.go
Outdated
return nil, err | ||
} | ||
|
||
if err := connectAdapterToBridge(iface.Name, bridgeName); err != nil { | ||
if err := connectAdapterToBridge(handle, iface.Name, bridgeName); err != nil { |
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.
Same as above, use netlink.LinkByName(iface.Name)
to retrieve the device for handle.LinkSetMaster
pkg/container/network.go
Outdated
func connectAdapterToBridge(adapterName, bridgeName string) error { | ||
_, err := util.ExecuteCommand("ip", "link", "set", adapterName, "master", bridgeName) | ||
return err | ||
func connectAdapterToBridge(handle *netlink.Handle, adapterName, bridgeName string) error { |
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.
Can be removed in favor of calling handle.LinkSetMaster
directly
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 very much for this contribution @alexeldeib 🎉!
Very appreciated. Sorry that the master branch had some outstanding issues
with the doc generation, something I just fixed at HEAD.
When you rebase those unnecessary changes should go away.
a9cb096
to
cbd2183
Compare
Hmm...something in this PR breaks |
oh, several things broke it! 😄 Should be better now. |
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 changes @alexeldeib!
LGTM 👍
netlink
library instead of exec'ing out to ip
Fixes #85