Skip to content

Commit

Permalink
Use wget while downloading image
Browse files Browse the repository at this point in the history
Recently we have experienced net.OpError error or http2streamerror error while downloading image quite frequently. This PR uses wget instead which is more resilient to http/network issues. We should change it to httpGet when network improves again.

Signed-off-by: Kashif Khan <[email protected]>
  • Loading branch information
kashifest committed Nov 26, 2024
1 parent 476b7e1 commit f4dbb7e
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,14 @@ func EnsureImage(k8sVersion string) (imageURL string, imageChecksum string) {

// DownloadFile will download a url and store it in local filepath.
func DownloadFile(filePath string, url string) error {
// Get the data
/* #nosec G107 */
resp, err := http.Get(url) //nolint:noctx
// TODO: Lets change the wget to use go's native http client when network
// more resilient
cmd := exec.Command("wget", "-O", filePath, url)
output, err := cmd.CombinedOutput()
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return errors.Errorf("failed to download image from %q got %d %s", filePath, resp.StatusCode, http.StatusText(resp.StatusCode))
return fmt.Errorf("wget failed: %v, output: %s", err, string(output))
}
defer resp.Body.Close()

// Create the file
out, err := os.Create(filepath.Clean(filePath))
if err != nil {
return err
}
defer func() {
err := out.Close()
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error closing file: %s", filePath))
}()

// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
return nil
}

// FilterBmhsByProvisioningState returns a filtered list of BaremetalHost objects in certain provisioning state.
Expand Down

0 comments on commit f4dbb7e

Please sign in to comment.