@@ -610,9 +610,7 @@ func (cache *EC2InstanceMetadataCache) getENIMetadata(eniMAC string) (ENIMetadat
610610 awsAPIErrInc ("GetMACImdsFields" , err )
611611 return ENIMetadata {}, err
612612 }
613-
614- ipv4Available := false
615- ipv6Available := false
613+ ipInfoAvailable := false
616614 // Efa-only interfaces do not have any ipv4s or ipv6s associated with it. If we don't find any local-ipv4 or ipv6 info in imds we assume it to be efa-only interface and validate this later via ec2 call
617615 for _ , field := range macImdsFields {
618616 if field == "local-ipv4s" {
@@ -622,7 +620,7 @@ func (cache *EC2InstanceMetadataCache) getENIMetadata(eniMAC string) (ENIMetadat
622620 return ENIMetadata {}, err
623621 }
624622 if len (imdsIPv4s ) > 0 {
625- ipv4Available = true
623+ ipInfoAvailable = true
626624 log .Debugf ("Found IPv4 addresses associated with interface. This is not efa-only interface" )
627625 break
628626 }
@@ -632,14 +630,14 @@ func (cache *EC2InstanceMetadataCache) getENIMetadata(eniMAC string) (ENIMetadat
632630 if err != nil {
633631 awsAPIErrInc ("GetIPv6s" , err )
634632 } else if len (imdsIPv6s ) > 0 {
635- ipv6Available = true
633+ ipInfoAvailable = true
636634 log .Debugf ("Found IPv6 addresses associated with interface. This is not efa-only interface" )
637635 break
638636 }
639637 }
640638 }
641639
642- if ! ipv4Available && ! ipv6Available {
640+ if ! ipInfoAvailable {
643641 return ENIMetadata {
644642 ENIID : eniID ,
645643 MAC : eniMAC ,
@@ -654,29 +652,23 @@ func (cache *EC2InstanceMetadataCache) getENIMetadata(eniMAC string) (ENIMetadat
654652 }
655653
656654 // Get IPv4 and IPv6 addresses assigned to interface
657- var ec2ip4s []* ec2.NetworkInterfacePrivateIpAddress
658- var subnetV4Cidr string
659- if ipv4Available {
660- cidr , err := cache .imds .GetSubnetIPv4CIDRBlock (ctx , eniMAC )
661- if err != nil {
662- awsAPIErrInc ("GetSubnetIPv4CIDRBlock" , err )
663- return ENIMetadata {}, err
664- }
665-
666- subnetV4Cidr = cidr .String ()
655+ cidr , err := cache .imds .GetSubnetIPv4CIDRBlock (ctx , eniMAC )
656+ if err != nil {
657+ awsAPIErrInc ("GetSubnetIPv4CIDRBlock" , err )
658+ return ENIMetadata {}, err
659+ }
667660
668- imdsIPv4s , err := cache .imds .GetLocalIPv4s (ctx , eniMAC )
669- if err != nil {
670- awsAPIErrInc ("GetLocalIPv4s" , err )
671- return ENIMetadata {}, err
672- }
661+ imdsIPv4s , err := cache .imds .GetLocalIPv4s (ctx , eniMAC )
662+ if err != nil {
663+ awsAPIErrInc ("GetLocalIPv4s" , err )
664+ return ENIMetadata {}, err
665+ }
673666
674- ec2ip4s = make ([]* ec2.NetworkInterfacePrivateIpAddress , len (imdsIPv4s ))
675- for i , ip4 := range imdsIPv4s {
676- ec2ip4s [i ] = & ec2.NetworkInterfacePrivateIpAddress {
677- Primary : aws .Bool (i == 0 ),
678- PrivateIpAddress : aws .String (ip4 .String ()),
679- }
667+ ec2ip4s := make ([]* ec2.NetworkInterfacePrivateIpAddress , len (imdsIPv4s ))
668+ for i , ip4 := range imdsIPv4s {
669+ ec2ip4s [i ] = & ec2.NetworkInterfacePrivateIpAddress {
670+ Primary : aws .Bool (i == 0 ),
671+ PrivateIpAddress : aws .String (ip4 .String ()),
680672 }
681673 }
682674
@@ -740,7 +732,7 @@ func (cache *EC2InstanceMetadataCache) getENIMetadata(eniMAC string) (ENIMetadat
740732 ENIID : eniID ,
741733 MAC : eniMAC ,
742734 DeviceNumber : deviceNum ,
743- SubnetIPv4CIDR : subnetV4Cidr ,
735+ SubnetIPv4CIDR : cidr . String () ,
744736 IPv4Addresses : ec2ip4s ,
745737 IPv4Prefixes : ec2ipv4Prefixes ,
746738 SubnetIPv6CIDR : subnetV6Cidr ,
@@ -1415,17 +1407,14 @@ func (cache *EC2InstanceMetadataCache) DescribeAllENIs() (DescribeAllENIsResult,
14151407 efaENIs [eniID ] = true
14161408 }
14171409 if interfaceType != "efa-only" {
1418- if len (eniMetadata .IPv4Addresses ) == 0 && len ( eniMetadata . IPv6Addresses ) == 0 {
1410+ if len (eniMetadata .IPv4Addresses ) == 0 {
14191411 log .Errorf ("Missing IP addresses from IMDS. Non efa-only interface should have IP address associated with it %s" , eniID )
1420- outOfSyncErr := errors .New ("DescribeAllENIs: No IPv4 and IPv6 addresses found" )
1412+ outOfSyncErr := errors .New ("DescribeAllENIs: No IPv4 address found" )
14211413 return DescribeAllENIsResult {}, outOfSyncErr
14221414 }
14231415 }
1424-
14251416 // Check IPv4 addresses
1426- if len (eniMetadata .IPv4Addresses ) > 0 {
1427- logOutOfSyncState (eniID , eniMetadata .IPv4Addresses , ec2res .PrivateIpAddresses )
1428- }
1417+ logOutOfSyncState (eniID , eniMetadata .IPv4Addresses , ec2res .PrivateIpAddresses )
14291418 tagMap [eniMetadata .ENIID ] = convertSDKTagsToTags (ec2res .TagSet )
14301419 }
14311420 return DescribeAllENIsResult {
0 commit comments