Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dry run flag to print support bundle specs to std out #1337

Merged
merged 21 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading