Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
fb257f8
Temporary commit. Added vlan support
tamilmani1989 Mar 5, 2018
3cd7300
checkpoint
tamilmani1989 Mar 5, 2018
0c05120
fixes
tamilmani1989 Mar 7, 2018
ef6d539
Added code for cleaning up ovs rules on deleting endpoint
tamilmani1989 Apr 2, 2018
035462d
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 2, 2018
72f34ff
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 2, 2018
7a7ba69
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 3, 2018
09122b0
Added code to get network config
tamilmani1989 Apr 4, 2018
9bea2e8
Added cnsclient
tamilmani1989 Apr 4, 2018
149ce20
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 5, 2018
eecc9ec
Added setorchestrator api
tamilmani1989 Apr 5, 2018
9a21055
Fixed styling
tamilmani1989 Apr 5, 2018
d433550
Merge branch 'master' of https://github.com/tamilmani1989/azure-conta…
tamilmani1989 Apr 5, 2018
f7ab7ea
Modified networkcontainercreate request to save podinfo (#115)
tamilmani1989 Apr 5, 2018
40b87bc
Added GetNetworkContainerByContext Api (#116)
tamilmani1989 Apr 5, 2018
1a439cb
Added testcase to check if state is cleaneup after delete call
tamilmani1989 Apr 5, 2018
0df120d
Resued existing errorcode
tamilmani1989 Apr 5, 2018
70e8074
Added code in CNI to retrieve network config from CNS based on podnam…
tamilmani1989 Apr 6, 2018
46fc36f
Added option in cns to not to start cnm by default.
tamilmani1989 Apr 6, 2018
37f8114
Fixed style and spacing
tamilmani1989 Apr 6, 2018
7f730fc
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 7, 2018
b4eaf38
Merge branch 'master' of https://github.com/tamilmani1989/azure-conta…
tamilmani1989 Apr 9, 2018
765cac9
fixed merge issues
tamilmani1989 Apr 9, 2018
00522ae
CNI gets networkconfig from CNS (#117)
tamilmani1989 Apr 9, 2018
bba9c4a
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 9, 2018
3858cec
Fixed issues and tested cnm and cni
tamilmani1989 Apr 10, 2018
adde6f2
Added comments
tamilmani1989 Apr 10, 2018
679dc94
Fixed hardcoded values
tamilmani1989 Apr 10, 2018
fad692c
removed unnecessary checks
tamilmani1989 Apr 10, 2018
82486a8
check for network container type (#121)
tamilmani1989 Apr 12, 2018
4ea20be
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 Apr 12, 2018
ce6a357
Fixed review comments
tamilmani1989 Apr 13, 2018
c77597a
Redesigned OVS code and tested
tamilmani1989 Apr 26, 2018
bb62d01
Added fake arp reply for all arp requests
tamilmani1989 May 3, 2018
b633dd6
removed unused functions
tamilmani1989 May 8, 2018
7cdab6b
Addressed review comments
tamilmani1989 May 9, 2018
ad2f472
removed hardcoded values
tamilmani1989 May 10, 2018
ecdcd97
removed ipaccept rule
tamilmani1989 May 26, 2018
07ed3ef
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 May 29, 2018
74a8f87
Added stdout support
tamilmani1989 May 30, 2018
6720293
Added lock before saving state in setorchestrator api
tamilmani1989 May 30, 2018
9d74bc1
moved lock before setting state
tamilmani1989 May 30, 2018
323c49f
Fixed review comments and added rule to drop packet if already tagged
tamilmani1989 May 30, 2018
5b39198
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Jun 8, 2018
82c0df4
fixed merge conflict bugs
tamilmani1989 Jun 8, 2018
e7f0136
jaeryn changes in cns
tamilmani1989 Jun 8, 2018
08fdbdc
Missing changes from devaci branch.
Jun 8, 2018
b6682bd
fixed route issue
tamilmani1989 Jun 12, 2018
3499ad5
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 Jun 12, 2018
385d9c7
updated ovs config to clean ovs setup on bootup
tamilmani1989 Jun 12, 2018
2106013
Merge branch 'ovsabstract' of https://github.com/tamilmani1989/azure-…
tamilmani1989 Jun 12, 2018
ed58e92
fixed the hardcoded part
tamilmani1989 Jun 12, 2018
c76a859
Added multiwrite option for windows logger
Jun 13, 2018
8313b04
fixed getting podname without suffix
tamilmani1989 Jun 20, 2018
9d32e49
Merge branch 'ovsabstract' of https://github.com/tamilmani1989/azure-…
tamilmani1989 Jun 20, 2018
1151913
added logs
tamilmani1989 Jun 20, 2018
e2ad9fd
Added snat support for outbound traffic
tamilmani1989 Jun 21, 2018
eaec5d9
Added cnetspace routes
tamilmani1989 Jun 22, 2018
fa0fd46
snat changes
tamilmani1989 Jun 25, 2018
5d190d9
snat changes integrated with cns
tamilmani1989 Jun 27, 2018
265c285
moved linux specific code to appropriate files
tamilmani1989 Jun 27, 2018
11aeb20
addressed review comments and fixed issues
tamilmani1989 Jun 28, 2018
bab14a5
handled failure case and create internet bridge if enablesnatonhost i…
tamilmani1989 Jun 29, 2018
99770ae
addressed review comments and tested for regression
tamilmani1989 Jul 4, 2018
d1f405e
fixed review comments
tamilmani1989 Jul 5, 2018
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
23 changes: 23 additions & 0 deletions cni/azure-linux-multitenancy.conflist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"cniVersion":"0.3.0",
"name":"azure",
"plugins":[
{
"type":"azure-vnet",
"mode":"bridge",
"bridge":"azure0",
"multiTenancy":true,
"enableSnatOnHost":true,
"ipam":{
"type":"azure-vnet-ipam"
}
},
{
"type":"portmap",
"capabilities":{
"portMappings":true
},
"snat":true
}
]
}
20 changes: 11 additions & 9 deletions cni/netconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ type KVPair struct {

// NetworkConfig represents Azure CNI plugin network configuration.
type NetworkConfig struct {
CNIVersion string `json:"cniVersion"`
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
Master string `json:"master"`
Bridge string `json:"bridge,omitempty"`
LogLevel string `json:"logLevel,omitempty"`
LogTarget string `json:"logTarget,omitempty"`
Ipam struct {
CNIVersion string `json:"cniVersion"`
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
Master string `json:"master"`
Bridge string `json:"bridge,omitempty"`
LogLevel string `json:"logLevel,omitempty"`
LogTarget string `json:"logTarget,omitempty"`
MultiTenancy bool `json:"multiTenancy,omitempty"`
EnableSnatOnHost bool `json:"enableSnatOnHost,omitempty"`
Ipam struct {
Type string `json:"type"`
Environment string `json:"environment,omitempty"`
AddrSpace string `json:"addressSpace,omitempty"`
Expand Down
126 changes: 126 additions & 0 deletions cni/network/mutlitenancy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package network

import (
"encoding/json"
"fmt"
"net"
"strings"

"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/cnsclient"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/network"
cniTypes "github.com/containernetworking/cni/pkg/types"
cniTypesCurr "github.com/containernetworking/cni/pkg/types/current"
)

func SetupRoutingForMultitenancy(nwCfg *cni.NetworkConfig, cnsNetworkConfig *cns.GetNetworkContainerResponse, epInfo *network.EndpointInfo, result *cniTypesCurr.Result) {
// Adding default gateway
if nwCfg.MultiTenancy {
// if snat enabled, add 169.254.0.1 as default gateway
if nwCfg.EnableSnatOnHost {
log.Printf("add default route for multitenancy.snat on host enabled")
addDefaultRoute(cnsNetworkConfig.LocalIPConfiguration.GatewayIPAddress, epInfo, result)
} else {
_, defaultIPNet, _ := net.ParseCIDR("0.0.0.0/0")
dstIP := net.IPNet{IP: net.ParseIP("0.0.0.0"), Mask: defaultIPNet.Mask}
gwIP := net.ParseIP(cnsNetworkConfig.IPConfiguration.GatewayIPAddress)
epInfo.Routes = append(epInfo.Routes, network.RouteInfo{Dst: dstIP, Gw: gwIP})
result.Routes = append(result.Routes, &cniTypes.Route{Dst: dstIP, GW: gwIP})
}
}
}

func GetContainerNetworkConfiguration(multiTenancy bool, address string, podName string, podNamespace string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) {
if multiTenancy {
podNameWithoutSuffix := getPodNameWithoutSuffix(podName)
log.Printf("Podname without suffix %v", podNameWithoutSuffix)
return getContainerNetworkConfiguration(address, podNamespace, podNameWithoutSuffix)
}

return nil, nil, net.IPNet{}, nil
}

func getContainerNetworkConfiguration(address string, namespace string, podName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) {
cnsClient, err := cnsclient.NewCnsClient(address)
if err != nil {
log.Printf("Initializing CNS client error %v", err)
return nil, nil, net.IPNet{}, err
}

podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: namespace}
orchestratorContext, err := json.Marshal(podInfo)
if err != nil {
log.Printf("Marshalling KubernetesPodInfo failed with %v", err)
return nil, nil, net.IPNet{}, err
}

networkConfig, err := cnsClient.GetNetworkConfiguration(orchestratorContext)
if err != nil {
log.Printf("GetNetworkConfiguration failed with %v", err)
return nil, nil, net.IPNet{}, err
}

log.Printf("Network config received from cns %+v", networkConfig)

subnetPrefix := common.GetInterfaceSubnetWithSpecificIp(networkConfig.PrimaryInterfaceIdentifier)
if subnetPrefix == nil {
errBuf := fmt.Sprintf("Interface not found for this ip %v", networkConfig.PrimaryInterfaceIdentifier)
log.Printf(errBuf)
return nil, nil, net.IPNet{}, fmt.Errorf(errBuf)
}

return convertToCniResult(networkConfig), networkConfig, *subnetPrefix, nil
}

func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse) *cniTypesCurr.Result {
result := &cniTypesCurr.Result{}
resultIpconfig := &cniTypesCurr.IPConfig{}

ipconfig := networkConfig.IPConfiguration
ipAddr := net.ParseIP(ipconfig.IPSubnet.IPAddress)

if ipAddr.To4() != nil {
resultIpconfig.Version = "4"
resultIpconfig.Address = net.IPNet{IP: ipAddr, Mask: net.CIDRMask(int(ipconfig.IPSubnet.PrefixLength), 32)}
} else {
resultIpconfig.Version = "6"
resultIpconfig.Address = net.IPNet{IP: ipAddr, Mask: net.CIDRMask(int(ipconfig.IPSubnet.PrefixLength), 128)}
}

resultIpconfig.Gateway = net.ParseIP(ipconfig.GatewayIPAddress)
result.IPs = append(result.IPs, resultIpconfig)
result.DNS.Nameservers = ipconfig.DNSServers

if networkConfig.Routes != nil && len(networkConfig.Routes) > 0 {
for _, route := range networkConfig.Routes {
_, routeIPnet, _ := net.ParseCIDR(route.IPAddress)
gwIP := net.ParseIP(route.GatewayIPAddress)
result.Routes = append(result.Routes, &cniTypes.Route{Dst: *routeIPnet, GW: gwIP})
}
}

for _, ipRouteSubnet := range networkConfig.CnetAddressSpace {
log.Printf("Adding cnetAddressspace routes %v %v", ipRouteSubnet.IPAddress, ipRouteSubnet.PrefixLength)
routeIPnet := net.IPNet{IP: net.ParseIP(ipRouteSubnet.IPAddress), Mask: net.CIDRMask(int(ipRouteSubnet.PrefixLength), 32)}
gwIP := net.ParseIP(ipconfig.GatewayIPAddress)
result.Routes = append(result.Routes, &cniTypes.Route{Dst: routeIPnet, GW: gwIP})
}

return result
}

func getPodNameWithoutSuffix(podName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the use case of this feature?

nameSplit := strings.Split(podName, "-")
log.Printf("namesplit %v", nameSplit)
if len(nameSplit) > 2 {
nameSplit = nameSplit[:len(nameSplit)-2]
} else {
return podName
}

log.Printf("Pod name after splitting based on - : %v", nameSplit)
return strings.Join(nameSplit, "-")
}
Loading