@@ -58,13 +58,41 @@ func (c *MockCNSClient) RequestIPAddress(ctx context.Context, ipconfig cns.IPCon
5858 },
5959 }
6060 return result , nil
61+ case "nilGateway" :
62+ result := & cns.IPConfigResponse {
63+ PodIpInfo : cns.PodIpInfo {
64+ PodIPConfig : cns.IPSubnet {
65+ IPAddress : "10.0.1.10" ,
66+ PrefixLength : 24 ,
67+ },
68+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
69+ IPSubnet : cns.IPSubnet {
70+ IPAddress : "10.0.1.0" ,
71+ PrefixLength : 24 ,
72+ },
73+ DNSServers : nil ,
74+ GatewayIPAddress : "" , // nil/empty gateway
75+ },
76+ HostPrimaryIPInfo : cns.HostIPInfo {
77+ Gateway : "" ,
78+ PrimaryIP : "10.0.0.1" ,
79+ Subnet : "10.0.0.0/24" ,
80+ },
81+ },
82+ Response : cns.Response {
83+ ReturnCode : 0 ,
84+ Message : "" ,
85+ },
86+ }
87+ return result , nil
6188 default :
6289 result := & cns.IPConfigResponse {
6390 PodIpInfo : cns.PodIpInfo {
6491 PodIPConfig : cns.IPSubnet {
6592 IPAddress : "10.0.1.10" ,
6693 PrefixLength : 24 ,
6794 },
95+ MacAddress : "00:11:22:33:44:55" ,
6896 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
6997 IPSubnet : cns.IPSubnet {
7098 IPAddress : "10.0.1.0" ,
@@ -92,11 +120,60 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
92120 switch ipconfig .InfraContainerID {
93121 case "failRequestCNSArgs" :
94122 return nil , errFoo
95- case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" :
123+ case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" , "nilGateway" :
96124 e := & client.CNSClientError {}
97125 e .Code = types .UnsupportedAPI
98126 e .Err = errUnsupportedAPI
99127 return nil , e
128+ case "happyArgsDual" :
129+ result := & cns.IPConfigsResponse {
130+ PodIPInfo : []cns.PodIpInfo {
131+ {
132+ PodIPConfig : cns.IPSubnet {
133+ IPAddress : "10.0.1.10" ,
134+ PrefixLength : 24 ,
135+ },
136+ MacAddress : "00:11:22:33:44:55" ,
137+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
138+ IPSubnet : cns.IPSubnet {
139+ IPAddress : "10.0.1.0" ,
140+ PrefixLength : 24 ,
141+ },
142+ DNSServers : nil ,
143+ GatewayIPAddress : "10.0.0.1" ,
144+ },
145+ HostPrimaryIPInfo : cns.HostIPInfo {
146+ Gateway : "10.0.0.1" ,
147+ PrimaryIP : "10.0.0.1" ,
148+ Subnet : "10.0.0.0/24" ,
149+ },
150+ },
151+ {
152+ PodIPConfig : cns.IPSubnet {
153+ IPAddress : "fd11:1234::1" ,
154+ PrefixLength : 120 ,
155+ },
156+ MacAddress : "00:11:22:33:44:55" , // Same MAC for dual-stack scenario
157+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
158+ IPSubnet : cns.IPSubnet {
159+ IPAddress : "fd11:1234::" ,
160+ PrefixLength : 120 ,
161+ },
162+ DNSServers : nil ,
163+ },
164+ HostPrimaryIPInfo : cns.HostIPInfo {
165+ Gateway : "fe80::1234:5678:9abc" ,
166+ PrimaryIP : "fe80::1234:5678:9abc" ,
167+ Subnet : "fd11:1234::/120" ,
168+ },
169+ },
170+ },
171+ Response : cns.Response {
172+ ReturnCode : 0 ,
173+ Message : "" ,
174+ },
175+ }
176+ return result , nil
100177 case "failProcessCNSResp" :
101178 result := & cns.IPConfigsResponse {
102179 PodIPInfo : []cns.PodIpInfo {
@@ -129,8 +206,7 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
129206 IPAddress : "fd11:1234::" ,
130207 PrefixLength : 112 ,
131208 },
132- DNSServers : nil ,
133- GatewayIPAddress : "fe80::1234:5678:9abc" ,
209+ DNSServers : nil ,
134210 },
135211 HostPrimaryIPInfo : cns.HostIPInfo {
136212 Gateway : "fe80::1234:5678:9abc" ,
@@ -153,6 +229,7 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
153229 IPAddress : "10.0.1.10" ,
154230 PrefixLength : 24 ,
155231 },
232+ MacAddress : "00:11:22:33:44:55" ,
156233 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
157234 IPSubnet : cns.IPSubnet {
158235 IPAddress : "10.0.1.0" ,
@@ -172,13 +249,13 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
172249 IPAddress : "fd11:1234::1" ,
173250 PrefixLength : 120 ,
174251 },
252+ MacAddress : "00:11:22:33:44:55" , // Same MAC for dual-stack scenario
175253 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
176254 IPSubnet : cns.IPSubnet {
177255 IPAddress : "fd11:1234::" ,
178256 PrefixLength : 120 ,
179257 },
180- DNSServers : nil ,
181- GatewayIPAddress : "fe80::1234:5678:9abc" ,
258+ DNSServers : nil ,
182259 },
183260 HostPrimaryIPInfo : cns.HostIPInfo {
184261 Gateway : "fe80::1234:5678:9abc" ,
@@ -281,12 +358,18 @@ func TestCmdAdd(t *testing.T) {
281358 args : buildArgs ("happyArgsSingle" , happyPodArgs , happyNetConfByteArr ),
282359 want : & types100.Result {
283360 CNIVersion : "1.0.0" ,
361+ Interfaces : []* types100.Interface {
362+ {
363+ Mac : "00:11:22:33:44:55" ,
364+ },
365+ },
284366 IPs : []* types100.IPConfig {
285367 {
286368 Address : net.IPNet {
287369 IP : net .IPv4 (10 , 0 , 1 , 10 ),
288370 Mask : net .CIDRMask (24 , 32 ),
289371 },
372+ Gateway : net .IPv4 (10 , 0 , 0 , 1 ),
290373 },
291374 },
292375 DNS : cniTypes.DNS {},
@@ -298,24 +381,36 @@ func TestCmdAdd(t *testing.T) {
298381 args : buildArgs ("happyArgsDual" , happyPodArgs , happyNetConfByteArr ),
299382 want : & types100.Result {
300383 CNIVersion : "1.0.0" ,
384+ Interfaces : []* types100.Interface {
385+ {
386+ Mac : "00:11:22:33:44:55" , // Single interface for dual-stack
387+ },
388+ },
301389 IPs : []* types100.IPConfig {
302390 {
303391 Address : net.IPNet {
304392 IP : net .IPv4 (10 , 0 , 1 , 10 ),
305393 Mask : net .CIDRMask (24 , 32 ),
306394 },
395+ Gateway : net .IPv4 (10 , 0 , 0 , 1 ),
307396 },
308397 {
309398 Address : net.IPNet {
310399 IP : net .ParseIP ("fd11:1234::1" ),
311400 Mask : net .CIDRMask (120 , 128 ),
312401 },
402+ Gateway : net .ParseIP ("fe80::1234:5678:9abc" ),
313403 },
314404 },
315405 DNS : cniTypes.DNS {},
316406 },
317407 wantErr : false ,
318408 },
409+ {
410+ name : "CNI add with nil gateway IP" ,
411+ args : buildArgs ("nilGateway" , happyPodArgs , happyNetConfByteArr ),
412+ wantErr : true ,
413+ },
319414 {
320415 name : "Fail request CNS ipconfig during CmdAdd" ,
321416 args : buildArgs ("failRequestCNSArgs" , happyPodArgs , happyNetConfByteArr ),
0 commit comments