Skip to content

Commit

Permalink
feat: Add dry run flag to print support bundle specs to std out (repl…
Browse files Browse the repository at this point in the history
…icatedhq#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
  • Loading branch information
banjoh authored Oct 10, 2023
1 parent 0d4d305 commit 15a4802
Show file tree
Hide file tree
Showing 22 changed files with 534 additions and 171 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*.dylib
bin
.DS_Store

# npm generated files
node_modules/
package*.json

# Test binary, build with `go test -c`
*.test
Expand Down
15 changes: 1 addition & 14 deletions bin/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@

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

const binList = [
// 'bin/analyze',
// 'bin/preflight',
'bin/support-bundle',
// 'bin/collect'
]
const makeList = [
// 'analyze',
// 'preflight',
'support-bundle',
// 'collect'
]

const commands = [
// {
// command: 'rm',
// args: binList,
// },
{
command: 'make',
args: makeList,
args: ['build'],
},
];

Expand Down
8 changes: 1 addition & 7 deletions bin/watchrsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ const binList = [
'bin/support-bundle',
// 'bin/collect'
]
const makeList = [
// 'analyze',
// 'preflight',
'support-bundle',
// 'collect'
]

const commands = [
// {
Expand All @@ -30,7 +24,7 @@ const commands = [
// },
{
command: 'make',
args: makeList,
args: ['build'],
},
];

Expand Down
14 changes: 14 additions & 0 deletions cmd/preflight/cli/oci_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ package cli

import (
"fmt"
"strings"

"github.com/replicatedhq/troubleshoot/pkg/logger"
"github.com/replicatedhq/troubleshoot/pkg/oci"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func OciFetchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "oci-fetch [URI]",
Args: cobra.MinimumNArgs(1),
Short: "Fetch a preflight from an OCI registry and print it to standard out",
PreRun: func(cmd *cobra.Command, args []string) {
v := viper.GetViper()
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
v.BindPFlags(cmd.Flags())

logger.SetupLogger(v)
},
RunE: func(cmd *cobra.Command, args []string) error {
uri := args[0]
data, err := oci.PullPreflightFromOCI(uri)
Expand All @@ -22,5 +32,9 @@ func OciFetchCmd() *cobra.Command {
return nil
},
}

// Initialize klog flags
logger.InitKlogFlags(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion cmd/preflight/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ that a cluster meets the requirements to run an application.`,
}

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

Expand Down
5 changes: 3 additions & 2 deletions cmd/troubleshoot/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
}

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

Expand Down Expand Up @@ -74,14 +74,15 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
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")
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")

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

// `no-uri` references the `followURI` functionality where we can use an upstream spec when creating a support bundle
// This flag makes sure we can also disable this and fall back to the default spec.
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.`")
cmd.Flags().Bool("no-uri", false, "When this flag is used, Troubleshoot does not attempt to retrieve the spec referenced by the uri: field`")

k8sutil.AddFlags(cmd.Flags())

Expand Down
Loading

0 comments on commit 15a4802

Please sign in to comment.