Skip to content

Commit deab5e4

Browse files
readded auto upload flag for support bundle (#1893)
* readded auto upload flag for support bundle * updated auto upload message
1 parent df40c66 commit deab5e4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cmd/troubleshoot/cli/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ If no arguments are provided, specs are automatically loaded from the cluster by
132132
cmd.Flags().Bool("dry-run", false, "print support bundle spec without collecting anything")
133133
cmd.Flags().Bool("auto-update", true, "enable automatic binary self-update check and install")
134134

135+
// Upload flags
136+
cmd.Flags().Bool("auto-upload", false, "automatically upload resulting bundle to replicated.app")
137+
cmd.Flags().String("license-id", "", "license ID for authentication when uploading (auto-detected from bundle if not provided)")
138+
cmd.Flags().String("app-slug", "", "application slug when uploading (auto-detected from bundle if not provided)")
139+
135140
// Auto-discovery flags
136141
cmd.Flags().Bool("auto", false, "enable auto-discovery of foundational collectors. When used with YAML specs, adds foundational collectors to YAML collectors. When used alone, collects only foundational data")
137142
cmd.Flags().Bool("include-images", false, "include container image metadata collection when using auto-discovery")

cmd/troubleshoot/cli/run.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,20 @@ func runTroubleshoot(v *viper.Viper, args []string) error {
242242
}
243243
}
244244

245+
// Attempt auto-upload before any early returns
246+
if v.GetBool("auto-upload") && !response.FileUploaded {
247+
licenseID := v.GetString("license-id")
248+
appSlug := v.GetString("app-slug")
249+
250+
fmt.Fprintf(os.Stderr, "Auto-uploading bundle to replicated.app...\n")
251+
if err := supportbundle.UploadBundleAutoDetect(response.ArchivePath, licenseID, appSlug); err != nil {
252+
fmt.Fprintf(os.Stderr, "Auto-upload failed: %v\n", err)
253+
fmt.Fprintf(os.Stderr, "You can manually upload the bundle using: support-bundle upload %s\n", response.ArchivePath)
254+
} else {
255+
response.FileUploaded = true
256+
}
257+
}
258+
245259
if !response.FileUploaded {
246260
if appName := mainBundle.Labels["applicationName"]; appName != "" {
247261
f := `A support bundle for %s has been created in this directory
@@ -269,11 +283,12 @@ the %s Admin Console to begin analysis.`
269283
fmt.Printf("\r%s\r", cursor.ClearEntireLine())
270284
}
271285
if response.FileUploaded {
272-
fmt.Printf("A support bundle has been created and uploaded to your cluster for analysis. Please visit the Troubleshoot page to continue.\n")
286+
fmt.Printf("A support bundle has been created and uploaded to replicated.app for analysis.\n")
273287
fmt.Printf("A copy of this support bundle was written to the current directory, named %q\n", response.ArchivePath)
274288
} else {
275289
fmt.Printf("A support bundle has been created in the current directory named %q\n", response.ArchivePath)
276290
}
291+
277292
return nil
278293
}
279294

@@ -497,7 +512,7 @@ func (a *analysisOutput) FormattedAnalysisOutput() (outputJson string, err error
497512

498513
formatted, err := json.MarshalIndent(o, "", " ")
499514
if err != nil {
500-
return "", fmt.Errorf("\r * Failed to format analysis: %v\n", err)
515+
return "", fmt.Errorf("\r * Failed to format analysis: %v", err)
501516
}
502517
return string(formatted), nil
503518
}

0 commit comments

Comments
 (0)