Skip to content

Commit b3b4b47

Browse files
committed
proactively clean up leaked vnet and container veths in vm ns before creating new veth pair
1 parent 969e8e0 commit b3b4b47

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

network/transparent_vlan_endpointclient_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ func (client *TransparentVlanEndpointClient) PopulateVM(epInfo *EndpointInfo) er
310310
logger.Info("Failed to parse the mac address", zap.String("defaultHostVethHwAddr", defaultHostVethHwAddr))
311311
}
312312

313+
// Proactively clean up any leftover veth interfaces before creating new ones
314+
if err := client.netlink.DeleteLink(client.vnetVethName); err != nil {
315+
logger.Info("Could not proactively clean up vnet veth (expected if not present)",
316+
zap.String("vnetVethName", client.vnetVethName), zap.Error(err))
317+
}
318+
if err := client.netlink.DeleteLink(client.containerVethName); err != nil {
319+
logger.Info("Could not proactively clean up container veth (expected if not present)",
320+
zap.String("containerVethName", client.containerVethName), zap.Error(err))
321+
}
322+
313323
// Create veth pair
314324
if err = client.netUtilsClient.CreateEndpoint(client.vnetVethName, client.containerVethName, mac); err != nil {
315325
return errors.Wrap(err, "failed to create veth pair")

network/transparent_vlan_endpointclient_linux_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ func TestTransparentVlanAddEndpoints(t *testing.T) {
344344
set: defaultSet,
345345
deleteNamed: defaultDeleteNamed,
346346
},
347-
netlink: netlink.NewMockNetlink(false, ""),
347+
netlink: &netlink.MockNetlink{
348+
DeleteLinkFn: func(name string) error {
349+
// should still succeed
350+
return netlink.ErrorMockNetlink
351+
},
352+
},
348353
plClient: platform.NewMockExecClient(false),
349354
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
350355
netioshim: netio.NewMockNetIO(false, 0),

0 commit comments

Comments
 (0)