Skip to content

Commit

Permalink
Use sugared logger in webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed May 18, 2024
1 parent b954d76 commit 9329975
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ import (
"knative.dev/pkg/webhook/resourcesemantics/validation"
"sigs.k8s.io/controller-runtime/pkg/healthz"

logctrl "sigs.k8s.io/controller-runtime/pkg/log"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/operator/logging"
"sigs.k8s.io/karpenter/pkg/operator/options"
Expand Down Expand Up @@ -92,7 +90,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont
ctx, startInformers := knativeinjection.EnableInjectionOrDie(ctx, cfg)
logger := logging.NewLogger(ctx, component).Sugar()
ctx = knativelogging.WithLogger(ctx, logger)
cmw := sharedmain.SetupConfigMapWatchOrDie(ctx, knativelogging.FromContext(ctx))
cmw := sharedmain.SetupConfigMapWatchOrDie(ctx, logger)
controllers, webhooks := sharedmain.ControllersAndWebhooksFromCtors(ctx, cmw, ctors...)

// Many of the webhooks rely on configuration, e.g. configurable defaults, feature flags.
Expand All @@ -102,7 +100,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont
if err := cmw.Start(ctx.Done()); err != nil {
// The controller-runtime log package lacks native support for fatal level logging,
// hence we utilize os.Exit() to signify encountering a fatal error.
logctrl.Log.Error(err, "Failed to start configuration manager")
logger.Error(err, "Failed to start configuration manager")
os.Exit(1)
}

Expand All @@ -126,7 +124,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont
if err != nil {
// The controller-runtime log package lacks native support for fatal level logging,
// hence we utilize os.Exit() to signify encountering a fatal error.
logctrl.Log.Error(err, "Failed to create webhook")
logger.Error(err, "Failed to create webhook")
os.Exit(1)
}
eg.Go(func() error {
Expand Down

0 comments on commit 9329975

Please sign in to comment.