Skip to content

Commit

Permalink
Small logging fixes in webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed May 18, 2024
1 parent ca6203b commit 40d7cf0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclaim/lifecycle/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (l *Launch) launchNodeClaim(ctx context.Context, nodeClaim *v1beta1.NodeCla
switch {
case cloudprovider.IsInsufficientCapacityError(err):
l.recorder.Publish(InsufficientCapacityErrorEvent(nodeClaim, err))
log.FromContext(ctx).Error(fmt.Errorf("failed to launch nodeClaim, %w", err), "NodeClaim lifecycle error")
log.FromContext(ctx).Error(fmt.Errorf("launching nodeclaim, %w", err), "NodeClaim lifecycle error")

if err = l.kubeClient.Delete(ctx, nodeClaim); err != nil {
return nil, client.IgnoreNotFound(err)
Expand Down
14 changes: 4 additions & 10 deletions pkg/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"fmt"
"io"
"net/http"
"os"
"strings"

"github.com/samber/lo"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -99,10 +99,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont
// webhooks, so that things are properly initialized.
logger.Info("Starting configuration manager...")
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.
logger.Error(err, "Failed to start configuration manager")
os.Exit(1)
logger.Fatalw("Failed to start configuration manager", zap.Error(err))
}

// If we have one or more admission controllers, then start the webhook
Expand All @@ -123,10 +120,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont

wh, err = webhook.New(ctx, webhooks)
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.
logger.Error(err, "Failed to create webhook")
os.Exit(1)
logger.Fatalw("Failed to create webhook", zap.Error(err))
}
eg.Go(func() error {
return wh.Run(ctx.Done())
Expand All @@ -150,7 +144,7 @@ func Start(ctx context.Context, cfg *rest.Config, ctors ...knativeinjection.Cont

// Don't forward ErrServerClosed as that indicates we're already shutting down.
if err := eg.Wait(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error(err, "Error while running server")
logger.Errorw("Error while running server", zap.Error(err))
}
}

Expand Down

0 comments on commit 40d7cf0

Please sign in to comment.