@@ -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,41 @@ 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
+ c := http.Client {
528
+ Transport : knet .SetTransportDefaults (& http.Transport {
529
+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
530
+ }),
531
+ }
532
+
533
+ peekAtBlob := func (schema string ) (* http.Request , * http.Response , error ) {
534
+ req , err := http .NewRequest ("GET" , fmt .Sprintf ("%s://%s/v2/%s/blobs/%s" , schema , registryURL , repository , dgst .String ()), nil )
535
+ if err != nil {
536
+ return nil , nil , err
537
+ }
538
+ req .Header .Set ("range" , "bytes=0-1" )
539
+ req .Header .Set ("Authorization" , "Bearer " + token )
540
+ resp , err := c .Do (req )
541
+ if err != nil {
542
+ fmt .Fprintf (g .GinkgoWriter , "failed to %s %s: %v (%#+v)\n " , req .Method , req .URL , err , err )
543
+ return nil , nil , err
544
+ }
545
+ return req , resp , nil
546
+ }
547
+
548
+ var (
549
+ req * http.Request
550
+ resp * http.Response
551
+ getErr error
552
+ )
553
+ if req , resp , getErr = peekAtBlob ("https" ); getErr != nil {
554
+ if req , resp , getErr = peekAtBlob ("http" ); getErr != nil {
555
+ return getErr
556
+ }
534
557
}
535
558
defer resp .Body .Close ()
536
559
0 commit comments