http download: set a timeout to avoid hangs

I observed a node failure where we failed to download docker; we need
some timeout just to prevent the hang.

Two minutes should be plenty for our downloads.
This commit is contained in:
Justin SB 2020-05-17 15:21:23 -04:00
parent fd841dcd58
commit 7ae4d73b5b
1 changed files with 6 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import (
"net/http"
"os"
"path"
"time"
"k8s.io/klog"
"k8s.io/kops/util/pkg/hashing"
@ -76,7 +77,11 @@ func downloadURLAlways(url string, destPath string, dirMode os.FileMode) error {
klog.Infof("Downloading %q", url)
response, err := http.Get(url)
// Create a client with a shorter timeout
httpClient := http.Client{
Timeout: 2 * time.Minute,
}
response, err := httpClient.Get(url)
if err != nil {
return fmt.Errorf("error doing HTTP fetch of %q: %v", url, err)
}