diff --git a/go.mod b/go.mod index e58c0126..26e2091c 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect + github.com/bombsimon/logrusr/v4 v4.0.0 github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect diff --git a/go.sum b/go.sum index e5a67316..3af1ce4c 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bombsimon/logrusr/v4 v4.0.0 h1:Pm0InGphX0wMhPqC02t31onlq9OVyJ98eP/Vh63t1Oo= +github.com/bombsimon/logrusr/v4 v4.0.0/go.mod h1:pjfHC5e59CvjTBIU3V3sGhFWFAnsnhOR03TRc6im0l8= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/internal/controllers/manager.go b/internal/controllers/manager.go index dafd487f..84593e67 100644 --- a/internal/controllers/manager.go +++ b/internal/controllers/manager.go @@ -17,7 +17,7 @@ limitations under the License. package controllers import ( - "context" + "os" _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -28,12 +28,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" - log "github.com/sirupsen/logrus" - + logrusr "github.com/bombsimon/logrusr/v4" "github.com/padok-team/burrito/internal/controllers/terraformlayer" "github.com/padok-team/burrito/internal/controllers/terraformpullrequest" "github.com/padok-team/burrito/internal/controllers/terraformrepository" "github.com/padok-team/burrito/internal/storage/redis" + "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1" "github.com/padok-team/burrito/internal/burrito/config" @@ -65,8 +66,12 @@ func init() { } func (c *Controllers) Exec() { - log := log.WithContext(context.TODO()) - + ctrl.SetLogger(logrusr.New(&log.Logger{ + Out: os.Stderr, + Formatter: new(logrus.TextFormatter), + Hooks: make(logrus.LevelHooks), + Level: logrus.DebugLevel, + })) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: c.config.Controller.MetricsBindAddress, @@ -99,33 +104,33 @@ func (c *Controllers) Exec() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - log.Fatalf("unable to create repository controller: %s", err) + logrus.Fatalf("unable to create repository controller: %s", err) } - log.Infof("repository controller started successfully") + logrus.Infof("repository controller started successfully") case "pullrequest": if err = (&terraformpullrequest.Reconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Config: c.config, }).SetupWithManager(mgr); err != nil { - log.Fatalf("unable to create pullrequest controller: %s", err) + logrus.Fatalf("unable to create pullrequest controller: %s", err) } - log.Infof("pullrequest controller started successfully") + logrus.Infof("pullrequest controller started successfully") default: - log.Infof("unrecognized controller type %s, ignoring", ctrlType) + logrus.Infof("unrecognized controller type %s, ignoring", ctrlType) } } //+kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { - log.Fatalf("unable to set up health check: %s", err) + logrus.Fatalf("unable to set up health check: %s", err) } if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { - log.Fatalf("unable to set up ready check: %s", err) + logrus.Fatalf("unable to set up ready check: %s", err) } - log.Infof("starting manager") + logrus.Infof("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { - log.Fatalf("problem running manager: %s", err) + logrus.Fatalf("problem running manager: %s", err) } }