Skip to content

Commit

Permalink
changed vethnaming logic for transparent mode (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamilmani1989 authored and sharmasushant committed Jan 10, 2019
1 parent e98936c commit 69fde1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// Plugin name.
name = "azure-vnet"
dockerNetworkOption = "com.docker.network.generic"

opModeTransparent = "transparent"
// Supported IP version. Currently support only IPv4
ipVersion = "4"
)
Expand Down Expand Up @@ -454,9 +454,16 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {

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

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

// Create the endpoint.
Expand Down
12 changes: 11 additions & 1 deletion network/endpoint_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
}

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

if route.DevName != "" {
devIf, _ := net.InterfaceByName(route.DevName)
if devIf == nil {
log.Printf("[net] Not deleting route. Interface %v doesn't exist", interfaceName)
continue
}

ifIndex = devIf.Index
} else {
if interfaceIf == nil {
log.Printf("[net] Not deleting route. Interface %v doesn't exist", interfaceName)
continue
}

ifIndex = interfaceIf.Index
}

Expand Down
9 changes: 9 additions & 0 deletions network/transparent_endpointclient_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func setArpProxy(ifName string) error {
}

func (client *TransparentEndpointClient) AddEndpoints(epInfo *EndpointInfo) error {

if _, err := net.InterfaceByName(client.hostVethName); err == nil {
log.Printf("Deleting old host veth %v", client.hostVethName)
if err = netlink.DeleteLink(client.hostVethName); err != nil {
log.Printf("[net] Failed to delete old hostveth %v: %v.", client.hostVethName, err)
return err
}
}

if err := epcommon.CreateEndpoint(client.hostVethName, client.containerVethName); err != nil {
return err
}
Expand Down

0 comments on commit 69fde1c

Please sign in to comment.