@@ -36,6 +36,7 @@ import (
36
36
"k8s.io/minikube/pkg/minikube/detect"
37
37
"k8s.io/minikube/pkg/minikube/image"
38
38
"k8s.io/minikube/pkg/minikube/localpath"
39
+ "k8s.io/minikube/pkg/minikube/out"
39
40
)
40
41
41
42
var (
@@ -140,6 +141,12 @@ func ImageToCache(img string) error {
140
141
return errors .Wrap (err , "getting remote image" )
141
142
}
142
143
klog .V (3 ).Infof ("Writing image %v" , tag )
144
+ if out .JSON {
145
+ if err := tarball .WriteToFile (f , tag , i ); err != nil {
146
+ return errors .Wrap (err , "writing tarball image" )
147
+ }
148
+ return nil
149
+ }
143
150
errchan := make (chan error )
144
151
p := pb .Full .Start64 (0 )
145
152
fn := strings .Split (ref .Name (), "@" )[0 ]
@@ -271,37 +278,43 @@ func ImageToDaemon(img string) error {
271
278
}
272
279
273
280
klog .V (3 ).Infof ("Writing image %v" , tag )
274
- errchan := make (chan error )
275
- p := pb .Full .Start64 (0 )
276
- fn := strings .Split (ref .Name (), "@" )[0 ]
277
- // abbreviate filename for progress
278
- maxwidth := 30 - len ("..." )
279
- if len (fn ) > maxwidth {
280
- fn = fn [0 :maxwidth ] + "..."
281
- }
282
- p .Set ("prefix" , " > " + fn + ": " )
283
- p .Set (pb .Bytes , true )
284
-
285
- // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
286
- p .SetWidth (79 )
287
-
288
- go func () {
289
- _ , err = daemon .Write (tag , i )
290
- errchan <- err
291
- }()
292
- var update v1.Update
293
- loop:
294
- for {
295
- select {
296
- case update = <- c :
297
- p .SetCurrent (update .Complete )
298
- p .SetTotal (update .Total )
299
- case err = <- errchan :
300
- p .Finish ()
301
- if err != nil {
302
- return errors .Wrap (err , "writing daemon image" )
281
+ if out .JSON {
282
+ if _ , err := daemon .Write (tag , i ); err != nil {
283
+ return errors .Wrap (err , "writing daemon image" )
284
+ }
285
+ } else {
286
+ errchan := make (chan error )
287
+ p := pb .Full .Start64 (0 )
288
+ fn := strings .Split (ref .Name (), "@" )[0 ]
289
+ // abbreviate filename for progress
290
+ maxwidth := 30 - len ("..." )
291
+ if len (fn ) > maxwidth {
292
+ fn = fn [0 :maxwidth ] + "..."
293
+ }
294
+ p .Set ("prefix" , " > " + fn + ": " )
295
+ p .Set (pb .Bytes , true )
296
+
297
+ // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
298
+ p .SetWidth (79 )
299
+
300
+ go func () {
301
+ _ , err = daemon .Write (tag , i )
302
+ errchan <- err
303
+ }()
304
+ var update v1.Update
305
+ loop:
306
+ for {
307
+ select {
308
+ case update = <- c :
309
+ p .SetCurrent (update .Complete )
310
+ p .SetTotal (update .Total )
311
+ case err = <- errchan :
312
+ p .Finish ()
313
+ if err != nil {
314
+ return errors .Wrap (err , "writing daemon image" )
315
+ }
316
+ break loop
303
317
}
304
- break loop
305
318
}
306
319
}
307
320
klog .V (3 ).Infof ("Pulling image %v" , ref )
0 commit comments