Skip to content

Commit 26be9a4

Browse files
update test to handle gatway nil case
1 parent 8806489 commit 26be9a4

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

azure-ipam/ipam_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,9 @@ func TestCmdAdd(t *testing.T) {
347347
wantErr: false,
348348
},
349349
{
350-
name: "CNI add with nil gateway IP",
351-
args: buildArgs("nilGateway", happyPodArgs, happyNetConfByteArr),
352-
want: &types100.Result{
353-
CNIVersion: "1.0.0",
354-
IPs: []*types100.IPConfig{
355-
{
356-
Address: net.IPNet{
357-
IP: net.IPv4(10, 0, 1, 10),
358-
Mask: net.CIDRMask(24, 32),
359-
},
360-
},
361-
},
362-
DNS: cniTypes.DNS{},
363-
},
364-
wantErr: false,
350+
name: "CNI add with nil gateway IP",
351+
args: buildArgs("nilGateway", happyPodArgs, happyNetConfByteArr),
352+
wantErr: true,
365353
},
366354
{
367355
name: "Fail request CNS ipconfig during CmdAdd",

azure-ipam/ipconfig/ipconfig.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ func ProcessIPConfigsResp(resp *cns.IPConfigsResponse) (*[]netip.Prefix, *[]net.
8989
gatewayStr = resp.PodIPInfo[i].NetworkContainerPrimaryIPConfig.GatewayIPv6Address
9090
}
9191

92-
if gatewayStr != "" {
93-
gatewayIP = net.ParseIP(gatewayStr)
94-
if gatewayIP == nil {
95-
return nil, nil, errors.Errorf("failed to parse gateway IP %q for pod ip %s", gatewayStr, resp.PodIPInfo[i].PodIPConfig.IPAddress)
96-
}
92+
gatewayIP = net.ParseIP(gatewayStr)
93+
if gatewayIP == nil {
94+
return nil, nil, errors.Errorf("failed to parse gateway IP %q for pod ip %s", gatewayStr, resp.PodIPInfo[i].PodIPConfig.IPAddress)
9795
}
9896
gatewaysIPs[i] = gatewayIP
9997
}

0 commit comments

Comments
 (0)