Skip to content

Commit da4e6ac

Browse files
committed
CNI changes for multi-nic support
1 parent 291c3ed commit da4e6ac

File tree

9 files changed

+673
-426
lines changed

9 files changed

+673
-426
lines changed

cmd/routed-eni-cni-plugin/cni.go

+158-74
Large diffs are not rendered by default.

cmd/routed-eni-cni-plugin/cni_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,19 @@ func TestCmdAdd(t *testing.T) {
103103
enforceNpReply := &rpc.EnforceNpReply{Success: true}
104104
mockNP.EXPECT().EnforceNpToPod(gomock.Any(), gomock.Any()).Return(enforceNpReply, nil).Times(1)
105105

106-
addNetworkReply := &rpc.AddNetworkReply{Success: true, IPv4Addr: ipAddr, DeviceNumber: devNum, NetworkPolicyMode: "none"}
106+
addrs := []*rpc.IPAddress{&rpc.IPAddress{
107+
IPv4Addr: ipAddr,
108+
DeviceNumber: devNum,
109+
}}
110+
addNetworkReply := &rpc.AddNetworkReply{Success: true, IPAddress: addrs, NetworkPolicyMode: "none"}
107111
mockC.EXPECT().AddNetwork(gomock.Any(), gomock.Any()).Return(addNetworkReply, nil)
108112

109113
v4Addr := &net.IPNet{
110-
IP: net.ParseIP(addNetworkReply.IPv4Addr),
114+
IP: net.ParseIP(addNetworkReply.IPAddress[0].IPv4Addr),
111115
Mask: net.IPv4Mask(255, 255, 255, 255),
112116
}
113117
mocksNetwork.EXPECT().SetupPodNetwork(gomock.Any(), cmdArgs.IfName, cmdArgs.Netns,
114-
v4Addr, nil, int(addNetworkReply.DeviceNumber), gomock.Any(), gomock.Any()).Return(nil)
118+
v4Addr, nil, int(addNetworkReply.IPAddress[0].DeviceNumber), gomock.Any(), gomock.Any()).Return(nil)
115119

116120
mocksTypes.EXPECT().PrintResult(gomock.Any(), gomock.Any()).Return(nil).Times(1)
117121

cmd/routed-eni-cni-plugin/driver/driver.go

+89-68
Large diffs are not rendered by default.

misc/10-aws.conflist

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"cniVersion": "0.4.0",
33
"name": "aws-cni",
44
"disableCheck": true,
5-
"capabilities": {
6-
"io.kubernetes.cri.pod-annotations": true
7-
},
85
"plugins": [
96
{
107
"name": "aws-cni",
@@ -13,7 +10,8 @@
1310
"mtu": "__MTU__",
1411
"podSGEnforcingMode": "__PODSGENFORCINGMODE__",
1512
"pluginLogFile": "__PLUGINLOGFILE__",
16-
"pluginLogLevel": "__PLUGINLOGLEVEL__"
13+
"pluginLogLevel": "__PLUGINLOGLEVEL__",
14+
"capabilities": {"io.kubernetes.cri.pod-annotations": true}
1715
},
1816
{
1917
"name": "egress-cni",

pkg/ipamd/rpc_handler.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,23 @@ func (s *server) AddNetwork(ctx context.Context, in *rpc.AddNetworkRequest) (*rp
216216
}
217217
}
218218
}
219+
// This will be a list of IPs. For now it's just one
220+
ipAddrs := []*rpc.IPAddress{}
221+
222+
// All fields here need to be found from IPAM datastore
223+
ipAddr := &rpc.IPAddress{
224+
IPv4Addr: ipv4Addr,
225+
IPv6Addr: ipv6Addr,
226+
DeviceNumber: int32(deviceNumber),
227+
RouteTableId: int32(deviceNumber),
228+
NetworkCard: 0,
229+
}
230+
231+
ipAddrs = append(ipAddrs, ipAddr)
232+
219233
resp := rpc.AddNetworkReply{
220234
Success: err == nil,
221-
IPv4Addr: ipv4Addr,
222-
IPv6Addr: ipv6Addr,
223-
DeviceNumber: int32(deviceNumber),
235+
IPAddress: ipAddrs,
224236
UseExternalSNAT: useExternalSNAT,
225237
VPCv4CIDRs: pbVPCV4cidrs,
226238
VPCv6CIDRs: pbVPCV6cidrs,
@@ -304,7 +316,8 @@ func (s *server) DelNetwork(ctx context.Context, in *rpc.DelNetworkRequest) (*rp
304316
return &rpc.DelNetworkReply{
305317
Success: true,
306318
PodVlanId: int32(podENIData[0].VlanID),
307-
IPv4Addr: podENIData[0].PrivateIP}, err
319+
IPAddress: []*rpc.IPAddress{&rpc.IPAddress{IPv4Addr: podENIData[0].PrivateIP}},
320+
}, err
308321
}
309322
}
310323

@@ -318,7 +331,16 @@ func (s *server) DelNetwork(ctx context.Context, in *rpc.DelNetworkRequest) (*rp
318331

319332
log.Infof("Send DelNetworkReply: IPv4Addr: %s, IPv6Addr: %s, DeviceNumber: %d, err: %v", ipv4Addr, ipv6Addr, deviceNumber, err)
320333

321-
return &rpc.DelNetworkReply{Success: err == nil, IPv4Addr: ipv4Addr, IPv6Addr: ipv6Addr, DeviceNumber: int32(deviceNumber)}, err
334+
ipAddr := &rpc.IPAddress{
335+
IPv4Addr: ipv4Addr,
336+
IPv6Addr: ipv6Addr,
337+
DeviceNumber: int32(deviceNumber),
338+
}
339+
340+
return &rpc.DelNetworkReply{
341+
Success: err == nil,
342+
IPAddress: []*rpc.IPAddress{ipAddr},
343+
}, err
322344
}
323345

324346
func (s *server) GetNetworkPolicyConfigs(ctx context.Context, e *emptypb.Empty) (*rpc.NetworkPolicyAgentConfigReply, error) {

pkg/networkutils/names.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import (
88

99
// GeneratePodHostVethName generates the name for Pod's host-side veth device.
1010
// The veth name is generated in a way that aligns with the value expected by Calico for NetworkPolicy enforcement.
11-
func GeneratePodHostVethName(prefix string, podNamespace string, podName string) string {
11+
func GeneratePodHostVethName(prefix string, podNamespace string, podName string, index int) string {
12+
13+
if index > 0 {
14+
podName = fmt.Sprintf("%s.%s", podName, string(index))
15+
}
1216
suffix := GeneratePodHostVethNameSuffix(podNamespace, podName)
1317
return fmt.Sprintf("%s%s", prefix, suffix)
1418
}
@@ -19,3 +23,11 @@ func GeneratePodHostVethNameSuffix(podNamespace string, podName string) string {
1923
h.Write([]byte(fmt.Sprintf("%s.%s", podNamespace, podName)))
2024
return hex.EncodeToString(h.Sum(nil))[:11]
2125
}
26+
27+
// Generates the interface name inside the pod namespace
28+
func GenerateContainerVethName(defaultIfName string, prefix string, index int) string {
29+
if index > 0 {
30+
return fmt.Sprintf("%s%s", prefix, string(index))
31+
}
32+
return defaultIfName
33+
}

pkg/networkutils/network.go

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
// Rule priority for traffic destined to pod IP
5959
ToContainerRulePriority = 512
6060

61+
// From Interface priority for multi-homed pods
62+
FromInterfaceRulePriority = 1
63+
6164
// 513 - 1023, can be used for priority lower than fromPodRule but higher than default nonVPC CIDR rule
6265

6366
// 1024 is reserved for (ip rule not to <VPC's subnet> table main)

0 commit comments

Comments
 (0)