Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 23 additions & 13 deletions cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ type CNSIPAMInvoker struct {
}

type IPv4ResultInfo struct {
podIPAddress string
ncSubnetPrefix uint8
ncPrimaryIP string
gwIPAddress string
hostSubnet string
hostPrimaryIP string
podIPAddress string
ncSubnetPrefix uint8
ncPrimaryIP string
ncGatewayIPAddress string
hostSubnet string
hostPrimaryIP string
hostGateway string
}

func NewCNSInvoker(podName, namespace string) (*CNSIPAMInvoker, error) {
Expand Down Expand Up @@ -61,17 +62,26 @@ func (invoker *CNSIPAMInvoker) Add(nwCfg *cni.NetworkConfig, subnetPrefix *net.I
}

resultIPv4 := IPv4ResultInfo{
podIPAddress: response.PodIpInfo.PodIPConfig.IPAddress,
ncSubnetPrefix: response.PodIpInfo.NetworkContainerPrimaryIPConfig.IPSubnet.PrefixLength,
ncPrimaryIP: response.PodIpInfo.NetworkContainerPrimaryIPConfig.IPSubnet.IPAddress,
gwIPAddress: response.PodIpInfo.NetworkContainerPrimaryIPConfig.GatewayIPAddress,
hostSubnet: response.PodIpInfo.HostPrimaryIPInfo.Subnet,
hostPrimaryIP: response.PodIpInfo.HostPrimaryIPInfo.PrimaryIP,
podIPAddress: response.PodIpInfo.PodIPConfig.IPAddress,
ncSubnetPrefix: response.PodIpInfo.NetworkContainerPrimaryIPConfig.IPSubnet.PrefixLength,
ncPrimaryIP: response.PodIpInfo.NetworkContainerPrimaryIPConfig.IPSubnet.IPAddress,
ncGatewayIPAddress: response.PodIpInfo.NetworkContainerPrimaryIPConfig.GatewayIPAddress,
hostSubnet: response.PodIpInfo.HostPrimaryIPInfo.Subnet,
hostPrimaryIP: response.PodIpInfo.HostPrimaryIPInfo.PrimaryIP,
hostGateway: response.PodIpInfo.HostPrimaryIPInfo.Gateway,
}

ncgw := net.ParseIP(resultIPv4.ncGatewayIPAddress)
if ncgw == nil {
return nil, nil, fmt.Errorf("Gateway address %v from response is invalid", resultIPv4.ncGatewayIPAddress)
}

// set the NC Primary IP in options
options[network.SNATIPKey] = resultIPv4.ncPrimaryIP

// set host gateway in options
options[network.HostGWKey] = resultIPv4.hostGateway

log.Printf("Received result %+v for pod %v", resultIPv4, podInfo)

result, err := getCNIIPv4Result(resultIPv4, subnetPrefix)
Expand All @@ -85,7 +95,7 @@ func (invoker *CNSIPAMInvoker) Add(nwCfg *cni.NetworkConfig, subnetPrefix *net.I

func getCNIIPv4Result(info IPv4ResultInfo, subnetPrefix *net.IPNet) (*cniTypesCurr.Result, error) {

gw := net.ParseIP(info.gwIPAddress)
gw := net.ParseIP(info.ncGatewayIPAddress)
if gw == nil {
return nil, fmt.Errorf("Gateway address %v from response is invalid", gw)
}
Expand Down
1 change: 1 addition & 0 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ type PodIpInfo struct {

// DeleteNetworkContainerRequest specifies the details about the request to delete a specifc network container.
type HostIPInfo struct {
Gateway string
PrimaryIP string
Subnet string
}
Expand Down
1 change: 1 addition & 0 deletions cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ func (service *HTTPRestService) populateIpConfigInfoUntransacted(ipConfigStatus

podIpInfo.HostPrimaryIPInfo.PrimaryIP = hostInterfaceInfo.PrimaryIP
podIpInfo.HostPrimaryIPInfo.Subnet = hostInterfaceInfo.Subnet
podIpInfo.HostPrimaryIPInfo.Gateway = hostInterfaceInfo.Gateway

return nil
}
Expand Down
20 changes: 17 additions & 3 deletions network/bridge_networkclient_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,32 @@ func (client *LinuxBridgeClient) CreateBridge() error {

func (client *LinuxBridgeClient) AddRoutes(nwInfo *NetworkInfo, interfaceName string) error {
if client.nwInfo.IPAMType == AzureCNS {
// add pod subnet to host

// fetch the host gateway IP from options
gwIP := client.nwInfo.Options[HostGWKey]
if gwIP == nil {
return fmt.Errorf("Host gateway IP in Options not set")
}

gatewayIP := net.ParseIP(gwIP.(string))
if gatewayIP == nil {
return fmt.Errorf("Invalid host gateway IP: %+v", gwIP)
}

// add host gateway as the default gateway for pod IP's
devIf, _ := net.InterfaceByName(interfaceName)
ifIndex := devIf.Index
family := netlink.GetIpAddressFamily(Ipv4DefaultRouteDstPrefix.IP)
family := netlink.GetIpAddressFamily(gatewayIP)

nlRoute := &netlink.Route{
Family: family,
Dst: &client.nwInfo.PodSubnet.Prefix,
Gw: Ipv4DefaultRouteDstPrefix.IP,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like instead of adding a rule we're replacing a rule. Also what is the podsubnet here is it actually the node subnet (what I would think of in aks-rp as vnetsubnetid given to aks?)

Gw: gatewayIP,
LinkIndex: ifIndex,
}

log.Printf("Adding Swift route %+v", nlRoute)

if err := netlink.AddIpRoute(nlRoute); err != nil {
if !strings.Contains(strings.ToLower(err.Error()), "file exists") {
return fmt.Errorf("Failed to add route to host interface with error: %v", err)
Expand Down
1 change: 1 addition & 0 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
VlanIDKey = "VlanID"
AzureCNS = "azure-cns"
SNATIPKey = "NCPrimaryIPKey"
HostGWKey = "HostGatewayIP"
genericData = "com.docker.network.generic"
)

Expand Down