Skip to content

Commit

Permalink
Improve error handling when fetching interface device-number data
Browse files Browse the repository at this point in the history
Handle a rare IMDS failure mode in which the service returns a 0 value
for both device-number and network-card for an interface that is not
the primary ENI.
  • Loading branch information
Noah Meyerhans authored and vigh-m committed Mar 6, 2024
1 parent 75b6e5a commit 779468c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ _get_device_number() {

local -i maxtries=60 ntries=0
for (( ntries = 0; ntries < maxtries; ntries++ )); do
device_number=$(get_iface_imds "$ether" device-number)
device_number=$(get_iface_imds "$ether" device-number 1)
# if either the device number or the card index are nonzero,
# then we treat the value returned as valid. Zero values for
# both is only valid for the primary interface, which we've
Expand All @@ -434,6 +434,7 @@ _get_device_number() {
fi
done
error "Unable to identify device-number for $iface after $ntries attempts"
echo -1
return 1
}

Expand Down Expand Up @@ -464,12 +465,17 @@ _get_network_card() {
# interface-specific routing table.
setup_interface() {
local iface ether
local -i device_number network_card
local -i device_number network_card rc
iface=$1
ether=$2

network_card=$(_get_network_card "$iface" "$ether")
device_number=$(_get_device_number "$iface" "$ether" "$network_card")
rc=$?
if [ $rc -ne 0 ]; then
error "Unable to identify device-number for $iface in IMDS"
exit 1
fi

# Newly provisioned resources (new ENI attachments) take some
# time to be fully reflected in IMDS. In that case, we poll
Expand Down

0 comments on commit 779468c

Please sign in to comment.