Skip to content

Commit

Permalink
fix: readd the setLogger to fix issue with controller-runtime (#169)
Browse files Browse the repository at this point in the history
* fix: readd the setLogger to fix issue with controller-runtime

* fix: testing a setLogger with zap

* fix: setting up logrus with an interface for logr.Logger
  • Loading branch information
Alan-pad authored Oct 12, 2023
1 parent 9697028 commit 006165a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
33 changes: 19 additions & 14 deletions internal/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package controllers

import (
"context"
"os"

_ "k8s.io/client-go/plugin/pkg/client/auth"

Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 006165a

Please sign in to comment.