Skip to content

Conversation

@tamilmani1989
Copy link
Member

What this PR does / why we need it:
This PR adds multitenancy support in both cnm and cni. The user has the option to pass vlanid. If vlanid is specified, then OVS network will be setup and the packets coming out of container will be tagged with corresponding vlan id. In case of CNM, the vlanid can be specified as option in create network request. CNI will get vlanid after querying CNS for podname and namespace.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

Release note:

tamilmani1989 and others added 30 commits March 4, 2018 19:50
…working into multitenancy

# Conflicts:
#	cns/dnccontract.go
…iner-networking into multitenancy

# Conflicts:
#	cns/dnccontract.go
#	cns/restserver/restserver.go
Added getnetworkcontainerbyorchestrator context api and relevant test cases
…working into multitenancy

# Conflicts:
#	cns/dnccontract.go
#	cns/restserver/restserver.go
…iner-networking into multitenancy

# Conflicts:
#	client/cnsclient/cnsclient.go
#	cni/network/network.go
…working into multitenancy

# Conflicts:
#	client/cnsclient/cnsclient.go
#	cni/network/network.go
#	cns/service/main.go
if ipAddr.To4() != nil {
resultIpconfig.Version = "4"
resultIpconfig.Address = net.IPNet{IP: ipAddr, Mask: net.CIDRMask(int(ipconfig.IPSubnet.PrefixLength), 32)}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

gwIP := net.ParseIP(route.GatewayIPAddress)
result.Routes = append(result.Routes, &types.Route{Dst: *routeIPnet, GW: gwIP})
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can return route here instead of having else.

} else {
gwIP := net.ParseIP(networkConfig.IPConfiguration.GatewayIPAddress)
dstIP := net.IPNet{IP: net.ParseIP("0.0.0.0"), Mask: resultIpconfig.Address.Mask}
result.Routes = append(result.Routes, &types.Route{Dst: dstIP, GW: gwIP})
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if result.Routes==nil?

return convertToCniResult(networkConfig), networkConfig.MultiTenancyInfo.ID, *subnetPrefix, nil
}

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.

Suggestion:

func getPodNameWithoutSuffix(podName string) string {
	nameSplit := strings.Split(podName, "-")
	if len(nameSplit) < 2 {
		return podName
	}

	return strings.Join(nameSplit[:2], "-")
}

return nil, err
}

defer res.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Check if we need to close in case we get err!=nil

@@ -0,0 +1,85 @@
package cnsclient
Copy link
Contributor

Choose a reason for hiding this comment

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

move it under cns package

Copy link
Member Author

Choose a reason for hiding this comment

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

done

"type":"azure-vnet",
"mode":"bridge",
"bridge":"azure0",
"multiTenancy":true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a new conflist for this

Copy link
Member Author

Choose a reason for hiding this comment

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

done

"type":"azure-vnet",
"mode":"bridge",
"bridge":"azure0",
"multiTenancy":true,
Copy link
Contributor

Choose a reason for hiding this comment

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

add enablesnat: true

// Plugin name.
name = "azure-vnet"
name = "azure-vnet"
namespaceKey = "K8S_POD_NAMESPACE"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove it as it is not used

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}

func (service *httpRestService) getNetworkContainerResponse(req cns.GetNetworkContainerRequest) cns.GetNetworkContainerResponse {
var containerID string
Copy link
Contributor

Choose a reason for hiding this comment

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

log at beginning and end

Copy link
Member Author

Choose a reason for hiding this comment

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

this is internal function

}

func (service *httpRestService) getNetworkContainerByOrchestratorContext(w http.ResponseWriter, r *http.Request) {
log.Printf("[Azure CNS] getNetworkContainer")
Copy link
Contributor

Choose a reason for hiding this comment

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

fix log

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{
Name: acn.OptStopAzureVnet,
Shorthand: acn.OptStopAzureVnetAlias,
Description: "Start Azure-CNM if flag is true",
Copy link
Contributor

Choose a reason for hiding this comment

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

fix description or rename flag

Copy link
Member Author

Choose a reason for hiding this comment

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

done

common/utils.go Outdated
return err
}

func ExecuteShellCommand(command string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

platform specific

Copy link
Member Author

Choose a reason for hiding this comment

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

done

network/api.go Outdated

OptVethName = "vethname"
OptVethName = "vethname"
OptEnableSnatOnHost = "enableSnatOnHost"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove it

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}

func getContainerNetworkConfiguration(namespace string, podName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) {
cnsClient, err := cnsclient.NewCnsClient("")
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets leave it upto the caller to give CNS address.. ideally, it should come from cni config (when CNI is used)

podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: namespace}
orchestratorContext, err := json.Marshal(podInfo)
if err != nil {
log.Printf("Marshalling azure container instance info failed with %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Marshalling azure container instance info failed with %v" --> "Marshalling cns.KubernetesPodInfo failed with %v"


networkConfig, err := cnsClient.GetNetworkConfiguration(orchestratorContext)
if err != nil {
log.Printf("GetNetworkConfiguration failed with %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets print %v orchestrator context to help debug

return podName
}

log.Printf("Final namesplit %v", nameSplit)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Pod name after splitting based on - : %v"

Name: args.IfName,
}

snatIface := &cniTypesCurr.Interface{
Copy link
Contributor

Choose a reason for hiding this comment

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

Move it out to a linux specific method

}

if client.enableSnatOnHost {

Copy link
Contributor

Choose a reason for hiding this comment

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

remove empty line


_, err := net.InterfaceByName(internetBridgeName)
if err == nil {
log.Printf("Internet Bridge already exists")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace internet with SNAT everywhere...

}

func (client *OVSNetworkClient) AddBridgeRules(extIf *externalInterface) error {
//primary := extIf.IPAddresses[0].IP.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

remove dead code

return nil
}

func (client *OVSNetworkClient) AddBridgeRules(extIf *externalInterface) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

AddL2Rules

ovsctl/ovsctl.go Outdated
)

const (
macAddress = "12:34:56:78:9a:bc"
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultMacForArpResponse

epInfo.Data[network.VlanIDKey] = cnsNwConfig.MultiTenancyInfo.ID
epInfo.Data[network.LocalIPKey] = cnsNwConfig.LocalIPConfiguration.IPSubnet.IPAddress + "/" + strconv.Itoa(int(cnsNwConfig.LocalIPConfiguration.IPSubnet.PrefixLength))
epInfo.Data[network.InternetBridgeIPKey] = cnsNwConfig.LocalIPConfiguration.GatewayIPAddress + "/" + strconv.Itoa(int(cnsNwConfig.LocalIPConfiguration.IPSubnet.PrefixLength))

Copy link
Contributor

Choose a reason for hiding this comment

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

remove space

PrimaryInterfaceIdentifier string // Primary CA.
AuthorizationToken string
OrchestratorInfo OrchestratorInfo
LocalIPConfiguration IPConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this? Is this from your dnc change?

Copy link
Member Author

Choose a reason for hiding this comment

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

i changed this both in vendor and in my branch


defer res.Body.Close()

if res.StatusCode != 200 {
Copy link
Contributor

Choose a reason for hiding this comment

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

http.StatusOK instead of 200

getNetworkContainerResponse = cns.GetNetworkContainerResponse{
IPConfiguration: savedReq.IPConfiguration,
Routes: savedReq.Routes,
CnetAddressSpace: savedReq.CnetAddressSpace,
Copy link
Contributor

Choose a reason for hiding this comment

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

fix spacing


// Create the key value store.
pluginConfig.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + pluginName + ".json")

Copy link
Contributor

Choose a reason for hiding this comment

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

remove space

}

func createInternetBridge(internetBridgeIP string, mainInterface string) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

remove space


ip, addr, _ := net.ParseCIDR(internetBridgeIP)

log.Printf("Assigning %v on internet bridge", internetBridgeIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

move ParseCIDR below log.Printf

log.Printf("[net] Failed to delete bridge %v, err:%v.", internetBridgeName, err)
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return err here?

mac := extIf.MacAddress.String()
macHex := strings.Replace(mac, ":", "", -1)

/*if err := ovsctl.AddVMIpAcceptRule(client.bridgeName, primary, mac); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented section if not necessary

ovsctl/ovsctl.go Outdated

ofport = strings.Trim(ofport, "\n")

return ofport, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return strings.Trim(ofport, "\n"), nil

@sharmasushant sharmasushant merged commit 147c438 into Azure:master Jul 6, 2018
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants