Skip to content

Commit b01e6ef

Browse files
authored
Merge pull request #338 from replicatedhq/divolgin/preogress2
Add progress percentage
2 parents 17bff4b + 62afc87 commit b01e6ef

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

pkg/preflight/collect.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ type CollectOpts struct {
1919
}
2020

2121
type CollectProgress struct {
22-
Name string
23-
Status string
22+
CurrentName string
23+
CurrentStatus string
24+
CompletedCount int
25+
TotalCount int
2426
}
2527

2628
type CollectResult interface {
@@ -139,30 +141,46 @@ func Collect(opts CollectOpts, p *troubleshootv1beta2.Preflight) (CollectResult,
139141
}
140142

141143
// Run preflights collectors synchronously
142-
for _, collector := range collectors {
144+
for i, collector := range collectors {
143145
if len(collector.RBACErrors) > 0 {
144146
// don't skip clusterResources collector due to RBAC issues
145147
if collector.Collect.ClusterResources == nil {
146148
collectResult.isRBACAllowed = false // not failing, but going to report this
147149
opts.ProgressChan <- fmt.Sprintf("skipping collector %s with insufficient RBAC permissions", collector.GetDisplayName())
150+
opts.ProgressChan <- CollectProgress{
151+
CurrentName: collector.GetDisplayName(),
152+
CurrentStatus: "skipped",
153+
CompletedCount: i + 1,
154+
TotalCount: len(collectors),
155+
}
148156
continue
149157
}
150158
}
151159

152160
opts.ProgressChan <- CollectProgress{
153-
Name: collector.GetDisplayName(),
154-
Status: "running",
161+
CurrentName: collector.GetDisplayName(),
162+
CurrentStatus: "running",
163+
CompletedCount: i,
164+
TotalCount: len(collectors),
155165
}
156166

157167
result, err := collector.RunCollectorSync(nil)
158168
if err != nil {
159169
opts.ProgressChan <- errors.Errorf("failed to run collector %s: %v\n", collector.GetDisplayName(), err)
170+
opts.ProgressChan <- CollectProgress{
171+
CurrentName: collector.GetDisplayName(),
172+
CurrentStatus: "failed",
173+
CompletedCount: i + 1,
174+
TotalCount: len(collectors),
175+
}
160176
continue
161177
}
162178

163179
opts.ProgressChan <- CollectProgress{
164-
Name: collector.GetDisplayName(),
165-
Status: "completed",
180+
CurrentName: collector.GetDisplayName(),
181+
CurrentStatus: "completed",
182+
CompletedCount: i + 1,
183+
TotalCount: len(collectors),
166184
}
167185

168186
if result != nil {

0 commit comments

Comments
 (0)