-
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
support add veth pairs #10
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10 +/- ##
==========================================
- Coverage 80.82% 75.21% -5.61%
==========================================
Files 3 4 +1
Lines 73 117 +44
==========================================
+ Hits 59 88 +29
- Misses 12 20 +8
- Partials 2 9 +7
Continue to review full report at Codecov.
|
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.
Add the testing for
- makeVethPair
- invalid link name
- invalid MTU value
- SetupVeth
-
Invalid NS Object
-
invalid
link/link_test.go
Outdated
|
||
assert.Equal(t, "test-veth-ns1", contVeth.Attrs().Name) | ||
assert.Equal(t, 1500, contVeth.Attrs().MTU) | ||
defer netlink.LinkDel(contVeth) |
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.
Move this to line 17, we usually call the defer remove..
after we create that resoruce
link/link_test.go
Outdated
contVeth, err := makeVethPair("invalid-test-veth-ns1", "invalid-test-ovs-1", -1800) | ||
// Err: numerical result out of range | ||
assert.Error(t, err) | ||
defer netlink.LinkDel(contVeth) |
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
}) | ||
hostVeth, err := netlink.LinkByName(hostVethName) | ||
assert.NoError(t, err) | ||
defer netlink.LinkDel(hostVeth) |
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
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 case should delete link outside the netns.Do
since defer
will be executed at the end of the enclosing function (func(hostNS ns.NetNS) 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.
got it
@@ -25,7 +25,7 @@ before_install: | |||
- make pb | |||
|
|||
script: | |||
- sudo -E env PATH=$PATH TEST_OVS=1 gotestcover -coverprofile=coverage.txt -covermode=atomic ./... | |||
- sudo -E env PATH=$PATH TEST_OVS=1 TEST_VETH=1 gotestcover -coverprofile=coverage.txt -covermode=atomic ./... |
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.
Also add the TEST_VETH to Makefile's target test
func SetupVeth(contVethName, hostVethName string, mtu int, hostNS ns.NetNS) (net.Interface, net.Interface, error) { | ||
contVeth, err := makeVethPair(contVethName, hostVethName, mtu) | ||
if err != nil { | ||
return net.Interface{}, net.Interface{}, err |
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.
What about changing the type of returning values to pointer and this line will be return nil, nil, err
?
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 want to keep origin source code. https://github.com/containernetworking/plugins/blob/master/pkg/ip/link_linux.go#L131
Fork and modify from
containernetworking/plugins
support to create veth pairs. Given the container's vethName, host's VethName, mtu and host network namespace.APIs
makeVethPair(name, peer string, mtu int)
is equivalentveth name: veth-ns1
peer name: ovs-1
ip link add name veth-ns1 type veth peer name ovs-1
SetupVeth(contVethName, hostVethName string, mtu int, hostNS ns.NetNS)
is equivalentnetwork namespace name: ns1
veth name: veth-ns1
peer name: ovs-1