@@ -58,13 +58,68 @@ 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
88+ case "invalidGateway" :
89+ result := & cns.IPConfigResponse {
90+ PodIpInfo : cns.PodIpInfo {
91+ PodIPConfig : cns.IPSubnet {
92+ IPAddress : "10.0.1.10" ,
93+ PrefixLength : 24 ,
94+ },
95+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
96+ IPSubnet : cns.IPSubnet {
97+ IPAddress : "10.0.1.0" ,
98+ PrefixLength : 24 ,
99+ },
100+ DNSServers : nil ,
101+ GatewayIPAddress : "invalidgatewayip" ,
102+ },
103+ HostPrimaryIPInfo : cns.HostIPInfo {
104+ Gateway : "invalidgatewayip" ,
105+ PrimaryIP : "10.0.0.1" ,
106+ Subnet : "10.0.0.0/24" ,
107+ },
108+ },
109+ Response : cns.Response {
110+ ReturnCode : 0 ,
111+ Message : "" ,
112+ },
113+ }
114+ return result , nil
61115 default :
62116 result := & cns.IPConfigResponse {
63117 PodIpInfo : cns.PodIpInfo {
64118 PodIPConfig : cns.IPSubnet {
65119 IPAddress : "10.0.1.10" ,
66120 PrefixLength : 24 ,
67121 },
122+ MacAddress : "00:11:22:33:44:55" ,
68123 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
69124 IPSubnet : cns.IPSubnet {
70125 IPAddress : "10.0.1.0" ,
@@ -92,11 +147,60 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
92147 switch ipconfig .InfraContainerID {
93148 case "failRequestCNSArgs" :
94149 return nil , errFoo
95- case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" :
150+ case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" , "nilGateway" , "invalidGateway" :
96151 e := & client.CNSClientError {}
97152 e .Code = types .UnsupportedAPI
98153 e .Err = errUnsupportedAPI
99154 return nil , e
155+ case "happyArgsDual" :
156+ result := & cns.IPConfigsResponse {
157+ PodIPInfo : []cns.PodIpInfo {
158+ {
159+ PodIPConfig : cns.IPSubnet {
160+ IPAddress : "10.0.1.10" ,
161+ PrefixLength : 24 ,
162+ },
163+ MacAddress : "00:11:22:33:44:55" ,
164+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
165+ IPSubnet : cns.IPSubnet {
166+ IPAddress : "10.0.1.0" ,
167+ PrefixLength : 24 ,
168+ },
169+ DNSServers : nil ,
170+ GatewayIPAddress : "10.0.0.1" ,
171+ },
172+ HostPrimaryIPInfo : cns.HostIPInfo {
173+ Gateway : "10.0.0.1" ,
174+ PrimaryIP : "10.0.0.1" ,
175+ Subnet : "10.0.0.0/24" ,
176+ },
177+ },
178+ {
179+ PodIPConfig : cns.IPSubnet {
180+ IPAddress : "fd11:1234::1" ,
181+ PrefixLength : 120 ,
182+ },
183+ MacAddress : "00:11:22:33:44:55" , // Same MAC for dual-stack scenario
184+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
185+ IPSubnet : cns.IPSubnet {
186+ IPAddress : "fd11:1234::" ,
187+ PrefixLength : 120 ,
188+ },
189+ DNSServers : nil ,
190+ },
191+ HostPrimaryIPInfo : cns.HostIPInfo {
192+ Gateway : "fe80::1234:5678:9abc" ,
193+ PrimaryIP : "fe80::1234:5678:9abc" ,
194+ Subnet : "fd11:1234::/120" ,
195+ },
196+ },
197+ },
198+ Response : cns.Response {
199+ ReturnCode : 0 ,
200+ Message : "" ,
201+ },
202+ }
203+ return result , nil
100204 case "failProcessCNSResp" :
101205 result := & cns.IPConfigsResponse {
102206 PodIPInfo : []cns.PodIpInfo {
@@ -129,8 +233,7 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
129233 IPAddress : "fd11:1234::" ,
130234 PrefixLength : 112 ,
131235 },
132- DNSServers : nil ,
133- GatewayIPAddress : "fe80::1234:5678:9abc" ,
236+ DNSServers : nil ,
134237 },
135238 HostPrimaryIPInfo : cns.HostIPInfo {
136239 Gateway : "fe80::1234:5678:9abc" ,
@@ -153,6 +256,7 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
153256 IPAddress : "10.0.1.10" ,
154257 PrefixLength : 24 ,
155258 },
259+ MacAddress : "00:11:22:33:44:55" ,
156260 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
157261 IPSubnet : cns.IPSubnet {
158262 IPAddress : "10.0.1.0" ,
@@ -172,13 +276,13 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
172276 IPAddress : "fd11:1234::1" ,
173277 PrefixLength : 120 ,
174278 },
279+ MacAddress : "00:11:22:33:44:55" , // Same MAC for dual-stack scenario
175280 NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
176281 IPSubnet : cns.IPSubnet {
177282 IPAddress : "fd11:1234::" ,
178283 PrefixLength : 120 ,
179284 },
180- DNSServers : nil ,
181- GatewayIPAddress : "fe80::1234:5678:9abc" ,
285+ DNSServers : nil ,
182286 },
183287 HostPrimaryIPInfo : cns.HostIPInfo {
184288 Gateway : "fe80::1234:5678:9abc" ,
@@ -281,12 +385,18 @@ func TestCmdAdd(t *testing.T) {
281385 args : buildArgs ("happyArgsSingle" , happyPodArgs , happyNetConfByteArr ),
282386 want : & types100.Result {
283387 CNIVersion : "1.0.0" ,
388+ Interfaces : []* types100.Interface {
389+ {
390+ Mac : "00:11:22:33:44:55" ,
391+ },
392+ },
284393 IPs : []* types100.IPConfig {
285394 {
286395 Address : net.IPNet {
287396 IP : net .IPv4 (10 , 0 , 1 , 10 ),
288397 Mask : net .CIDRMask (24 , 32 ),
289398 },
399+ Gateway : net .IPv4 (10 , 0 , 0 , 1 ),
290400 },
291401 },
292402 DNS : cniTypes.DNS {},
@@ -298,24 +408,55 @@ func TestCmdAdd(t *testing.T) {
298408 args : buildArgs ("happyArgsDual" , happyPodArgs , happyNetConfByteArr ),
299409 want : & types100.Result {
300410 CNIVersion : "1.0.0" ,
411+ Interfaces : []* types100.Interface {
412+ {
413+ Mac : "00:11:22:33:44:55" , // Single interface for dual-stack
414+ },
415+ },
301416 IPs : []* types100.IPConfig {
302417 {
303418 Address : net.IPNet {
304419 IP : net .IPv4 (10 , 0 , 1 , 10 ),
305420 Mask : net .CIDRMask (24 , 32 ),
306421 },
422+ Gateway : net .IPv4 (10 , 0 , 0 , 1 ),
307423 },
308424 {
309425 Address : net.IPNet {
310426 IP : net .ParseIP ("fd11:1234::1" ),
311427 Mask : net .CIDRMask (120 , 128 ),
312428 },
429+ Gateway : net .ParseIP ("fe80::1234:5678:9abc" ),
313430 },
314431 },
315432 DNS : cniTypes.DNS {},
316433 },
317434 wantErr : false ,
318435 },
436+ {
437+ name : "CNI add with nil gateway IP" ,
438+ args : buildArgs ("nilGateway" , happyPodArgs , happyNetConfByteArr ),
439+ want : & types100.Result {
440+ CNIVersion : "1.0.0" ,
441+ Interfaces : nil ,
442+ IPs : []* types100.IPConfig {
443+ {
444+ Address : net.IPNet {
445+ IP : net .IPv4 (10 , 0 , 1 , 10 ),
446+ Mask : net .CIDRMask (24 , 32 ),
447+ },
448+ Gateway : nil , // No gateway
449+ },
450+ },
451+ DNS : cniTypes.DNS {},
452+ },
453+ wantErr : false ,
454+ },
455+ {
456+ name : "CNI add with invalid gateway IP" ,
457+ args : buildArgs ("invalidGateway" , happyPodArgs , happyNetConfByteArr ),
458+ wantErr : true ,
459+ },
319460 {
320461 name : "Fail request CNS ipconfig during CmdAdd" ,
321462 args : buildArgs ("failRequestCNSArgs" , happyPodArgs , happyNetConfByteArr ),
0 commit comments