Skip to content

Commit

Permalink
Merge pull request #3932 from aryan9600/null-logger
Browse files Browse the repository at this point in the history
Set `controller-runtime` logger to a null logger
  • Loading branch information
aryan9600 authored May 30, 2023
2 parents 9ee23a9 + aa65589 commit 390ff1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/flux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 390ff1b

Please sign in to comment.