From 7c74f8b75525e29653a1d32642412d28da0225a8 Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Fri, 10 Jun 2022 15:39:23 +0000 Subject: [PATCH] Disable client-go logging --- cmd/analyze/cli/root.go | 10 +++++++++- cmd/collect/cli/root.go | 10 +++++++++- cmd/preflight/cli/root.go | 10 +++++++++- cmd/troubleshoot/cli/root.go | 10 +++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cmd/analyze/cli/root.go b/cmd/analyze/cli/root.go index 9761fba9..68d45f6c 100644 --- a/cmd/analyze/cli/root.go +++ b/cmd/analyze/cli/root.go @@ -4,10 +4,12 @@ import ( "os" "strings" + "github.com/go-logr/logr" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" "github.com/replicatedhq/troubleshoot/pkg/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "k8s.io/klog/v2" ) func RootCmd() *cobra.Command { @@ -18,7 +20,12 @@ func RootCmd() *cobra.Command { Long: `Run a series of analyzers on a support bundle archive`, SilenceUsage: true, PreRun: func(cmd *cobra.Command, args []string) { - viper.BindPFlags(cmd.Flags()) + v := viper.GetViper() + v.BindPFlags(cmd.Flags()) + + if !v.GetBool("debug") { + klog.SetLogger(logr.Discard()) + } }, RunE: func(cmd *cobra.Command, args []string) error { v := viper.GetViper() @@ -32,6 +39,7 @@ func RootCmd() *cobra.Command { cobra.OnInitialize(initConfig) cmd.Flags().String("analyzers", "", "filename or url of the analyzers to use") + cmd.Flags().Bool("debug", false, "enable debug logging") viper.BindPFlags(cmd.Flags()) diff --git a/cmd/collect/cli/root.go b/cmd/collect/cli/root.go index 70a303e9..8a533963 100644 --- a/cmd/collect/cli/root.go +++ b/cmd/collect/cli/root.go @@ -4,10 +4,12 @@ import ( "os" "strings" + "github.com/go-logr/logr" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" "github.com/replicatedhq/troubleshoot/pkg/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "k8s.io/klog/v2" ) func RootCmd() *cobra.Command { @@ -18,7 +20,12 @@ func RootCmd() *cobra.Command { Long: `Run a collector and output the results.`, SilenceUsage: true, PreRun: func(cmd *cobra.Command, args []string) { - viper.BindPFlags(cmd.Flags()) + v := viper.GetViper() + v.BindPFlags(cmd.Flags()) + + if !v.GetBool("debug") { + klog.SetLogger(logr.Discard()) + } }, RunE: func(cmd *cobra.Command, args []string) error { v := viper.GetViper() @@ -39,6 +46,7 @@ func RootCmd() *cobra.Command { cmd.Flags().String("collector-pull-policy", "", "the pull policy of the collector image") cmd.Flags().String("selector", "", "selector (label query) to filter remote collection nodes on.") cmd.Flags().Bool("collect-without-permissions", false, "always generate a support bundle, even if it some require additional permissions") + cmd.Flags().Bool("debug", false, "enable debug logging") // 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") diff --git a/cmd/preflight/cli/root.go b/cmd/preflight/cli/root.go index 39215337..c612db0c 100644 --- a/cmd/preflight/cli/root.go +++ b/cmd/preflight/cli/root.go @@ -4,9 +4,11 @@ import ( "os" "strings" + "github.com/go-logr/logr" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" "github.com/spf13/cobra" "github.com/spf13/viper" + "k8s.io/klog/v2" ) func RootCmd() *cobra.Command { @@ -18,7 +20,12 @@ func RootCmd() *cobra.Command { that a cluster meets the requirements to run an application.`, SilenceUsage: true, PreRun: func(cmd *cobra.Command, args []string) { - viper.BindPFlags(cmd.Flags()) + v := viper.GetViper() + v.BindPFlags(cmd.Flags()) + + if !v.GetBool("debug") { + klog.SetLogger(logr.Discard()) + } }, RunE: func(cmd *cobra.Command, args []string) error { v := viper.GetViper() @@ -39,6 +46,7 @@ that a cluster meets the requirements to run an application.`, 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 preflight checks") + cmd.Flags().Bool("debug", false, "enable debug logging") viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) diff --git a/cmd/troubleshoot/cli/root.go b/cmd/troubleshoot/cli/root.go index 5698d341..00ca3844 100644 --- a/cmd/troubleshoot/cli/root.go +++ b/cmd/troubleshoot/cli/root.go @@ -5,11 +5,13 @@ import ( "os" "strings" + "github.com/go-logr/logr" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" "github.com/replicatedhq/troubleshoot/pkg/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "k8s.io/klog/v2" ) func RootCmd() *cobra.Command { @@ -21,7 +23,12 @@ func RootCmd() *cobra.Command { from a server that can be used to assist when troubleshooting a Kubernetes cluster.`, SilenceUsage: true, PreRun: func(cmd *cobra.Command, args []string) { - viper.BindPFlags(cmd.Flags()) + v := viper.GetViper() + v.BindPFlags(cmd.Flags()) + + if !v.GetBool("debug") { + klog.SetLogger(logr.Discard()) + } }, RunE: func(cmd *cobra.Command, args []string) error { v := viper.GetViper() @@ -43,6 +50,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust 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") + cmd.Flags().Bool("debug", false, "enable debug logging") // 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")