Skip to content

Commit

Permalink
Handle empty string for ip-address returned by imds
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Kvetsinski committed Oct 31, 2024
1 parent a73dc2d commit 054479d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nodeadm/internal/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func getNetworkCardsDetails(ctx context.Context, imdsFunc func(ctx context.Conte
}
return nil, fmt.Errorf("failed to get network card details for MAC %s: %w", mac, err)
}
// ip address can be empty for efa-only cards
if cardDetails.IpAddress == "" {
continue
}

details = append(details, cardDetails)
}

Expand All @@ -107,7 +112,7 @@ func parseAvailableMacs(allMacs string) []string {
func getNetworkCardDetail(ctx context.Context, imdsFunc func(ctx context.Context, prop imds.IMDSProperty) (string, error), mac string) (NetworkCardDetails, error) {
// imds will return 404 if we query network-card object for instance that doesn't support multiple cards
cardIndexPath := imds.IMDSProperty(fmt.Sprintf("network/interfaces/macs/%s/network-card", mac))
// imds will return 404 if we query local-ipv4s object if ip-address is not confirured on the interface from EC2
// imds will return 404 if we query local-ipv4s object if ip-address is not confirured on the interface from EC2 (efa-only)
ipAddressPath := imds.IMDSProperty(fmt.Sprintf("network/interfaces/macs/%s/local-ipv4s", mac))

cardIndex, err := imdsFunc(ctx, cardIndexPath)
Expand Down
7 changes: 7 additions & 0 deletions nodeadm/internal/api/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
`
multicardNoIpOnOneCard = `06:83:e7:fb:fb:fb/
06:83:e7:fc:fc:fc/
06:83:e7:fc:fc:fd/
`
validTwoNetworkCardDetails = []NetworkCardDetails{
{MAC: "06:83:e7:fe:fe:fe", IpAddress: "1.2.3.4", CardIndex: 1},
Expand Down Expand Up @@ -77,12 +78,18 @@ func mockGetPropertyNoIp(ctx context.Context, prop imds.IMDSProperty) (string, e
if prop == "network/interfaces/macs/06:83:e7:fc:fc:fc/network-card" {
return "1", nil
}
if prop == "network/interfaces/macs/06:83:e7:fc:fc:fd/network-card" {
return "2", nil
}
if prop == "network/interfaces/macs/06:83:e7:fb:fb:fb/local-ipv4s" {
return "1.2.3.4", nil
}
if prop == "network/interfaces/macs/06:83:e7:fc:fc:fc/local-ipv4s" {
return "", imds404
}
if prop == "network/interfaces/macs/06:83:e7:fc:fc:fd/local-ipv4s" {
return "", nil
}

return "", nil
}
Expand Down

0 comments on commit 054479d

Please sign in to comment.