Skip to content

Commit

Permalink
Merge pull request #337 from replicatedhq/divolgin/progress
Browse files Browse the repository at this point in the history
Report back some basic progress
  • Loading branch information
divolgin authored Mar 18, 2021
2 parents afa0bc5 + 5f2525b commit 17bff4b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/preflight/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ func runPreflights(v *viper.Viper, arg string) error {
}
}
}()
} else {
// make sure we don't block any senders
go func() {
for {
select {
case _, ok := <-progressCh:
if !ok {
return
}
case <-finishedCh:
return
}
}
}()
}

defer func() {
Expand Down
15 changes: 15 additions & 0 deletions pkg/preflight/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type CollectOpts struct {
ProgressChan chan interface{}
}

type CollectProgress struct {
Name string
Status string
}

type CollectResult interface {
Analyze() []*analyze.AnalyzeResult
IsRBACAllowed() bool
Expand Down Expand Up @@ -144,12 +149,22 @@ func Collect(opts CollectOpts, p *troubleshootv1beta2.Preflight) (CollectResult,
}
}

opts.ProgressChan <- CollectProgress{
Name: collector.GetDisplayName(),
Status: "running",
}

result, err := collector.RunCollectorSync(nil)
if err != nil {
opts.ProgressChan <- errors.Errorf("failed to run collector %s: %v\n", collector.GetDisplayName(), err)
continue
}

opts.ProgressChan <- CollectProgress{
Name: collector.GetDisplayName(),
Status: "completed",
}

if result != nil {
for k, v := range result {
allCollectedData[k] = v
Expand Down

0 comments on commit 17bff4b

Please sign in to comment.