diff --git a/cmd/troubleshoot/cli/root.go b/cmd/troubleshoot/cli/root.go index 55392505..f98fb713 100644 --- a/cmd/troubleshoot/cli/root.go +++ b/cmd/troubleshoot/cli/root.go @@ -17,7 +17,7 @@ import ( func RootCmd() *cobra.Command { cmd := &cobra.Command{ Use: "support-bundle [url]", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(0), Short: "Generate a support bundle", Long: `A support bundle is an archive of files, output, metrics and state from a server that can be used to assist when troubleshooting a Kubernetes cluster.`, @@ -47,8 +47,8 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust cmd.Flags().Bool("redact", true, "enable/disable default redactions") cmd.Flags().Bool("interactive", true, "enable/disable interactive mode") cmd.Flags().Bool("collect-without-permissions", true, "always generate a support bundle, even if it some require additional permissions") - cmd.Flags().StringSliceP("selector", "l", []string{"troubleshoot.io/kind=supportbundle-spec"}, "Selector to filter on for loading additional support bundle specs found in secrets within the cluster") - cmd.Flags().Bool("load-cluster-specs", false, "enable/disable loading additional support bundle specs found in secrets within the cluster") + cmd.Flags().StringSliceP("selector", "l", []string{"troubleshoot.io/kind=supportbundle-spec"}, "selector to filter on for loading additional support bundle specs found in secrets within the cluster") + cmd.Flags().Bool("load-cluster-specs", false, "enable/disable loading additional support bundle specs found in secrets within the cluster. required when no specs are provided on the command line") 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().StringP("output", "o", "", "specify the output file path for the support bundle") diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index f7d93a64..e57b9ec8 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -38,6 +38,10 @@ const ( ) func runTroubleshoot(v *viper.Viper, arg []string) error { + if v.GetBool("load-cluster-specs") == false && len(arg) == 0 { + return errors.New("flag load-cluster-specs must be set if no specs are provided on the command line") + } + interactive := v.GetBool("interactive") && isatty.IsTerminal(os.Stdout.Fd()) if interactive { @@ -139,7 +143,11 @@ func runTroubleshoot(v *viper.Viper, arg []string) error { return errors.Wrap(err, "failed to parse support bundle spec") } - mainBundle = supportbundle.ConcatSpec(mainBundle, parsedBundlesFromSecrets) + if mainBundle == nil { + mainBundle = parsedBundlesFromSecrets + } else { + supportbundle.ConcatSpec(mainBundle, parsedBundlesFromSecrets) + } parsedRedactors, err := supportbundle.ParseRedactorsFromSpec(multidocs) if err != nil { @@ -150,6 +158,10 @@ func runTroubleshoot(v *viper.Viper, arg []string) error { } } + if mainBundle == nil { + return errors.New("no specs provided to run") + } + for idx, redactor := range v.GetStringSlice("redactors") { redactorObj, err := supportbundle.GetRedactorFromURI(redactor) if err != nil {