Skip to content

Commit f1f65e7

Browse files
Yongli Chentamilmani1989
authored andcommitted
moves cni related code from network package to cni. (Azure#129)
* configure dnssuffix & dnsServerList * add dns info to conflist * change case for dns info * remove hardcoding * remove hardcoding * parse k8s pod info * add AdditionalArgs and Dns info to conflist * serialize policies * program route info * start addressign ipam ip leak * fix 1) ip inconsistency in k8s & pod. 2) IP leak in IPAM. * remove comments * separate windows & linux * remove dnsServers * remove comments * address comments * add dns verification * abstract linux policy struct * remove setPolicies * separte Windows & Linux code
1 parent 0bbce8d commit f1f65e7

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

cni/network/network.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ func (plugin *netPlugin) findMasterInterface(nwCfg *cni.NetworkConfig, subnetPre
117117
return ""
118118
}
119119

120+
// GetEndpointID returns a unique endpoint ID based on the CNI args.
121+
func GetEndpointID(args *cniSkel.CmdArgs) string {
122+
infraEpId, _ := network.ConstructEndpointID(args.ContainerID, args.Netns, args.IfName)
123+
return infraEpId
124+
}
125+
120126
//
121127
// CNI implementation
122128
// https://github.com/containernetworking/cni/blob/master/SPEC.md

network/endpoint.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package network
55

66
import (
77
"net"
8+
"strings"
89

910
"github.com/Azure/azure-container-networking/log"
1011
"github.com/Azure/azure-container-networking/network/policy"
11-
cniSkel "github.com/containernetworking/cni/pkg/skel"
1212
)
1313

1414
// Endpoint represents a container network interface.
@@ -42,10 +42,29 @@ type RouteInfo struct {
4242
Gw net.IP
4343
}
4444

45-
// GetEndpointID returns a unique endpoint ID based on the CNI args.
46-
func GetEndpointID(args *cniSkel.CmdArgs) string {
47-
infraEpId, _ := ConstructEpName(args.ContainerID, args.Netns, args.IfName)
48-
return infraEpId
45+
// ConstructEndpointID constructs endpoint name from netNsPath.
46+
func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) {
47+
infraEpName, workloadEpName := "", ""
48+
49+
if len(containerID) > 8 {
50+
containerID = containerID[:8]
51+
}
52+
53+
if netNsPath != "" {
54+
splits := strings.Split(netNsPath, ":")
55+
// For workload containers, we extract its linking infrastructure container ID.
56+
if len(splits) == 2 {
57+
if len(splits[1]) > 8 {
58+
splits[1] = splits[1][:8]
59+
}
60+
infraEpName = splits[1] + "-" + ifName
61+
workloadEpName = containerID + "-" + ifName
62+
} else {
63+
// For infrastructure containers, we just use its container ID.
64+
infraEpName = containerID + "-" + ifName
65+
}
66+
}
67+
return infraEpName, workloadEpName
4968
}
5069

5170
// NewEndpoint creates a new endpoint in the network.

network/endpoint_windows.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,6 @@ import (
1515
"github.com/Microsoft/hcsshim"
1616
)
1717

18-
// ConstructEpName constructs endpoint name from netNsPath.
19-
func ConstructEpName(containerID string, netNsPath string, ifName string) (string, string) {
20-
infraEpName, workloadEpName := "", ""
21-
22-
if len(containerID) > 8 {
23-
containerID = containerID[:8]
24-
}
25-
26-
if netNsPath != "" {
27-
splits := strings.Split(netNsPath, ":")
28-
// For workload containers, we extract its linking infrastructure container ID.
29-
if len(splits) == 2 {
30-
if len(splits[1]) > 8 {
31-
splits[1] = splits[1][:8]
32-
}
33-
infraEpName = splits[1] + "-" + ifName
34-
workloadEpName = containerID + "-" + ifName
35-
} else {
36-
// For infrastructure containers, we just use its container ID.
37-
infraEpName = containerID + "-" + ifName
38-
}
39-
}
40-
return infraEpName, workloadEpName
41-
}
42-
4318
// HotAttachEndpoint is a wrapper of hcsshim's HotAttachEndpoint.
4419
func (endpoint *EndpointInfo) HotAttachEndpoint(containerID string) error {
4520
return hcsshim.HotAttachEndpoint(containerID, endpoint.Id)
@@ -48,7 +23,7 @@ func (endpoint *EndpointInfo) HotAttachEndpoint(containerID string) error {
4823
// newEndpointImpl creates a new endpoint in the network.
4924
func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
5025
// Get Infrastructure containerID. Handle ADD calls for workload container.
51-
infraEpName, _ := ConstructEpName(epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName)
26+
infraEpName, _ := ConstructEndpointID(epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName)
5227

5328
hnsEndpoint := &hcsshim.HNSEndpoint{
5429
Name: infraEpName,

0 commit comments

Comments
 (0)