@@ -27,10 +27,13 @@ import (
2727 "path/filepath"
2828 "regexp"
2929 "strings"
30+ "time"
3031
3132 "github.com/blang/semver/v4"
3233 . "github.com/onsi/gomega"
3334 "github.com/pkg/errors"
35+ kerrors "k8s.io/apimachinery/pkg/util/errors"
36+ "k8s.io/apimachinery/pkg/util/wait"
3437
3538 clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3639 "sigs.k8s.io/cluster-api/test/framework/exec"
@@ -276,21 +279,37 @@ func getComponentSourceFromURL(ctx context.Context, source ProviderVersionSource
276279 return nil , errors .Wrap (err , "failed to read file" )
277280 }
278281 case httpURIScheme , httpsURIScheme :
279- req , err := http .NewRequestWithContext (ctx , http .MethodGet , source .Value , http .NoBody )
280- if err != nil {
281- return nil , errors .Wrapf (err , "failed to get %s: failed to create request" , source .Value )
282- }
283- resp , err := http .DefaultClient .Do (req )
284- if err != nil {
285- return nil , errors .Wrapf (err , "failed to get %s" , source .Value )
286- }
287- if resp .StatusCode != http .StatusOK {
288- return nil , errors .Errorf ("failed to get %s: got status code %d" , source .Value , resp .StatusCode )
289- }
290- defer resp .Body .Close ()
291- buf , err = io .ReadAll (resp .Body )
282+ var getErr error
283+ err := wait .ExponentialBackoff (wait.Backoff {
284+ Steps : 5 ,
285+ Duration : 100 * time .Millisecond ,
286+ Factor : 4.0 ,
287+ }, func () (bool , error ) {
288+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , source .Value , http .NoBody )
289+ if err != nil {
290+ getErr = errors .Wrapf (err , "failed to get %s: failed to create request" , source .Value )
291+ return false , nil
292+ }
293+ resp , err := http .DefaultClient .Do (req )
294+ if err != nil {
295+ getErr = errors .Wrapf (err , "failed to get %s" , source .Value )
296+ return false , nil
297+ }
298+ if resp .StatusCode != http .StatusOK {
299+ getErr = errors .Errorf ("failed to get %s: got status code %d" , source .Value , resp .StatusCode )
300+ return false , nil
301+ }
302+ defer resp .Body .Close ()
303+ buf , err = io .ReadAll (resp .Body )
304+ if err != nil {
305+ getErr = errors .Wrapf (err , "failed to get %s: failed to read body" , source .Value )
306+ return false , nil
307+ }
308+
309+ return true , nil
310+ })
292311 if err != nil {
293- return nil , errors . Wrapf ( err , "failed to get %s: failed to read body" , source . Value )
312+ return nil , kerrors . NewAggregate ([] error { err , getErr } )
294313 }
295314 default :
296315 return nil , errors .Errorf ("unknown scheme for component source %q: allowed values are file, http, https" , u .Scheme )
0 commit comments