@@ -559,21 +559,39 @@ func (r *NodeENIReconciler) createENI(ctx context.Context, nodeENI *networkingv1
559559 }
560560
561561 // Determine the security group IDs to use
562- securityGroupIDs := nodeENI .Spec .SecurityGroupIDs
563- if len (securityGroupIDs ) == 0 && len (nodeENI .Spec .SecurityGroupNames ) > 0 {
564- // Look up security group IDs by name
562+ var securityGroupIDs []string
563+
564+ // First, use any explicitly provided security group IDs
565+ if len (nodeENI .Spec .SecurityGroupIDs ) > 0 {
566+ securityGroupIDs = append (securityGroupIDs , nodeENI .Spec .SecurityGroupIDs ... )
567+ }
568+
569+ // Then, look up any security group names and add those IDs
570+ if len (nodeENI .Spec .SecurityGroupNames ) > 0 {
565571 for _ , sgName := range nodeENI .Spec .SecurityGroupNames {
566572 sgID , err := r .getSecurityGroupIDByName (ctx , sgName )
567573 if err != nil {
568574 return "" , fmt .Errorf ("failed to get security group ID from name %s: %v" , sgName , err )
569575 }
570576 r .Log .Info ("Resolved security group name to ID" , "securityGroupName" , sgName , "securityGroupID" , sgID )
571- securityGroupIDs = append (securityGroupIDs , sgID )
577+
578+ // Check if this ID is already in the list (to avoid duplicates)
579+ isDuplicate := false
580+ for _ , existingID := range securityGroupIDs {
581+ if existingID == sgID {
582+ isDuplicate = true
583+ break
584+ }
585+ }
586+
587+ if ! isDuplicate {
588+ securityGroupIDs = append (securityGroupIDs , sgID )
589+ }
572590 }
573591 }
574592
575593 if len (securityGroupIDs ) == 0 {
576- return "" , fmt .Errorf ("neither securityGroupIDs nor securityGroupNames provided" )
594+ return "" , fmt .Errorf ("neither securityGroupIDs nor securityGroupNames provided, or all lookups failed " )
577595 }
578596
579597 input := & ec2.CreateNetworkInterfaceInput {
0 commit comments