Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b877895
Native Endpoint Client Add Endpoints
QxBytes Jul 6, 2022
7f4ae0c
AddEndpointRules, ConfigureContainerInterfacesAndRoutes
QxBytes Jul 6, 2022
89b5f27
Changed interface names, log statements
QxBytes Jul 6, 2022
abb2bca
Renaming, using lib to set ns
QxBytes Jul 7, 2022
cb45749
Namespace "path" is /var/run/netns/<NS>
QxBytes Jul 8, 2022
079ebca
Loopback set up, Remove auto kernel subnet route
QxBytes Jul 8, 2022
5e0eb74
Cannot set link to up if it's in another NS
QxBytes Jul 8, 2022
3ad9b98
Multiple containers on same VNET NS
QxBytes Jul 11, 2022
29483f6
Delete Endpoint routes on Delete
QxBytes Jul 11, 2022
e776142
Minimizing netns usage
QxBytes Jul 11, 2022
11afe22
Moving NS Exec Code
QxBytes Jul 12, 2022
1f2c532
Further minimized netns.Set usage
QxBytes Jul 12, 2022
59b44a4
Moved helper methods down, drafted tests
QxBytes Jul 12, 2022
6c2f6c9
Removed DevName from Route Info, more tests
QxBytes Jul 12, 2022
0b1da85
Test existing vnet ns, delete endpoint
QxBytes Jul 13, 2022
0002583
NetNS interface for testing
QxBytes Jul 13, 2022
2f2ef3e
Separated tests by namespace
QxBytes Jul 13, 2022
1c916eb
Endpoints delete if they cannot be moved into NS
QxBytes Jul 14, 2022
5809293
Namespace netns tests
QxBytes Jul 14, 2022
95bbea7
Added Native Client to deleteEndpointImpl
QxBytes Jul 14, 2022
0d53e94
Deletion of Endpoints Impl and Tests
QxBytes Jul 15, 2022
6917681
Cleaned code (Tests ok)
QxBytes Jul 15, 2022
0e91d53
Moved mock/netns to package (Tests ok)
QxBytes Jul 18, 2022
66ea8a3
Fixing Netns (wip)
QxBytes Jul 18, 2022
0546d2b
Using errors.Wrap for error context (wip)
QxBytes Jul 18, 2022
f805465
Removed sentence case (wip)
QxBytes Jul 19, 2022
8ef521d
Removing variable predeclaration
QxBytes Jul 19, 2022
e8b45af
Removed NewNativeEndpointClient
QxBytes Jul 19, 2022
cc8bf9a
Removed generics from ExecuteInNS
QxBytes Jul 19, 2022
71f4566
Removed uintptr from mocknetns, tests compile
QxBytes Jul 19, 2022
3fb5df0
Fix tests, lint
QxBytes Jul 19, 2022
6a999f7
Fixes from linter
QxBytes Jul 19, 2022
147a7c9
Replacing references to ethX with vlan veth
QxBytes Jul 19, 2022
08c6ed5
Removed unnecessary log
QxBytes Jul 19, 2022
947a6a9
Removed unnecessary mac, fix tests
QxBytes Jul 19, 2022
e20522c
Mockns method name enum
QxBytes Jul 19, 2022
41abffa
Unable to use GetNetworkInterfaceByName due to NS
QxBytes Jul 19, 2022
8f3f2ab
Fixes from linter
QxBytes Jul 19, 2022
b5a0621
Assume if NS exists, vlan veth exists
QxBytes Jul 20, 2022
0726bfd
Fixes for Linter
QxBytes Jul 20, 2022
50d1f2b
Fix delete tests
QxBytes Jul 20, 2022
fe00e3a
Fix delete tests bug
QxBytes Jul 20, 2022
60ce070
Go mod tidy for linting
QxBytes Jul 20, 2022
f31e59f
No lint on vishvananda netns
QxBytes Jul 21, 2022
fd3341b
Build linux only for netns package
QxBytes Jul 21, 2022
92cff30
Remove nolint to see if linter fails
QxBytes Jul 21, 2022
d344df6
Moved netns interface to caller, generalized tests
QxBytes Jul 26, 2022
81c9886
Typos
QxBytes Jul 27, 2022
60bfc32
Reordered if statement, unwrapped arp
QxBytes Jul 27, 2022
dd06670
Renamed veth, fixed logs
QxBytes Aug 1, 2022
12cc662
Made deleteEndpoints logic clearer, renamed error
QxBytes Aug 1, 2022
64794e6
Renamed eth0 to primaryHostIfName, vlanEth to vlanIf
QxBytes Aug 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ require (
github.com/subosito/gotenv v1.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
github.com/vishvananda/netlink v1.2.1-beta.2
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,14 @@ github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 h1:cPXZWzzG0NllBLdjWoD1nDfaqu98YMv+OneaKc8sPOA=
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs=
github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
38 changes: 38 additions & 0 deletions netns/netns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//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")
}
73 changes: 58 additions & 15 deletions network/endpoint_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/netio"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/netns"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/ovsctl"
"github.com/Azure/azure-container-networking/platform"
Expand Down Expand Up @@ -89,21 +90,42 @@ func (nw *network) newEndpointImpl(_ apipaClient, nl netlink.NetlinkInterface, p
}

if vlanid != 0 {
log.Printf("OVS client")
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
nw.SnatBridgeIP = epInfo.Data[SnatBridgeIPKey].(string)
}
if nw.Mode == opModeNative {
log.Printf("Native client")
vlanVethName := fmt.Sprintf("%s.%d", nw.extIf.Name, vlanid)
vnetNSName := fmt.Sprintf("az_ns_%d", vlanid)

epClient = &NativeEndpointClient{
primaryHostIfName: nw.extIf.Name,
vlanIfName: vlanVethName,
vnetVethName: hostIfName,
containerVethName: contIfName,
vnetNSName: vnetNSName,
nw: nw,
vlanID: vlanid,
netnsClient: netns.New(),
netlink: nl,
netioshim: &netio.NetIO{},
plClient: plc,
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
}
} else {
log.Printf("OVS client")
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
nw.SnatBridgeIP = epInfo.Data[SnatBridgeIPKey].(string)
}

epClient = NewOVSEndpointClient(
nw,
epInfo,
hostIfName,
contIfName,
vlanid,
localIP,
nl,
ovsctl.NewOvsctl(),
plc)
epClient = NewOVSEndpointClient(
nw,
epInfo,
hostIfName,
contIfName,
vlanid,
localIP,
nl,
ovsctl.NewOvsctl(),
plc)
}
} else if nw.Mode != opModeTransparent {
log.Printf("Bridge client")
epClient = NewLinuxBridgeEndpointClient(nw.extIf, hostIfName, contIfName, nw.Mode, nl, plc)
Expand Down Expand Up @@ -239,7 +261,28 @@ func (nw *network) deleteEndpointImpl(nl netlink.NetlinkInterface, plc platform.
// entering the container netns and hence works both for CNI and CNM.
if ep.VlanID != 0 {
epInfo := ep.getInfo()
epClient = NewOVSEndpointClient(nw, epInfo, ep.HostIfName, "", ep.VlanID, ep.LocalIP, nl, ovsctl.NewOvsctl(), plc)
if nw.Mode == opModeNative {
log.Printf("Native client")
vlanVethName := fmt.Sprintf("%s.%d", nw.extIf.Name, ep.VlanID)
vnetNSName := fmt.Sprintf("az_ns_%d", ep.VlanID)

epClient = &NativeEndpointClient{
primaryHostIfName: nw.extIf.Name,
vlanIfName: vlanVethName,
vnetVethName: ep.HostIfName,
containerVethName: "",
vnetNSName: vnetNSName,
nw: nw,
vlanID: ep.VlanID,
netnsClient: netns.New(),
netlink: nl,
netioshim: &netio.NetIO{},
plClient: plc,
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
}
} else {
epClient = NewOVSEndpointClient(nw, epInfo, ep.HostIfName, "", ep.VlanID, ep.LocalIP, nl, ovsctl.NewOvsctl(), plc)
}
} else if nw.Mode != opModeTransparent {
epClient = NewLinuxBridgeEndpointClient(nw.extIf, ep.HostIfName, "", nw.Mode, nl, plc)
} else {
Expand Down
2 changes: 1 addition & 1 deletion network/hnswrapper/hnsv1wrapper.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build windows
//+build windows
// +build windows

package hnswrapper

Expand Down
2 changes: 1 addition & 1 deletion network/hnswrapper/hnsv1wrapperinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ type HnsV1WrapperInterface interface {
GetHNSEndpointByID(endpointID string) (*hcsshim.HNSEndpoint, error)
HotAttachEndpoint(containerID string, endpointID string) error
IsAttached(hnsep *hcsshim.HNSEndpoint, containerID string) (bool, error)
GetHNSGlobals() (*hcsshim.HNSGlobals, error)
GetHNSGlobals() (*hcsshim.HNSGlobals, error)
}
2 changes: 1 addition & 1 deletion network/hnswrapper/hnsv2wrapperfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewHnsv2wrapperFake() *Hnsv2wrapperFake {
}
}

func delayHnsCall(delay time.Duration){
func delayHnsCall(delay time.Duration) {
time.Sleep(delay)
}

Expand Down
Loading