Skip to content

Commit

Permalink
ensure Copy collector run last
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao committed Nov 13, 2024
1 parent 9970fb1 commit b069b1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,20 @@ func DedupCollectors(allCollectors []*troubleshootv1beta2.Collect) []*troublesho
}
return finalCollectors
}

// Ensure Copy collectors are last in the list
// This is because copy collectors are expected to copy files from other collectors such as Exec, RunPod, RunDaemonSet
func EnsureCopyLast(allCollectors []Collector) []Collector {
otherCollectors := make([]Collector, 0)
copyCollectors := make([]Collector, 0)

for _, collector := range allCollectors {
if _, ok := collector.(*CollectCopy); ok {
copyCollectors = append(copyCollectors, collector)
} else {
otherCollectors = append(otherCollectors, collector)
}
}

return append(otherCollectors, copyCollectors...)
}
3 changes: 3 additions & 0 deletions pkg/supportbundle/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func runCollectors(ctx context.Context, collectors []*troubleshootv1beta2.Collec
return nil, collect.ErrInsufficientPermissionsToRun
}

// move Copy Collectors if any to the end of the execution list
allCollectors = collect.EnsureCopyLast(allCollectors)

for _, collector := range allCollectors {
_, span := otel.Tracer(constants.LIB_TRACER_NAME).Start(ctx, collector.Title())
span.SetAttributes(attribute.String("type", reflect.TypeOf(collector).String()))
Expand Down

0 comments on commit b069b1f

Please sign in to comment.