@@ -1412,12 +1412,23 @@ func (r *NodeENIReconciler) buildAttachmentMaps(nodeENI *networkingv1alpha1.Node
14121412 usedDeviceIndices map [int ]bool ,
14131413 subnetToDeviceIndex map [string ]int ,
14141414) {
1415+ log := r .Log .WithValues ("nodeeni" , nodeENI .Name , "node" , nodeName )
1416+
14151417 existingSubnets = make (map [string ]bool )
14161418 usedDeviceIndices = make (map [int ]bool )
14171419 subnetToDeviceIndex = make (map [string ]int )
14181420
1421+ log .Info ("Building attachment maps" , "totalAttachments" , len (nodeENI .Status .Attachments ))
1422+
14191423 // First pass: build the subnet to device index mapping from existing attachments
14201424 for _ , attachment := range nodeENI .Status .Attachments {
1425+ log .V (1 ).Info ("Processing attachment" ,
1426+ "nodeID" , attachment .NodeID ,
1427+ "eniID" , attachment .ENIID ,
1428+ "subnetID" , attachment .SubnetID ,
1429+ "deviceIndex" , attachment .DeviceIndex ,
1430+ "isCurrentNode" , attachment .NodeID == nodeName )
1431+
14211432 // We want to build a global mapping across all nodes
14221433 if attachment .SubnetID != "" && attachment .DeviceIndex > 0 {
14231434 // If we haven't seen this subnet before, or if this device index is lower
@@ -1430,14 +1441,21 @@ func (r *NodeENIReconciler) buildAttachmentMaps(nodeENI *networkingv1alpha1.Node
14301441 // For this specific node, track which subnets already have ENIs
14311442 if attachment .NodeID == nodeName && attachment .SubnetID != "" {
14321443 existingSubnets [attachment .SubnetID ] = true
1444+ log .Info ("Found existing ENI for node in subnet" , "subnetID" , attachment .SubnetID , "eniID" , attachment .ENIID )
14331445 }
14341446
14351447 // For this specific node, track which device indices are already in use
14361448 if attachment .NodeID == nodeName && attachment .DeviceIndex > 0 {
14371449 usedDeviceIndices [attachment .DeviceIndex ] = true
1450+ log .Info ("Found used device index for node" , "deviceIndex" , attachment .DeviceIndex , "eniID" , attachment .ENIID )
14381451 }
14391452 }
14401453
1454+ log .Info ("Built attachment maps" ,
1455+ "existingSubnets" , existingSubnets ,
1456+ "usedDeviceIndices" , usedDeviceIndices ,
1457+ "subnetToDeviceIndex" , subnetToDeviceIndex )
1458+
14411459 return existingSubnets , usedDeviceIndices , subnetToDeviceIndex
14421460}
14431461
@@ -1454,22 +1472,32 @@ func (r *NodeENIReconciler) createMissingENIs(
14541472) {
14551473 log := r .Log .WithValues ("nodeeni" , nodeENI .Name , "node" , node .Name )
14561474
1475+ log .Info ("Processing subnets for ENI creation" ,
1476+ "totalSubnets" , len (subnetIDs ),
1477+ "subnetIDs" , subnetIDs ,
1478+ "existingSubnets" , existingSubnets ,
1479+ "usedDeviceIndices" , usedDeviceIndices )
1480+
14571481 for i , subnetID := range subnetIDs {
14581482 // Skip if we already have an ENI in this subnet
14591483 if existingSubnets [subnetID ] {
1460- log .Info ("Node already has an ENI in this subnet" , "subnetID" , subnetID )
1484+ log .Info ("Node already has an ENI in this subnet, skipping " , "subnetID" , subnetID )
14611485 continue
14621486 }
14631487
1488+ log .Info ("Creating ENI for subnet" , "subnetID" , subnetID , "subnetIndex" , i )
1489+
14641490 // Determine the device index to use for this subnet
14651491 deviceIndex := r .determineDeviceIndex (nodeENI , subnetID , i , subnetToDeviceIndex , usedDeviceIndices , log )
14661492
14671493 // Create and attach a new ENI for this subnet
14681494 if err := r .createAndAttachENIForSubnet (ctx , nodeENI , node , instanceID , subnetID , deviceIndex ); err != nil {
1469- log .Error (err , "Failed to create and attach ENI for subnet" , "subnetID" , subnetID )
1495+ log .Error (err , "Failed to create and attach ENI for subnet" , "subnetID" , subnetID , "deviceIndex" , deviceIndex )
14701496 // Continue with other subnets even if one fails
14711497 continue
14721498 }
1499+
1500+ log .Info ("Successfully created and attached ENI for subnet" , "subnetID" , subnetID , "deviceIndex" , deviceIndex )
14731501 }
14741502}
14751503
@@ -1602,6 +1630,14 @@ func (r *NodeENIReconciler) createAndAttachENIForSubnet(ctx context.Context, nod
16021630 LastUpdated : metav1 .Now (),
16031631 })
16041632
1633+ // Update the NodeENI status immediately to prevent race conditions
1634+ // This ensures that subsequent reconciliations see the attachment
1635+ if err := r .updateNodeENIStatusWithRetry (ctx , nodeENI ); err != nil {
1636+ log .Error (err , "Failed to update NodeENI status after ENI attachment" , "eniID" , eniID )
1637+ // Don't return error here as the ENI is already attached successfully
1638+ // The status will be updated in the next reconciliation
1639+ }
1640+
16051641 r .Recorder .Eventf (nodeENI , corev1 .EventTypeNormal , "ENIAttached" ,
16061642 "Successfully attached ENI %s to node %s in subnet %s" , eniID , node .Name , subnetID )
16071643
0 commit comments