1
1
package bundle
2
2
3
3
import (
4
+ "context"
4
5
"encoding/json"
5
6
"fmt"
6
7
"io"
@@ -337,16 +338,15 @@ func getVerifiedHash(url string, file string) (string, error) {
337
338
return "" , fmt .Errorf ("%s hash is missing or shasums are malformed" , file )
338
339
}
339
340
340
- func downloadDefault (preset crcPreset.Preset ) (string , error ) {
341
+ func downloadDefault (ctx context. Context , preset crcPreset.Preset ) (string , error ) {
341
342
downloadInfo , err := getBundleDownloadInfo (preset )
342
343
if err != nil {
343
344
return "" , err
344
345
}
345
-
346
- return downloadInfo .Download (constants .GetDefaultBundlePath (preset ), 0664 )
346
+ return downloadInfo .Download (ctx , constants .GetDefaultBundlePath (preset ), 0664 )
347
347
}
348
348
349
- func Download (preset crcPreset.Preset , bundleURI string , enableBundleQuayFallback bool ) (string , error ) {
349
+ func Download (ctx context. Context , preset crcPreset.Preset , bundleURI string , enableBundleQuayFallback bool ) (string , error ) {
350
350
// If we are asked to download
351
351
// ~/.crc/cache/crc_podman_libvirt_4.1.1.crcbundle, this means we want
352
352
// are downloading the default bundle for this release. This uses a
@@ -355,23 +355,23 @@ func Download(preset crcPreset.Preset, bundleURI string, enableBundleQuayFallbac
355
355
if bundleURI == constants .GetDefaultBundlePath (preset ) {
356
356
switch preset {
357
357
case crcPreset .OpenShift , crcPreset .Microshift :
358
- downloadedBundlePath , err := downloadDefault (preset )
358
+ downloadedBundlePath , err := downloadDefault (ctx , preset )
359
359
if err != nil && enableBundleQuayFallback {
360
360
logging .Info ("Unable to download bundle from mirror, falling back to quay" )
361
- return image .PullBundle (constants .GetDefaultBundleImageRegistry (preset ))
361
+ return image .PullBundle (ctx , constants .GetDefaultBundleImageRegistry (preset ))
362
362
}
363
363
return downloadedBundlePath , err
364
364
case crcPreset .OKD :
365
365
fallthrough
366
366
default :
367
- return image .PullBundle (constants .GetDefaultBundleImageRegistry (preset ))
367
+ return image .PullBundle (ctx , constants .GetDefaultBundleImageRegistry (preset ))
368
368
}
369
369
}
370
370
switch {
371
371
case strings .HasPrefix (bundleURI , "http://" ), strings .HasPrefix (bundleURI , "https://" ):
372
- return download .Download (bundleURI , constants .MachineCacheDir , 0644 , nil )
372
+ return download .Download (ctx , bundleURI , constants .MachineCacheDir , 0644 , nil )
373
373
case strings .HasPrefix (bundleURI , "docker://" ):
374
- return image .PullBundle (bundleURI )
374
+ return image .PullBundle (ctx , bundleURI )
375
375
}
376
376
// the `bundleURI` parameter turned out to be a local path
377
377
return bundleURI , nil
0 commit comments