Skip to content

Commit b9f4fc4

Browse files
authored
feat: Dry run flag to print preflight specs to std out (#1240)
1 parent 5381350 commit b9f4fc4

File tree

25 files changed

+248
-135
lines changed

25 files changed

+248
-135
lines changed

cmd/analyze/cli/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"strings"
66

7-
"github.com/replicatedhq/troubleshoot/cmd/util"
7+
"github.com/replicatedhq/troubleshoot/cmd/internal/util"
88
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
99
"github.com/replicatedhq/troubleshoot/pkg/logger"
1010
"github.com/spf13/cobra"
@@ -43,6 +43,8 @@ func RootCmd() *cobra.Command {
4343

4444
cobra.OnInitialize(initConfig)
4545

46+
cmd.AddCommand(util.VersionCmd())
47+
4648
cmd.Flags().String("analyzers", "", "filename or url of the analyzers to use")
4749
cmd.Flags().Bool("debug", false, "enable debug logging")
4850

cmd/collect/cli/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"strings"
66

7-
"github.com/replicatedhq/troubleshoot/cmd/util"
7+
"github.com/replicatedhq/troubleshoot/cmd/internal/util"
88
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
99
"github.com/replicatedhq/troubleshoot/pkg/logger"
1010
"github.com/spf13/cobra"
@@ -43,7 +43,7 @@ func RootCmd() *cobra.Command {
4343

4444
cobra.OnInitialize(initConfig)
4545

46-
cmd.AddCommand(VersionCmd())
46+
cmd.AddCommand(util.VersionCmd())
4747

4848
cmd.Flags().StringSlice("redactors", []string{}, "names of the additional redactors to use")
4949
cmd.Flags().Bool("redact", true, "enable/disable default redactions")

cmd/collect/cli/version.go

Lines changed: 0 additions & 22 deletions
This file was deleted.
File renamed without changes.

cmd/troubleshoot/cli/version.go renamed to cmd/internal/util/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cli
1+
package util
22

33
import (
44
"fmt"

cmd/preflight/cli/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strings"
88

9-
"github.com/replicatedhq/troubleshoot/cmd/util"
9+
"github.com/replicatedhq/troubleshoot/cmd/internal/util"
1010
"github.com/replicatedhq/troubleshoot/internal/traces"
1111
"github.com/replicatedhq/troubleshoot/pkg/constants"
1212
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
@@ -64,10 +64,14 @@ that a cluster meets the requirements to run an application.`,
6464

6565
cobra.OnInitialize(initConfig)
6666

67-
cmd.AddCommand(VersionCmd())
67+
cmd.AddCommand(util.VersionCmd())
6868
cmd.AddCommand(OciFetchCmd())
6969
preflight.AddFlags(cmd.PersistentFlags())
7070

71+
// Dry run flag should be in cmd.PersistentFlags() flags made available to all subcommands
72+
// Adding here to avoid that
73+
cmd.Flags().Bool("dry-run", false, "print the preflight spec without running preflight checks")
74+
7175
k8sutil.AddFlags(cmd.Flags())
7276

7377
// Initialize klog flags

cmd/preflight/cli/version.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

cmd/troubleshoot/cli/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/replicatedhq/troubleshoot/cmd/util"
8+
"github.com/replicatedhq/troubleshoot/cmd/internal/util"
99
"github.com/replicatedhq/troubleshoot/internal/traces"
1010
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1111
"github.com/replicatedhq/troubleshoot/pkg/logger"
@@ -62,7 +62,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
6262

6363
cmd.AddCommand(Analyze())
6464
cmd.AddCommand(Redact())
65-
cmd.AddCommand(VersionCmd())
65+
cmd.AddCommand(util.VersionCmd())
6666

6767
cmd.Flags().StringSlice("redactors", []string{}, "names of the additional redactors to use")
6868
cmd.Flags().Bool("redact", true, "enable/disable default redactions")

docs/preflight.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ preflight [url] [flags]
2929
--cpuprofile string File path to write cpu profiling data
3030
--debug enable debug logging
3131
--disable-compression If true, opt-out of response compression for all requests to the server
32+
--dry-run print the preflight spec without running preflight checks
3233
--format string output format, one of human, json, yaml. only used when interactive is set to false (default "human")
3334
-h, --help help for preflight
3435
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
@@ -53,4 +54,4 @@ preflight [url] [flags]
5354
* [preflight oci-fetch](preflight_oci-fetch.md) - Fetch a preflight from an OCI registry and print it to standard out
5455
* [preflight version](preflight_version.md) - Print the current version and exit
5556

56-
###### Auto generated by spf13/cobra on 8-Jun-2023
57+
###### Auto generated by spf13/cobra on 31-Aug-2023

docs/preflight_oci-fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ preflight oci-fetch [URI] [flags]
3333

3434
* [preflight](preflight.md) - Run and retrieve preflight checks in a cluster
3535

36-
###### Auto generated by spf13/cobra on 8-Jun-2023
36+
###### Auto generated by spf13/cobra on 31-Aug-2023

0 commit comments

Comments
 (0)