From b069b1feed3f8202564a99c89c27a39fa4e57b13 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Mon, 11 Nov 2024 14:26:43 +1100 Subject: [PATCH] ensure Copy collector run last --- pkg/collect/collector.go | 17 +++++++++++++++++ pkg/supportbundle/collect.go | 3 +++ 2 files changed, 20 insertions(+) diff --git a/pkg/collect/collector.go b/pkg/collect/collector.go index 310f84ff0..b8ccbf63d 100644 --- a/pkg/collect/collector.go +++ b/pkg/collect/collector.go @@ -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...) +} diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index cb3f508a2..3866b2859 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -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()))