From aa65589391db2433691d8cebde5c77c090cae3a9 Mon Sep 17 00:00:00 2001 From: Sanskar Jaiswal Date: Tue, 30 May 2023 14:31:01 +0530 Subject: [PATCH] set controller-runtime logger to a null logger This is required because controller-runtime expects its consumers to set a logger through log.SetLogger within 30 seconds of the program's initalization. If not set, the entire debug stack is printed as an error. Ref: https://github.com/kubernetes-sigs/controller-runtime/blob/ed8be90/pkg/log/log.go#L59 Since we have our own logging and don't care about controller-runtime's logger, we configure it's logger to do nothing. Signed-off-by: Sanskar Jaiswal --- cmd/flux/main.go | 11 +++++++++++ go.mod | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/flux/main.go b/cmd/flux/main.go index f38223f8c1..9485110cb1 100644 --- a/cmd/flux/main.go +++ b/cmd/flux/main.go @@ -24,12 +24,14 @@ import ( "strings" "time" + "github.com/go-logr/logr" "github.com/spf13/cobra" "golang.org/x/term" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/cli-runtime/pkg/genericclioptions" _ "k8s.io/client-go/plugin/pkg/client/auth" + ctrllog "sigs.k8s.io/controller-runtime/pkg/log" runclient "github.com/fluxcd/pkg/runtime/client" @@ -170,6 +172,15 @@ func NewRootFlags() rootFlags { func main() { log.SetFlags(0) + + // This is required because controller-runtime expects its consumers to + // set a logger through log.SetLogger within 30 seconds of the program's + // initalization. If not set, the entire debug stack is printed as an + // error, see: https://github.com/kubernetes-sigs/controller-runtime/blob/ed8be90/pkg/log/log.go#L59 + // Since we have our own logging and don't care about controller-runtime's + // logger, we configure it's logger to do nothing. + ctrllog.SetLogger(logr.New(ctrllog.NullLogSink{})) + if err := rootCmd.Execute(); err != nil { if err, ok := err.(*RequestError); ok { diff --git a/go.mod b/go.mod index 2a18d0d24e..690b1f877e 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/fluxcd/pkg/version v0.2.2 github.com/fluxcd/source-controller/api v1.0.0-rc.4 github.com/go-git/go-git/v5 v5.7.0 + github.com/go-logr/logr v1.2.4 github.com/gonvenience/bunt v1.3.5 github.com/gonvenience/ytbx v1.4.4 github.com/google/go-cmp v0.5.9 @@ -117,7 +118,6 @@ require ( github.com/go-errors/errors v1.4.2 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.4.1 // indirect - github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.1 // indirect github.com/go-openapi/swag v0.22.3 // indirect