diff --git a/go.mod b/go.mod index 72a311e54608..9080abfd684a 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/c4milo/gotoolkit v0.0.0-20170318115440-bcc06269efa9 // indirect github.com/cenkalti/backoff v2.2.1+incompatible github.com/cenkalti/backoff/v4 v4.1.1 - github.com/cheggaaa/pb/v3 v3.0.8 + github.com/cheggaaa/pb v1.0.29 github.com/cloudevents/sdk-go/v2 v2.3.1 github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 // indirect @@ -26,6 +26,7 @@ require ( github.com/docker/machine v0.16.2 github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect + github.com/fatih/color v1.9.0 // indirect github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/google/go-cmp v0.5.6 github.com/google/go-containerregistry v0.4.1 diff --git a/go.sum b/go.sum index de7f56d87edb..44277b5373ec 100644 --- a/go.sum +++ b/go.sum @@ -182,6 +182,8 @@ github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOo github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/cheggaaa/pb v1.0.27 h1:wIkZHkNfC7R6GI5w7l/PdAdzXzlrbcI3p8OAlnkTsnc= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= +github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo= +github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30= github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA= github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -335,6 +337,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4= github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -713,17 +717,21 @@ github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24 h1:uYuGXJBAi1u github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= diff --git a/pkg/minikube/download/image.go b/pkg/minikube/download/image.go index bc06237670cb..18e20fe9f47d 100644 --- a/pkg/minikube/download/image.go +++ b/pkg/minikube/download/image.go @@ -24,7 +24,7 @@ import ( "runtime" "strings" - "github.com/cheggaaa/pb/v3" + "github.com/cheggaaa/pb" "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/daemon" @@ -135,18 +135,22 @@ func ImageToCache(img string) error { } klog.V(3).Infof("Writing image %v", ref) errchan := make(chan error) - p := pb.Full.Start64(0) + //p := pb.Full.Start64(0) + p := pb.New64(0) + p.ShowSpeed = true + p.ShowTimeLeft = true fn := strings.Split(ref.Name(), "@")[0] // abbreviate filename for progress maxwidth := 30 - len("...") if len(fn) > maxwidth { fn = fn[0:maxwidth] + "..." } - p.Set("prefix", " > "+fn+": ") - p.Set(pb.Bytes, true) + p.Prefix(" > " + fn + ": ") + p.SetUnits(pb.U_BYTES) // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs p.SetWidth(79) + p.Start() go func() { err = tarball.WriteToFile(f, ref, i, tarball.WithProgress(c)) @@ -156,8 +160,8 @@ func ImageToCache(img string) error { for { select { case update = <-c: - p.SetCurrent(update.Complete) - p.SetTotal(update.Total) + p.Set64(update.Complete) + p.SetTotal64(update.Total) case err = <-errchan: p.Finish() if err != nil { @@ -235,15 +239,19 @@ func ImageToDaemon(img string) error { klog.V(3).Infof("Writing image %v", ref) errchan := make(chan error) - p := pb.Full.Start64(0) + //p := pb.Full.Start64(0) + p := pb.New64(0) + p.ShowSpeed = true + p.ShowTimeLeft = true + p.Start() fn := strings.Split(ref.Name(), "@")[0] // abbreviate filename for progress maxwidth := 30 - len("...") if len(fn) > maxwidth { fn = fn[0:maxwidth] + "..." } - p.Set("prefix", " > "+fn+": ") - p.Set(pb.Bytes, true) + p.Prefix(" > " + fn + ": ") + p.SetUnits(pb.U_BYTES) // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs p.SetWidth(79) @@ -256,8 +264,8 @@ func ImageToDaemon(img string) error { for { select { case update = <-c: - p.SetCurrent(update.Complete) - p.SetTotal(update.Total) + p.Set64(update.Complete) + p.SetTotal64(update.Total) case err = <-errchan: p.Finish() if err != nil { diff --git a/pkg/minikube/download/progressbar.go b/pkg/minikube/download/progressbar.go index a80a887e0f35..97940ed1938c 100644 --- a/pkg/minikube/download/progressbar.go +++ b/pkg/minikube/download/progressbar.go @@ -23,18 +23,46 @@ package download import ( "io" "path/filepath" + "runtime" "sync" - "github.com/cheggaaa/pb/v3" + "github.com/cheggaaa/pb" "github.com/hashicorp/go-getter" + "k8s.io/klog/v2" ) // DefaultProgressBar is the default cheggaaa progress bar var DefaultProgressBar getter.ProgressTracker = &progressBar{} type progressBar struct { - lock sync.Mutex - progress *pb.ProgressBar + lock sync.Mutex + pool *pb.Pool + pbs int +} + +// AddProgressBar add progress bar to the concurrent pool +func (cpb *progressBar) AddProgressBar(p *pb.ProgressBar) error { + if cpb.pool == nil { + cpb.pool = pb.NewPool() + if err := cpb.pool.Start(); err != nil { + return err + } + } + cpb.pool.Add(p) + cpb.pbs++ + return nil +} + +// RemoveProgressBar removes progress bar from the concurrent pool +func (cpb *progressBar) RemoveProgressBar(p *pb.ProgressBar) error { + cpb.pbs-- + if cpb.pbs <= 0 { + if err := cpb.pool.Stop(); err != nil { + return err + } + cpb.pool = nil + } + return nil } // TrackProgress instantiates a new progress bar that will @@ -43,30 +71,41 @@ type progressBar struct { func (cpb *progressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser { cpb.lock.Lock() defer cpb.lock.Unlock() - if cpb.progress == nil { - cpb.progress = pb.New64(totalSize) - } - p := pb.Full.Start64(totalSize) + //p := pb.Full.Start64(totalSize) + p := pb.New64(totalSize) + p.ShowSpeed = true + p.ShowTimeLeft = true fn := filepath.Base(src) // abbreviate filename for progress maxwidth := 30 - len("...") if len(fn) > maxwidth { fn = fn[0:maxwidth] + "..." } - p.Set("prefix", " > "+fn+": ") - p.SetCurrent(currentSize) - p.Set(pb.Bytes, true) + p.Prefix(" > " + fn + ": ") + p.Set64(currentSize) + p.SetUnits(pb.U_BYTES) // Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs p.SetWidth(79) + p.Start() barReader := p.NewProxyReader(stream) + if runtime.GOOS != "windows" { + if err := cpb.AddProgressBar(p); err != nil { + klog.Errorf("pool start: %v", err) + } + } return &readCloser{ Reader: barReader, close: func() error { cpb.lock.Lock() defer cpb.lock.Unlock() p.Finish() + if runtime.GOOS != "windows" { + if err := cpb.RemoveProgressBar(p); err != nil { + klog.Errorf("pool stop: %v", err) + } + } return nil }, }