Skip to content

Commit a818417

Browse files
include atomic collector statuses (#534)
1 parent f9039a0 commit a818417

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

pkg/preflight/collect.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type CollectProgress struct {
3030
CurrentStatus string
3131
CompletedCount int
3232
TotalCount int
33+
Collectors map[string]CollectorStatus
34+
}
35+
36+
type CollectorStatus struct {
37+
Status string
3338
}
3439

3540
func (cp *CollectProgress) String() string {
@@ -161,47 +166,71 @@ func Collect(opts CollectOpts, p *troubleshootv1beta2.Preflight) (CollectResult,
161166
return collectResult, errors.New("insufficient permissions to run all collectors")
162167
}
163168

169+
// generate a map of all collectors for atomic status messages
170+
collectorList := map[string]CollectorStatus{}
171+
for _, collector := range collectors {
172+
collectorList[collector.GetDisplayName()] = CollectorStatus{
173+
Status: "pending",
174+
}
175+
}
176+
164177
// Run preflights collectors synchronously
165178
for i, collector := range collectors {
166179
if len(collector.RBACErrors) > 0 {
167180
// don't skip clusterResources collector due to RBAC issues
168181
if collector.Collect.ClusterResources == nil {
182+
collectorList[collector.GetDisplayName()] = CollectorStatus{
183+
Status: "skipped",
184+
}
169185
collectResult.isRBACAllowed = false // not failing, but going to report this
170186
opts.ProgressChan <- fmt.Sprintf("skipping collector %s with insufficient RBAC permissions", collector.GetDisplayName())
171187
opts.ProgressChan <- CollectProgress{
172188
CurrentName: collector.GetDisplayName(),
173189
CurrentStatus: "skipped",
174190
CompletedCount: i + 1,
175191
TotalCount: len(collectors),
192+
Collectors: collectorList,
176193
}
177194
continue
178195
}
179196
}
180197

198+
collectorList[collector.GetDisplayName()] = CollectorStatus{
199+
Status: "running",
200+
}
181201
opts.ProgressChan <- CollectProgress{
182202
CurrentName: collector.GetDisplayName(),
183203
CurrentStatus: "running",
184204
CompletedCount: i,
185205
TotalCount: len(collectors),
206+
Collectors: collectorList,
186207
}
187208

188209
result, err := collector.RunCollectorSync(opts.KubernetesRestConfig, k8sClient, nil)
189210
if err != nil {
211+
collectorList[collector.GetDisplayName()] = CollectorStatus{
212+
Status: "failed",
213+
}
190214
opts.ProgressChan <- errors.Errorf("failed to run collector %s: %v\n", collector.GetDisplayName(), err)
191215
opts.ProgressChan <- CollectProgress{
192216
CurrentName: collector.GetDisplayName(),
193217
CurrentStatus: "failed",
194218
CompletedCount: i + 1,
195219
TotalCount: len(collectors),
220+
Collectors: collectorList,
196221
}
197222
continue
198223
}
199224

225+
collectorList[collector.GetDisplayName()] = CollectorStatus{
226+
Status: "completed",
227+
}
200228
opts.ProgressChan <- CollectProgress{
201229
CurrentName: collector.GetDisplayName(),
202230
CurrentStatus: "completed",
203231
CompletedCount: i + 1,
204232
TotalCount: len(collectors),
233+
Collectors: collectorList,
205234
}
206235

207236
for k, v := range result {
@@ -240,32 +269,55 @@ func CollectRemote(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (Coll
240269
Spec: p,
241270
}
242271

272+
// generate a map of all collectors for atomic status messages
273+
collectorList := map[string]CollectorStatus{}
274+
for _, collector := range collectors {
275+
collectorList[collector.GetDisplayName()] = CollectorStatus{
276+
Status: "pending",
277+
}
278+
}
279+
243280
// Run preflights collectors synchronously
244281
for i, collector := range collectors {
282+
collectorList[collector.GetDisplayName()] = CollectorStatus{
283+
Status: "running",
284+
}
285+
245286
opts.ProgressChan <- CollectProgress{
246287
CurrentName: collector.GetDisplayName(),
247288
CurrentStatus: "running",
248289
CompletedCount: i,
249290
TotalCount: len(collectors),
291+
Collectors: collectorList,
250292
}
251293

252294
result, err := collector.RunCollectorSync(nil)
253295
if err != nil {
296+
collectorList[collector.GetDisplayName()] = CollectorStatus{
297+
Status: "failed",
298+
}
299+
254300
opts.ProgressChan <- errors.Errorf("failed to run collector %s: %v\n", collector.GetDisplayName(), err)
255301
opts.ProgressChan <- CollectProgress{
256302
CurrentName: collector.GetDisplayName(),
257303
CurrentStatus: "failed",
258304
CompletedCount: i + 1,
259305
TotalCount: len(collectors),
306+
Collectors: collectorList,
260307
}
261308
continue
262309
}
263310

311+
collectorList[collector.GetDisplayName()] = CollectorStatus{
312+
Status: "completed",
313+
}
314+
264315
opts.ProgressChan <- CollectProgress{
265316
CurrentName: collector.GetDisplayName(),
266317
CurrentStatus: "completed",
267318
CompletedCount: i + 1,
268319
TotalCount: len(collectors),
320+
Collectors: collectorList,
269321
}
270322

271323
for k, v := range result {

0 commit comments

Comments
 (0)