@@ -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