From daeab2dc20ff2859fb3d2e7c46786e3ecaf1abeb Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Tue, 14 Apr 2026 18:42:30 +0100 Subject: [PATCH] fix: improve collector output discoverability (#2018) * fix: document .tar.gz auto-append in --output flag help text The --output flag silently appends .tar.gz to the provided path, which was not mentioned in the help text, causing confusion for users who expected the exact filename they specified. Co-Authored-By: Claude Opus 4.6 (1M context) * fix: exec collector falls back to containerName for file naming When collectorName is not set, the exec collector now uses containerName as the output file prefix instead of producing bare -stdout.txt filenames. This makes output files identifiable without requiring collectorName to be explicitly set. Co-Authored-By: Claude Opus 4.6 (1M context) --------- Co-authored-by: Claude Opus 4.6 (1M context) --- cmd/troubleshoot/cli/root.go | 2 +- pkg/collect/exec.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/troubleshoot/cli/root.go b/cmd/troubleshoot/cli/root.go index 27c70877..92e292f5 100644 --- a/cmd/troubleshoot/cli/root.go +++ b/cmd/troubleshoot/cli/root.go @@ -133,7 +133,7 @@ If no arguments are provided, specs are automatically loaded from the cluster by cmd.Flags().String("since-time", "", "force pod logs collectors to return logs after a specific date (RFC3339)") cmd.Flags().String("since", "", "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.") cmd.Flags().Int("remote-host-collect-timeout", 30, "timeout in seconds for remote host collect operations (e.g. waiting for pods/daemonsets)") - cmd.Flags().StringP("output", "o", "", "specify the output file path for the support bundle") + cmd.Flags().StringP("output", "o", "", "specify the output file path for the support bundle (.tar.gz extension is added automatically)") cmd.Flags().Bool("debug", false, "enable debug logging. This is equivalent to --v=0") cmd.Flags().Bool("dry-run", false, "print support bundle spec without collecting anything") cmd.Flags().Bool("auto-update", true, "enable automatic binary self-update check and install") diff --git a/pkg/collect/exec.go b/pkg/collect/exec.go index c2002526..27ae956d 100644 --- a/pkg/collect/exec.go +++ b/pkg/collect/exec.go @@ -87,16 +87,21 @@ func execWithoutTimeout(clientConfig *rest.Config, bundlePath string, execCollec pod := pods[0] stdout, stderr, execErrors := getExecOutputs(ctx, clientConfig, client, pod, execCollector) + filePrefix := execCollector.CollectorName + if filePrefix == "" { + filePrefix = execCollector.ContainerName + } + path := filepath.Join(execCollector.Name, pod.Namespace, pod.Name) if len(stdout) > 0 { - output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stdout.txt"), bytes.NewBuffer(stdout)) + output.SaveResult(bundlePath, filepath.Join(path, filePrefix+"-stdout.txt"), bytes.NewBuffer(stdout)) } if len(stderr) > 0 { - output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stderr.txt"), bytes.NewBuffer(stderr)) + output.SaveResult(bundlePath, filepath.Join(path, filePrefix+"-stderr.txt"), bytes.NewBuffer(stderr)) } if len(execErrors) > 0 { - output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-errors.json"), marshalErrors(execErrors)) + output.SaveResult(bundlePath, filepath.Join(path, filePrefix+"-errors.json"), marshalErrors(execErrors)) } }