mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 19:56:32 +02:00
fix(coreos-base/oem-gce): Replace curl's --retry with block_until_url
Curl will not retry after most errors, just connection timeouts and some HTTP errors. In our case the most likely error is network unreachable. Instead use our simple-minded but trusty block_until_url script to wait.
This commit is contained in:
parent
4e2597c238
commit
6a9e81713a
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
URL_PREFIX="http://169.254.169.254/computeMetadata/v1/"
|
||||
METADATA_URL="http://169.254.169.254/computeMetadata/"
|
||||
TMPFILE=$(mktemp /tmp/XXXXXX-cloud-init)
|
||||
if [[ $? -ne 0 || ! -f "${TMPFILE}" ]]; then
|
||||
echo "Failed to create temp file for user-data" >&2
|
||||
@ -10,11 +10,12 @@ trap "rm -f '${TMPFILE}'" EXIT
|
||||
|
||||
try_cloudinit() {
|
||||
local id="$1"
|
||||
local url="${URL_PREFIX}${id}/attributes/user-data"
|
||||
local url="${METADATA_URL}v1/${id}/attributes/user-data"
|
||||
|
||||
echo "Trying to fetch $id user-data..."
|
||||
curl --retry 5 --retry-delay 2 --silent --fail --show-error \
|
||||
-H "X-Google-Metadata-Request: True" -o "${TMPFILE}" "${url}"
|
||||
curl --fail --silent --show-error \
|
||||
-H "X-Google-Metadata-Request: True" \
|
||||
-o "${TMPFILE}" "${url}"
|
||||
|
||||
ret=$?
|
||||
if [[ $ret -ne 0 && $ret -ne 22 ]]; then
|
||||
@ -29,4 +30,5 @@ try_cloudinit() {
|
||||
return $?
|
||||
}
|
||||
|
||||
block-until-url "${METADATA_URL}"
|
||||
try_cloudinit project && try_cloudinit instance
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
ENV=$1
|
||||
METADATA_URL="http://169.254.169.254/computeMetadata/"
|
||||
|
||||
if [ -z "$ENV" ]; then
|
||||
echo usage: $0 /etc/environment
|
||||
@ -14,18 +15,19 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_value() {
|
||||
curl --fail --silent --show-error \
|
||||
-H "X-Google-Metadata-Request: True" \
|
||||
"${METADATA_URL}v1/instance/$1"
|
||||
}
|
||||
|
||||
block-until-url "${METADATA_URL}"
|
||||
external_ip=$(get_value network-interfaces/0/access-configs/0/external-ip)
|
||||
public_ip=$(get_value network-interfaces/0/ip)
|
||||
|
||||
sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
|
||||
-e '/^COREOS_PRIVATE_IPV4=/d' \
|
||||
"${ENV}"
|
||||
|
||||
external_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
|
||||
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" \
|
||||
-H "X-Google-Metadata-Request: True")
|
||||
|
||||
|
||||
public_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
|
||||
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/ip" \
|
||||
-H "X-Google-Metadata-Request: True")
|
||||
|
||||
echo COREOS_PUBLIC_IPV4=${external_ip} >> $ENV
|
||||
echo COREOS_PRIVATE_IPV4=${public_ip} >> $ENV
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user