Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for "forwarded-ip[v6]s" to be available from metadata server before reading value #267

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Description=Writes metadata to a known location
Before=setup-after-boot.service

# This unit writes data to the disk which gets mounted in various containers.
# Be sure that this unit runs before the kubelet to be sure that no k8s
# workloads start running before this unit has completed.
Before=kubelet.service

# generate-eth0-config.service sets the hostname of the machine to the expected
# M-Lab DNS name for the machine. Since this write-metadata unit writes the
# hostname value to the metadata directory, then be sure this unit runs later,
Expand Down
14 changes: 14 additions & 0 deletions configs/virtual_ubuntu/opt/mlab/bin/write-metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ is_mig=$(
)

if [[ $is_mig == "200" ]]; then
# It was discovered that there is some sort of race condition between this
# script and GCP fully populating VM metadata, specifically the
# "forwarded-ip[v6]s" values, requests for which were occasionally returning a
# 404, other times not. This loop just makes sure that one of those values
# exists before trying to read the value.
metadata_status=""
until [[ $metadata_status == "200" ]]; do
sleep 5
metadata_status=$(
curl "${CURL_FLAGS[@]}" --output /dev/null --write-out "%{http_code}" \
"${METADATA_URL}/network-interfaces/0/forwarded-ips/0" \
|| true
)
done
echo -n "true" > $METADATA_DIR/loadbalanced
external_ip=$(curl "${CURL_FLAGS[@]}" "${METADATA_URL}/network-interfaces/0/forwarded-ips/0")
external_ipv6=$(curl "${CURL_FLAGS[@]}" "${METADATA_URL}/network-interfaces/0/forwarded-ipv6s/0")
Expand Down