Skip to content

Commit 15a4802

Browse files
authored
feat: Add dry run flag to print support bundle specs to std out (#1337)
* Add dry-run flag * No traces on dry run * More refactoring * More updates to support bundle binary * More refactoring changes * Different approach of loading specs from URIs * Self review * More changes after review and testing * fix how we parse oci image uri * Remove unnecessary comment * Add missing file * Fix failing tests * Better error check for no collectors * Add default collectors when parsing support bundle specs * Add missed test fixture * Download specs with correct headers * Fix typo
1 parent 0d4d305 commit 15a4802

File tree

22 files changed

+534
-171
lines changed

22 files changed

+534
-171
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
*.dylib
88
bin
99
.DS_Store
10+
11+
# npm generated files
1012
node_modules/
13+
package*.json
1114

1215
# Test binary, build with `go test -c`
1316
*.test

bin/watch.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,14 @@
22

33
const gri = require('gaze-run-interrupt');
44

5-
const binList = [
6-
// 'bin/analyze',
7-
// 'bin/preflight',
8-
'bin/support-bundle',
9-
// 'bin/collect'
10-
]
11-
const makeList = [
12-
// 'analyze',
13-
// 'preflight',
14-
'support-bundle',
15-
// 'collect'
16-
]
17-
185
const commands = [
196
// {
207
// command: 'rm',
218
// args: binList,
229
// },
2310
{
2411
command: 'make',
25-
args: makeList,
12+
args: ['build'],
2613
},
2714
];
2815

bin/watchrsync.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ const binList = [
1616
'bin/support-bundle',
1717
// 'bin/collect'
1818
]
19-
const makeList = [
20-
// 'analyze',
21-
// 'preflight',
22-
'support-bundle',
23-
// 'collect'
24-
]
2519

2620
const commands = [
2721
// {
@@ -30,7 +24,7 @@ const commands = [
3024
// },
3125
{
3226
command: 'make',
33-
args: makeList,
27+
args: ['build'],
3428
},
3529
];
3630

cmd/preflight/cli/oci_fetch.go

+14
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ package cli
22

33
import (
44
"fmt"
5+
"strings"
56

7+
"github.com/replicatedhq/troubleshoot/pkg/logger"
68
"github.com/replicatedhq/troubleshoot/pkg/oci"
79
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
811
)
912

1013
func OciFetchCmd() *cobra.Command {
1114
cmd := &cobra.Command{
1215
Use: "oci-fetch [URI]",
1316
Args: cobra.MinimumNArgs(1),
1417
Short: "Fetch a preflight from an OCI registry and print it to standard out",
18+
PreRun: func(cmd *cobra.Command, args []string) {
19+
v := viper.GetViper()
20+
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
21+
v.BindPFlags(cmd.Flags())
22+
23+
logger.SetupLogger(v)
24+
},
1525
RunE: func(cmd *cobra.Command, args []string) error {
1626
uri := args[0]
1727
data, err := oci.PullPreflightFromOCI(uri)
@@ -22,5 +32,9 @@ func OciFetchCmd() *cobra.Command {
2232
return nil
2333
},
2434
}
35+
36+
// Initialize klog flags
37+
logger.InitKlogFlags(cmd)
38+
2539
return cmd
2640
}

cmd/preflight/cli/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ that a cluster meets the requirements to run an application.`,
4949
}
5050

5151
err = preflight.RunPreflights(v.GetBool("interactive"), v.GetString("output"), v.GetString("format"), args)
52-
if v.GetBool("debug") || v.IsSet("v") {
52+
if !v.GetBool("dry-run") && (v.GetBool("debug") || v.IsSet("v")) {
5353
fmt.Printf("\n%s", traces.GetExporterInstance().GetSummary())
5454
}
5555

cmd/troubleshoot/cli/root.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
4545
}
4646

4747
err = runTroubleshoot(v, args)
48-
if v.GetBool("debug") || v.IsSet("v") {
48+
if !v.IsSet("dry-run") && (v.GetBool("debug") || v.IsSet("v")) {
4949
fmt.Printf("\n%s", traces.GetExporterInstance().GetSummary())
5050
}
5151

@@ -74,14 +74,15 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
7474
cmd.Flags().String("since", "", "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.")
7575
cmd.Flags().StringP("output", "o", "", "specify the output file path for the support bundle")
7676
cmd.Flags().Bool("debug", false, "enable debug logging. This is equivalent to --v=0")
77+
cmd.Flags().Bool("dry-run", false, "print support bundle spec without collecting anything")
7778

7879
// hidden in favor of the `insecure-skip-tls-verify` flag
7980
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")
8081
cmd.Flags().MarkHidden("allow-insecure-connections")
8182

8283
// `no-uri` references the `followURI` functionality where we can use an upstream spec when creating a support bundle
8384
// This flag makes sure we can also disable this and fall back to the default spec.
84-
cmd.Flags().Bool("no-uri", false, "When this flag is used, Troubleshoot does not attempt to retrieve the bundle referenced by the uri: field in the spec.`")
85+
cmd.Flags().Bool("no-uri", false, "When this flag is used, Troubleshoot does not attempt to retrieve the spec referenced by the uri: field`")
8586

8687
k8sutil.AddFlags(cmd.Flags())
8788

0 commit comments

Comments
 (0)