Skip to content

Commit 69fde1c

Browse files
tamilmani1989sharmasushant
authored andcommitted
changed vethnaming logic for transparent mode (#286)
1 parent e98936c commit 69fde1c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

cni/network/network.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
// Plugin name.
2626
name = "azure-vnet"
2727
dockerNetworkOption = "com.docker.network.generic"
28-
28+
opModeTransparent = "transparent"
2929
// Supported IP version. Currently support only IPv4
3030
ipVersion = "4"
3131
)
@@ -454,9 +454,16 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
454454

455455
SetupRoutingForMultitenancy(nwCfg, cnsNetworkConfig, azIpamResult, epInfo, result)
456456

457-
// A runtime must not call ADD twice (without a corresponding DEL) for the same
458-
// (network name, container id, name of the interface inside the container)
459-
vethName = fmt.Sprintf("%s%s%s", networkId, k8sContainerID, k8sIfName)
457+
if nwCfg.Mode == opModeTransparent {
458+
// this mechanism of using only namespace and name is not unique for different incarnations of POD/container.
459+
// IT will result in unpredictable behavior if API server decides to
460+
// reorder DELETE and ADD call for new incarnation of same POD.
461+
vethName = fmt.Sprintf("%s.%s", k8sNamespace, k8sPodName)
462+
} else {
463+
// A runtime must not call ADD twice (without a corresponding DEL) for the same
464+
// (network name, container id, name of the interface inside the container)
465+
vethName = fmt.Sprintf("%s%s%s", networkId, k8sContainerID, k8sIfName)
466+
}
460467
setEndpointOptions(cnsNetworkConfig, epInfo, vethName)
461468

462469
// Create the endpoint.

network/endpoint_linux.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
6868
}
6969

7070
if _, ok := epInfo.Data[OptVethName]; ok {
71-
log.Printf("Generate veth name based on the key provided")
7271
key := epInfo.Data[OptVethName].(string)
72+
log.Printf("Generate veth name based on the key provided %v", key)
7373
vethname := generateVethName(key)
7474
hostIfName = fmt.Sprintf("%s%s", hostVEthInterfacePrefix, vethname)
7575
contIfName = fmt.Sprintf("%s%s2", hostVEthInterfacePrefix, vethname)
@@ -270,8 +270,18 @@ func deleteRoutes(interfaceName string, routes []RouteInfo) error {
270270

271271
if route.DevName != "" {
272272
devIf, _ := net.InterfaceByName(route.DevName)
273+
if devIf == nil {
274+
log.Printf("[net] Not deleting route. Interface %v doesn't exist", interfaceName)
275+
continue
276+
}
277+
273278
ifIndex = devIf.Index
274279
} else {
280+
if interfaceIf == nil {
281+
log.Printf("[net] Not deleting route. Interface %v doesn't exist", interfaceName)
282+
continue
283+
}
284+
275285
ifIndex = interfaceIf.Index
276286
}
277287

network/transparent_endpointclient_linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func setArpProxy(ifName string) error {
5252
}
5353

5454
func (client *TransparentEndpointClient) AddEndpoints(epInfo *EndpointInfo) error {
55+
56+
if _, err := net.InterfaceByName(client.hostVethName); err == nil {
57+
log.Printf("Deleting old host veth %v", client.hostVethName)
58+
if err = netlink.DeleteLink(client.hostVethName); err != nil {
59+
log.Printf("[net] Failed to delete old hostveth %v: %v.", client.hostVethName, err)
60+
return err
61+
}
62+
}
63+
5564
if err := epcommon.CreateEndpoint(client.hostVethName, client.containerVethName); err != nil {
5665
return err
5766
}

0 commit comments

Comments
 (0)