Skip to content

Commit 573f656

Browse files
committed
Updated ipam to only send macaddr
1 parent 75d1d54 commit 573f656

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

azure-ipam/ipam.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,24 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
143143
cniResult.IPs[i] = ipConfig
144144
}
145145

146-
cniResult.Interfaces = make([]*types100.Interface, 1)
147-
interfaceMap := make(map[string]bool)
148-
cniResult.Interfaces = make([]*types100.Interface, 0, len(resp.PodIPInfo))
146+
cniResult.Interfaces = []*types100.Interface{}
147+
seenInterfaces := map[string]bool{}
148+
149149
for _, podIPInfo := range resp.PodIPInfo {
150-
if _, exists := interfaceMap[podIPInfo.InterfaceName]; !exists {
151-
cniResult.Interfaces = append(cniResult.Interfaces, &types100.Interface{
152-
Name: podIPInfo.InterfaceName, // Populate interface name based on MacAddress
153-
Mac: podIPInfo.MacAddress,
154-
})
155-
interfaceMap[podIPInfo.InterfaceName] = true
150+
if seenInterfaces[podIPInfo.MacAddress] {
151+
continue
152+
}
153+
154+
infMac, err := net.ParseMAC(podIPInfo.MacAddress)
155+
if err != nil {
156+
p.logger.Error("Failed to parse interface MAC address", zap.Error(err), zap.String("macAddress", podIPInfo.MacAddress))
157+
return cniTypes.NewError(cniTypes.ErrUnsupportedField, err.Error(), "failed to parse interface MAC address")
156158
}
159+
160+
cniResult.Interfaces = append(cniResult.Interfaces, &types100.Interface{
161+
Mac: infMac.String(),
162+
})
163+
seenInterfaces[podIPInfo.MacAddress] = true
157164
}
158165

159166
// Get versioned result

0 commit comments

Comments
 (0)