From a90595961fc7aa5394da9c5323ecd9c8415b357a Mon Sep 17 00:00:00 2001 From: David Simansky Date: Wed, 30 Jun 2021 16:10:10 +0200 Subject: [PATCH] Move warning handler from `main()` to `RestConfig()` (#1359) * Move warning handler from main() to RestConfig() * Add also original code comment --- cmd/kn/main.go | 10 ---------- pkg/kn/commands/types.go | 9 ++++++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/cmd/kn/main.go b/cmd/kn/main.go index 064570b25..dc3d67809 100644 --- a/cmd/kn/main.go +++ b/cmd/kn/main.go @@ -24,8 +24,6 @@ import ( "time" "github.com/spf13/cobra" - "k8s.io/client-go/rest" - "knative.dev/client/pkg/kn/config" "knative.dev/client/pkg/kn/plugin" "knative.dev/client/pkg/kn/root" @@ -36,14 +34,6 @@ func init() { } func main() { - // Override client-go's warning handler to give us nicely printed warnings. - rest.SetDefaultWarningHandler( - rest.NewWarningWriter(os.Stderr, rest.WarningWriterOptions{ - // only print a given warning the first time we receive it - Deduplicate: true, - }), - ) - os.Exit(runWithExit(os.Args[1:])) } diff --git a/pkg/kn/commands/types.go b/pkg/kn/commands/types.go index 2cb943cad..733371078 100644 --- a/pkg/kn/commands/types.go +++ b/pkg/kn/commands/types.go @@ -192,10 +192,13 @@ func (params *KnParams) RestConfig() (*rest.Config, error) { return nil, knerrors.GetError(err) } if params.LogHTTP { - // TODO: When we update to the newer version of client-go, replace with - // config.Wrap() for future compat. - config.WrapTransport = util.NewLoggingTransport + config.Wrap(util.NewLoggingTransport) } + // Override client-go's warning handler to give us nicely printed warnings. + config.WarningHandler = rest.NewWarningWriter(os.Stderr, rest.WarningWriterOptions{ + // only print a given warning the first time we receive it + Deduplicate: true, + }) return config, nil }