mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #101015 from mborsz/retry
Do not grep for curl --help for --retry-connrefused
This commit is contained in:
commit
74497632f4
@ -2296,10 +2296,8 @@ function download-extra-addons {
|
|||||||
"--retry-delay" "3"
|
"--retry-delay" "3"
|
||||||
"--silent"
|
"--silent"
|
||||||
"--show-error"
|
"--show-error"
|
||||||
|
"--retry-connrefused"
|
||||||
)
|
)
|
||||||
if [[ -n "${CURL_RETRY_CONNREFUSED:-}" ]]; then
|
|
||||||
curl_cmd+=("${CURL_RETRY_CONNREFUSED}")
|
|
||||||
fi
|
|
||||||
if [[ -n "${EXTRA_ADDONS_HEADER:-}" ]]; then
|
if [[ -n "${EXTRA_ADDONS_HEADER:-}" ]]; then
|
||||||
curl_cmd+=("-H" "${EXTRA_ADDONS_HEADER}")
|
curl_cmd+=("-H" "${EXTRA_ADDONS_HEADER}")
|
||||||
fi
|
fi
|
||||||
@ -2320,12 +2318,10 @@ function get-metadata-value {
|
|||||||
local default="${2:-}"
|
local default="${2:-}"
|
||||||
|
|
||||||
local status
|
local status
|
||||||
# We do not want quotes for CURL_RETRY_CONNREFUSED
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
curl \
|
curl \
|
||||||
--retry 5 \
|
--retry 5 \
|
||||||
--retry-delay 3 \
|
--retry-delay 3 \
|
||||||
${CURL_RETRY_CONNREFUSED} \
|
--retry-connrefused \
|
||||||
--fail \
|
--fail \
|
||||||
--silent \
|
--silent \
|
||||||
-H 'Metadata-Flavor: Google' \
|
-H 'Metadata-Flavor: Google' \
|
||||||
@ -3120,13 +3116,6 @@ function detect_host_info() {
|
|||||||
# NOTE: this function is duplicated in configure.sh, any changes here should be
|
# NOTE: this function is duplicated in configure.sh, any changes here should be
|
||||||
# duplicated there as well.
|
# duplicated there as well.
|
||||||
function log-init {
|
function log-init {
|
||||||
# CURL_RETRY_CONNREFUSED needs to be defined before calling get-metadata-value.
|
|
||||||
# Use --retry-connrefused opt only if it's supported by curl.
|
|
||||||
CURL_RETRY_CONNREFUSED=""
|
|
||||||
if curl --help | grep -q -- '--retry-connrefused'; then
|
|
||||||
CURL_RETRY_CONNREFUSED='--retry-connrefused'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Used by log-* functions.
|
# Used by log-* functions.
|
||||||
LOG_CLUSTER_ID=$(get-metadata-value 'instance/attributes/cluster-uid' 'get-metadata-value-error')
|
LOG_CLUSTER_ID=$(get-metadata-value 'instance/attributes/cluster-uid' 'get-metadata-value-error')
|
||||||
LOG_INSTANCE_NAME=$(hostname)
|
LOG_INSTANCE_NAME=$(hostname)
|
||||||
|
@ -59,12 +59,10 @@ function get-metadata-value {
|
|||||||
local default="${2:-}"
|
local default="${2:-}"
|
||||||
|
|
||||||
local status
|
local status
|
||||||
# We do not want quotes for CURL_RETRY_CONNREFUSED
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
curl \
|
curl \
|
||||||
--retry 5 \
|
--retry 5 \
|
||||||
--retry-delay 3 \
|
--retry-delay 3 \
|
||||||
${CURL_RETRY_CONNREFUSED} \
|
--retry-connrefused \
|
||||||
--fail \
|
--fail \
|
||||||
--silent \
|
--silent \
|
||||||
-H 'Metadata-Flavor: Google' \
|
-H 'Metadata-Flavor: Google' \
|
||||||
@ -84,8 +82,7 @@ function download-kube-env {
|
|||||||
(
|
(
|
||||||
umask 077
|
umask 077
|
||||||
local -r tmp_kube_env="/tmp/kube-env.yaml"
|
local -r tmp_kube_env="/tmp/kube-env.yaml"
|
||||||
# shellcheck disable=SC2086
|
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error \
|
||||||
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error \
|
|
||||||
-H "X-Google-Metadata-Request: True" \
|
-H "X-Google-Metadata-Request: True" \
|
||||||
-o "${tmp_kube_env}" \
|
-o "${tmp_kube_env}" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env
|
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env
|
||||||
@ -111,8 +108,7 @@ function download-kubelet-config {
|
|||||||
(
|
(
|
||||||
umask 077
|
umask 077
|
||||||
local -r tmp_kubelet_config="/tmp/kubelet-config.yaml"
|
local -r tmp_kubelet_config="/tmp/kubelet-config.yaml"
|
||||||
# shellcheck disable=SC2086
|
if curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error \
|
||||||
if curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error \
|
|
||||||
-H "X-Google-Metadata-Request: True" \
|
-H "X-Google-Metadata-Request: True" \
|
||||||
-o "${tmp_kubelet_config}" \
|
-o "${tmp_kubelet_config}" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kubelet-config; then
|
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kubelet-config; then
|
||||||
@ -130,8 +126,7 @@ function download-kube-master-certs {
|
|||||||
(
|
(
|
||||||
umask 077
|
umask 077
|
||||||
local -r tmp_kube_master_certs="/tmp/kube-master-certs.yaml"
|
local -r tmp_kube_master_certs="/tmp/kube-master-certs.yaml"
|
||||||
# shellcheck disable=SC2086
|
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error \
|
||||||
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error \
|
|
||||||
-H "X-Google-Metadata-Request: True" \
|
-H "X-Google-Metadata-Request: True" \
|
||||||
-o "${tmp_kube_master_certs}" \
|
-o "${tmp_kube_master_certs}" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-certs
|
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-certs
|
||||||
@ -165,14 +160,12 @@ function validate-hash {
|
|||||||
# Get default service account credentials of the VM.
|
# Get default service account credentials of the VM.
|
||||||
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
|
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
|
||||||
function get-credentials {
|
function get-credentials {
|
||||||
# shellcheck disable=SC2086
|
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | ${PYTHON} -c \
|
||||||
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | ${PYTHON} -c \
|
|
||||||
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
|
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
|
||||||
}
|
}
|
||||||
|
|
||||||
function valid-storage-scope {
|
function valid-storage-scope {
|
||||||
# shellcheck disable=SC2086
|
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
|
||||||
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retry a download until we get it. Takes a hash and a set of URLs.
|
# Retry a download until we get it. Takes a hash and a set of URLs.
|
||||||
@ -192,8 +185,7 @@ function download-or-bust {
|
|||||||
if [[ "$url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
|
if [[ "$url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
|
||||||
curl_headers="Authorization: Bearer $(get-credentials)"
|
curl_headers="Authorization: Bearer $(get-credentials)"
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=SC2086
|
if ! curl ${curl_headers:+-H "${curl_headers}"} -f --ipv4 -Lo "${file}" --connect-timeout 20 --max-time 300 --retry 6 --retry-delay 10 --retry-connrefused "${url}"; then
|
||||||
if ! curl ${curl_headers:+-H "${curl_headers}"} -f --ipv4 -Lo "${file}" --connect-timeout 20 --max-time 300 --retry 6 --retry-delay 10 ${CURL_RETRY_CONNREFUSED} "${url}"; then
|
|
||||||
echo "== Failed to download ${url}. Retrying. =="
|
echo "== Failed to download ${url}. Retrying. =="
|
||||||
elif [[ -n "${hash}" ]] && ! validate-hash "${file}" "${hash}"; then
|
elif [[ -n "${hash}" ]] && ! validate-hash "${file}" "${hash}"; then
|
||||||
echo "== Hash validation of ${url} failed. Retrying. =="
|
echo "== Hash validation of ${url} failed. Retrying. =="
|
||||||
@ -718,13 +710,6 @@ function retry-forever {
|
|||||||
# NOTE: this function is duplicated in configure-helper.sh, any changes here
|
# NOTE: this function is duplicated in configure-helper.sh, any changes here
|
||||||
# should be duplicated there as well.
|
# should be duplicated there as well.
|
||||||
function log-init {
|
function log-init {
|
||||||
# CURL_RETRY_CONNREFUSED needs to be defined before calling get-metadata-value.
|
|
||||||
# Use --retry-connrefused opt only if it's supported by curl.
|
|
||||||
CURL_RETRY_CONNREFUSED=""
|
|
||||||
if curl --help | grep -q -- '--retry-connrefused'; then
|
|
||||||
CURL_RETRY_CONNREFUSED='--retry-connrefused'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Used by log-* functions.
|
# Used by log-* functions.
|
||||||
LOG_CLUSTER_ID=$(get-metadata-value 'instance/attributes/cluster-uid' 'get-metadata-value-error')
|
LOG_CLUSTER_ID=$(get-metadata-value 'instance/attributes/cluster-uid' 'get-metadata-value-error')
|
||||||
LOG_INSTANCE_NAME=$(hostname)
|
LOG_INSTANCE_NAME=$(hostname)
|
||||||
|
@ -45,8 +45,7 @@ write_files:
|
|||||||
ExecStartPre=/bin/mkdir -p /home/kubernetes/bin
|
ExecStartPre=/bin/mkdir -p /home/kubernetes/bin
|
||||||
ExecStartPre=/bin/mount --bind /home/kubernetes/bin /home/kubernetes/bin
|
ExecStartPre=/bin/mount --bind /home/kubernetes/bin /home/kubernetes/bin
|
||||||
ExecStartPre=/bin/mount -o remount,exec /home/kubernetes/bin
|
ExecStartPre=/bin/mount -o remount,exec /home/kubernetes/bin
|
||||||
# Use --retry-connrefused opt only if it's supported by curl.
|
ExecStartPre=/usr/bin/curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error -H "X-Google-Metadata-Request: True" -o /home/kubernetes/bin/configure.sh http://metadata.google.internal/computeMetadata/v1/instance/attributes/configure-sh
|
||||||
ExecStartPre=/bin/bash -c 'OPT=""; if curl --help | grep -q -- "--retry-connrefused"; then OPT="--retry-connrefused"; fi; /usr/bin/curl --fail --retry 5 --retry-delay 3 $OPT --silent --show-error -H "X-Google-Metadata-Request: True" -o /home/kubernetes/bin/configure.sh http://metadata.google.internal/computeMetadata/v1/instance/attributes/configure-sh'
|
|
||||||
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure.sh
|
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure.sh
|
||||||
ExecStart=/home/kubernetes/bin/configure.sh
|
ExecStart=/home/kubernetes/bin/configure.sh
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ write_files:
|
|||||||
ExecStartPre=/bin/mkdir -p /home/kubernetes/bin
|
ExecStartPre=/bin/mkdir -p /home/kubernetes/bin
|
||||||
ExecStartPre=/bin/mount --bind /home/kubernetes/bin /home/kubernetes/bin
|
ExecStartPre=/bin/mount --bind /home/kubernetes/bin /home/kubernetes/bin
|
||||||
ExecStartPre=/bin/mount -o remount,exec /home/kubernetes/bin
|
ExecStartPre=/bin/mount -o remount,exec /home/kubernetes/bin
|
||||||
# Use --retry-connrefused opt only if it's supported by curl.
|
ExecStartPre=/usr/bin/curl --fail --retry 5 --retry-delay 3 --silent --show-error -H "X-Google-Metadata-Request: True" -o /home/kubernetes/bin/configure.sh http://metadata.google.internal/computeMetadata/v1/instance/attributes/configure-sh
|
||||||
ExecStartPre=/bin/bash -c 'OPT=""; if curl --help | grep -q -- "--retry-connrefused"; then OPT="--retry-connrefused"; fi; /usr/bin/curl --fail --retry 5 --retry-delay 3 $OPT --silent --show-error -H "X-Google-Metadata-Request: True" -o /home/kubernetes/bin/configure.sh http://metadata.google.internal/computeMetadata/v1/instance/attributes/configure-sh'
|
|
||||||
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure.sh
|
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure.sh
|
||||||
ExecStart=/home/kubernetes/bin/configure.sh
|
ExecStart=/home/kubernetes/bin/configure.sh
|
||||||
StandardOutput=journal+console
|
StandardOutput=journal+console
|
||||||
|
Loading…
Reference in New Issue
Block a user