From 054479debd589d9f078f6c12fabc09b4135de2b9 Mon Sep 17 00:00:00 2001 From: Nikolay Kvetsinski Date: Thu, 31 Oct 2024 12:15:26 -0700 Subject: [PATCH] Handle empty string for ip-address returned by imds --- nodeadm/internal/api/status.go | 7 ++++++- nodeadm/internal/api/status_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nodeadm/internal/api/status.go b/nodeadm/internal/api/status.go index c301fb803..a35a0e896 100644 --- a/nodeadm/internal/api/status.go +++ b/nodeadm/internal/api/status.go @@ -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) } @@ -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) diff --git a/nodeadm/internal/api/status_test.go b/nodeadm/internal/api/status_test.go index e1df13c59..5a6d37d49 100644 --- a/nodeadm/internal/api/status_test.go +++ b/nodeadm/internal/api/status_test.go @@ -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}, @@ -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 }