feat: Add native linux endpoint client to prep removing OVS (#1471)
* Native Endpoint Client Add Endpoints
* AddEndpointRules, ConfigureContainerInterfacesAndRoutes
* Changed interface names, log statements
nw.extIf.Name > eth0 (eth0)
eth0.vlanid > eth0.X (eth0.1)
%s%s hostIfName > vnet (A1veth0)
%s%s-2 contIfName > container (B1veth0)
* Renaming, using lib to set ns
* Namespace "path" is /var/run/netns/<NS>
* Loopback set up, Remove auto kernel subnet route
* Cannot set link to up if it's in another NS
* Multiple containers on same VNET NS
* Delete Endpoint routes on Delete
* Minimizing netns usage
* Moving NS Exec Code
* Further minimized netns.Set usage
* Moved helper methods down, drafted tests
* Removed DevName from Route Info, more tests
* Test existing vnet ns, delete endpoint
* NetNS interface for testing
* Separated tests by namespace
* Endpoints delete if they cannot be moved into NS
* Namespace netns tests
* Added Native Client to deleteEndpointImpl
* Deletion of Endpoints Impl and Tests
* Cleaned code (Tests ok)
* Moved mock/netns to package (Tests ok)
* Fixing Netns (wip)
Moved netnsinterface to consumer package (network).
Removed "Netns" from "NewNetns" and "NewMockNetns" as it is unambiguous.
Changed uintptr to int and casted the int to uintptr when needed later.
* Using errors.Wrap for error context (wip)
* Removed sentence case (wip)
* Removing variable predeclaration
* Removed NewNativeEndpointClient
Directly instantiating struct because nothing special happens in NewNativeEndpointClient
* Removed generics from ExecuteInNS
* Removed uintptr from mocknetns, tests compile
Forgot to remove uintptr from mocknetns
* Fix tests, lint
* Fixes from linter
Works on VMSS
* Replacing references to ethX with vlan veth
* Removed unnecessary log
* Removed unnecessary mac, fix tests
* Mockns method name enum
* Unable to use GetNetworkInterfaceByName due to NS
If I use GetNetworkInterface, I need to be in the vnet NS, but that means I will need to call ExecuteInNS, which causes tests to fail.
* Fixes from linter
* Assume if NS exists, vlan veth exists
Tests ok
* Fixes for Linter
* Fix delete tests
* Fix delete tests bug
* Go mod tidy for linting
Hopefully this fixes the windows lint error
* No lint on vishvananda netns
Maybe this will fix the windows linter?
* Build linux only for netns package
Maybe this fixes the linter error?
* Remove nolint to see if linter fails
* Moved netns interface to caller, generalized tests
Tests ok, Native ok
* Typos
* Reordered if statement, unwrapped arp
Tests ok, ping ok, wget ok
* Renamed veth, fixed logs
* Made deleteEndpoints logic clearer, renamed error
* Renamed eth0 to primaryHostIfName, vlanEth to vlanIf
2022-08-03 00:54:10 +03:00
|
|
|
//go:build linux
|
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package netns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/vishvananda/netns"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Netns struct{}
|
|
|
|
|
|
|
|
func New() *Netns {
|
|
|
|
return &Netns{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) Get() (int, error) {
|
|
|
|
nsHandle, err := netns.Get()
|
|
|
|
return int(nsHandle), errors.Wrap(err, "netns impl")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) GetFromName(name string) (int, error) {
|
|
|
|
nsHandle, err := netns.GetFromName(name)
|
|
|
|
return int(nsHandle), errors.Wrap(err, "netns impl")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) Set(fileDescriptor int) error {
|
|
|
|
return errors.Wrap(netns.Set(netns.NsHandle(fileDescriptor)), "netns impl")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) NewNamed(name string) (int, error) {
|
|
|
|
nsHandle, err := netns.NewNamed(name)
|
|
|
|
return int(nsHandle), errors.Wrap(err, "netns impl")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) DeleteNamed(name string) error {
|
|
|
|
return errors.Wrap(netns.DeleteNamed(name), "netns impl")
|
|
|
|
}
|
2023-04-18 00:26:00 +03:00
|
|
|
|
|
|
|
func (f *Netns) IsNamespaceEqual(fd1, fd2 int) bool {
|
|
|
|
return netns.NsHandle(fd1).Equal(netns.NsHandle(fd2))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Netns) NamespaceUniqueID(fd int) string {
|
|
|
|
return netns.NsHandle(fd).UniqueId()
|
|
|
|
}
|