@@ -3,6 +3,7 @@ package images
3
3
import (
4
4
"bytes"
5
5
cryptorand "crypto/rand"
6
+ "crypto/tls"
6
7
"fmt"
7
8
"io"
8
9
"io/ioutil"
@@ -21,6 +22,7 @@ import (
21
22
22
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
kerrors "k8s.io/apimachinery/pkg/util/errors"
25
+ knet "k8s.io/apimachinery/pkg/util/net"
24
26
"k8s.io/apimachinery/pkg/util/sets"
25
27
"k8s.io/apimachinery/pkg/util/wait"
26
28
"k8s.io/kubernetes/pkg/client/retry"
@@ -517,20 +519,36 @@ func MirrorBlobInRegistry(oc *exutil.CLI, dgst digest.Digest, repository string,
517
519
if err != nil {
518
520
return err
519
521
}
520
- req , err := http .NewRequest ("GET" , fmt .Sprintf ("http://%s/v2/%s/blobs/%s" , registryURL , repository , dgst .String ()), nil )
521
- if err != nil {
522
- return err
523
- }
524
522
token , err := oc .Run ("whoami" ).Args ("-t" ).Output ()
525
523
if err != nil {
526
524
return err
527
525
}
528
- req .Header .Set ("range" , "bytes=0-1" )
529
- req .Header .Set ("Authorization" , "Bearer " + token )
530
- c := http.Client {}
531
- resp , err := c .Do (req )
532
- if err != nil {
533
- return err
526
+
527
+ var (
528
+ req * http.Request
529
+ resp * http.Response
530
+ getErr error
531
+ )
532
+ for _ , schema := range []string {"https" , "http" } {
533
+ req , err = http .NewRequest ("GET" , fmt .Sprintf ("%s://%s/v2/%s/blobs/%s" , schema , registryURL , repository , dgst .String ()), nil )
534
+ if err != nil {
535
+ return err
536
+ }
537
+ req .Header .Set ("range" , "bytes=0-1" )
538
+ req .Header .Set ("Authorization" , "Bearer " + token )
539
+ c := http.Client {
540
+ Transport : knet .SetTransportDefaults (& http.Transport {
541
+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
542
+ }),
543
+ }
544
+ resp , getErr = c .Do (req )
545
+ if getErr == nil {
546
+ break
547
+ }
548
+ fmt .Fprintf (g .GinkgoWriter , "failed to %s %s: %v (%#+v)\n " , req .Method , req .URL , err , err )
549
+ }
550
+ if getErr != nil {
551
+ return getErr
534
552
}
535
553
defer resp .Body .Close ()
536
554
0 commit comments