Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Use wget while downloading image #2110

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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