Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print download progress every second #9099

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/minikube/download/json_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"sync"
"time"

"github.com/hashicorp/go-getter"
"k8s.io/minikube/pkg/minikube/out/register"
Expand All @@ -44,6 +45,7 @@ func (cpb *jsonOutput) TrackProgress(src string, currentSize, totalSize int64, s
artifact: src,
current: currentSize,
total: totalSize,
Time: time.Now(),
},
close: func() error {
cpb.lock.Lock()
Expand All @@ -59,12 +61,17 @@ type jsonReader struct {
current int64
total int64
io.Reader
time.Time
}

func (r *jsonReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
r.current += int64(n)
progress := float64(r.current) / float64(r.total)
register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress))
// print progress every second so user isn't overwhelmed with events
if t := time.Now(); t.Sub(r.Time) > time.Second || progress == 1 {
register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress))
r.Time = t
}
return
}