Retry curl when it failed during download

Fixes #34769
This commit is contained in:
Łukasz Oleś
2016-10-13 18:11:36 +02:00
parent 786cc3ef6c
commit 1cda616a9b
2 changed files with 25 additions and 2 deletions

View File

@@ -478,4 +478,23 @@ kube::util::has_changes_against_upstream_branch() {
return 1
}
kube::util::download_file() {
local -r url=$1
local -r destination_file=$2
rm ${destination_file} 2&> /dev/null || true
for i in $(seq 5)
do
if ! curl -fsSL --retry 3 --keepalive-time 2 ${url} -o ${destination_file}; then
echo "Downloading ${url} failed. $((5-i)) retries left."
sleep 1
else
echo "Downloading ${url} succeed"
return 0
fi
done
return 1
}
# ex: ts=2 sw=2 et filetype=sh