Skip to content

Commit 8e2fc07

Browse files
committed
remove progress bar for kic download when JSON output
1 parent 2853940 commit 8e2fc07

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,7 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
14051405
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14061406
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14071407
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1408+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14081409
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
14091410
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14101411
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

pkg/minikube/download/image.go

+43-30
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/minikube/pkg/minikube/detect"
3737
"k8s.io/minikube/pkg/minikube/image"
3838
"k8s.io/minikube/pkg/minikube/localpath"
39+
"k8s.io/minikube/pkg/minikube/out"
3940
)
4041

4142
var (
@@ -140,6 +141,12 @@ func ImageToCache(img string) error {
140141
return errors.Wrap(err, "getting remote image")
141142
}
142143
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+
}
143150
errchan := make(chan error)
144151
p := pb.Full.Start64(0)
145152
fn := strings.Split(ref.Name(), "@")[0]
@@ -271,37 +278,43 @@ func ImageToDaemon(img string) error {
271278
}
272279

273280
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
303317
}
304-
break loop
305318
}
306319
}
307320
klog.V(3).Infof("Pulling image %v", ref)

0 commit comments

Comments
 (0)