-
Notifications
You must be signed in to change notification settings - Fork 260
Multitenancy Support using vlanid #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 3cd7300
checkpoint
tamilmani1989 0c05120
fixes
tamilmani1989 ef6d539
Added code for cleaning up ovs rules on deleting endpoint
tamilmani1989 035462d
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 72f34ff
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 7a7ba69
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 09122b0
Added code to get network config
tamilmani1989 9bea2e8
Added cnsclient
tamilmani1989 149ce20
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 eecc9ec
Added setorchestrator api
tamilmani1989 9a21055
Fixed styling
tamilmani1989 d433550
Merge branch 'master' of https://github.com/tamilmani1989/azure-conta…
tamilmani1989 f7ab7ea
Modified networkcontainercreate request to save podinfo (#115)
tamilmani1989 40b87bc
Added GetNetworkContainerByContext Api (#116)
tamilmani1989 1a439cb
Added testcase to check if state is cleaneup after delete call
tamilmani1989 0df120d
Resued existing errorcode
tamilmani1989 70e8074
Added code in CNI to retrieve network config from CNS based on podnam…
tamilmani1989 46fc36f
Added option in cns to not to start cnm by default.
tamilmani1989 37f8114
Fixed style and spacing
tamilmani1989 7f730fc
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 b4eaf38
Merge branch 'master' of https://github.com/tamilmani1989/azure-conta…
tamilmani1989 765cac9
fixed merge issues
tamilmani1989 00522ae
CNI gets networkconfig from CNS (#117)
tamilmani1989 bba9c4a
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 3858cec
Fixed issues and tested cnm and cni
tamilmani1989 adde6f2
Added comments
tamilmani1989 679dc94
Fixed hardcoded values
tamilmani1989 fad692c
removed unnecessary checks
tamilmani1989 82486a8
check for network container type (#121)
tamilmani1989 4ea20be
Merge branch 'devaci' of https://github.com/Azure/azure-container-net…
tamilmani1989 ce6a357
Fixed review comments
tamilmani1989 c77597a
Redesigned OVS code and tested
tamilmani1989 bb62d01
Added fake arp reply for all arp requests
tamilmani1989 b633dd6
removed unused functions
tamilmani1989 7cdab6b
Addressed review comments
tamilmani1989 ad2f472
removed hardcoded values
tamilmani1989 ecdcd97
removed ipaccept rule
tamilmani1989 07ed3ef
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 74a8f87
Added stdout support
tamilmani1989 6720293
Added lock before saving state in setorchestrator api
tamilmani1989 9d74bc1
moved lock before setting state
tamilmani1989 323c49f
Fixed review comments and added rule to drop packet if already tagged
tamilmani1989 5b39198
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 82c0df4
fixed merge conflict bugs
tamilmani1989 e7f0136
jaeryn changes in cns
tamilmani1989 08fdbdc
Missing changes from devaci branch.
b6682bd
fixed route issue
tamilmani1989 3499ad5
Merge branch 'master' of https://github.com/Azure/azure-container-net…
tamilmani1989 385d9c7
updated ovs config to clean ovs setup on bootup
tamilmani1989 2106013
Merge branch 'ovsabstract' of https://github.com/tamilmani1989/azure-…
tamilmani1989 ed58e92
fixed the hardcoded part
tamilmani1989 c76a859
Added multiwrite option for windows logger
8313b04
fixed getting podname without suffix
tamilmani1989 9d32e49
Merge branch 'ovsabstract' of https://github.com/tamilmani1989/azure-…
tamilmani1989 1151913
added logs
tamilmani1989 e2ad9fd
Added snat support for outbound traffic
tamilmani1989 eaec5d9
Added cnetspace routes
tamilmani1989 fa0fd46
snat changes
tamilmani1989 5d190d9
snat changes integrated with cns
tamilmani1989 265c285
moved linux specific code to appropriate files
tamilmani1989 11aeb20
addressed review comments and fixed issues
tamilmani1989 bab14a5
handled failure case and create internet bridge if enablesnatonhost i…
tamilmani1989 99770ae
addressed review comments and tested for regression
tamilmani1989 d1f405e
fixed review comments
tamilmani1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| 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, "-") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?