@@ -1422,7 +1422,9 @@ func (c *Cloud) NodeAddresses(ctx context.Context, name types.NodeName) ([]v1.No
1422
1422
// We want the IPs to end up in order by interface (in particular, we want eth0's
1423
1423
// IPs first), but macs isn't necessarily sorted in that order so we have to
1424
1424
// explicitly order by device-number (device-number == the "0" in "eth0").
1425
- macIPs := make (map [int ]string )
1425
+
1426
+ var macIDs []string
1427
+ macDevNum := make (map [string ]int )
1426
1428
for _ , macID := range strings .Split (macs , "\n " ) {
1427
1429
if macID == "" {
1428
1430
continue
@@ -1437,18 +1439,22 @@ func (c *Cloud) NodeAddresses(ctx context.Context, name types.NodeName) ([]v1.No
1437
1439
klog .Warningf ("Bad device-number %q for interface %s\n " , numStr , macID )
1438
1440
continue
1439
1441
}
1442
+ macIDs = append (macIDs , macID )
1443
+ macDevNum [macID ] = num
1444
+ }
1445
+
1446
+ // Sort macIDs by interface device-number
1447
+ sort .Slice (macIDs , func (i , j int ) bool {
1448
+ return macDevNum [macIDs [i ]] < macDevNum [macIDs [j ]]
1449
+ })
1450
+
1451
+ for _ , macID := range macIDs {
1440
1452
ipPath := path .Join ("network/interfaces/macs/" , macID , "local-ipv4s" )
1441
- macIPs [ num ] , err = c .metadata .GetMetadata (ipPath )
1453
+ internalIPs , err : = c .metadata .GetMetadata (ipPath )
1442
1454
if err != nil {
1443
1455
return nil , fmt .Errorf ("error querying AWS metadata for %q: %q" , ipPath , err )
1444
1456
}
1445
- }
1446
1457
1447
- for i := 0 ; i < len (macIPs ); i ++ {
1448
- internalIPs := macIPs [i ]
1449
- if internalIPs == "" {
1450
- continue
1451
- }
1452
1458
for _ , internalIP := range strings .Split (internalIPs , "\n " ) {
1453
1459
if internalIP == "" {
1454
1460
continue
0 commit comments