Skip to content

Commit

Permalink
Merge pull request #2334 from sbueringer/pr-webhook-log-levels
Browse files Browse the repository at this point in the history
⚠ Change webhook request received / response written logs to log level 4
  • Loading branch information
k8s-ci-robot authored May 19, 2023
2 parents 260b822 + babed98 commit e7b9407
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/webhook/admission/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
wh.writeResponse(w, reviewResponse)
return
}
wh.getLogger(&req).V(1).Info("received request")
wh.getLogger(&req).V(4).Info("received request")

reviewResponse = wh.Handle(ctx, req)
wh.writeResponseTyped(w, reviewResponse, actualAdmRevGVK)
Expand Down Expand Up @@ -136,11 +136,11 @@ func (wh *Webhook) writeAdmissionResponse(w io.Writer, ar v1.AdmissionReview) {
}
} else {
res := ar.Response
if log := wh.getLogger(nil); log.V(1).Enabled() {
if log := wh.getLogger(nil); log.V(4).Enabled() {
if res.Result != nil {
log = log.WithValues("code", res.Result.Code, "reason", res.Result.Reason, "message", res.Result.Message)
}
log.V(1).Info("wrote response", "requestID", res.UID, "allowed", res.Allowed)
log.V(4).Info("wrote response", "requestID", res.UID, "allowed", res.Allowed)
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/webhook/authentication/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ar.SetGroupVersionKind(authenticationv1.SchemeGroupVersion.WithKind("TokenReview"))
_, actualTokRevGVK, err := authenticationCodecs.UniversalDeserializer().Decode(body, nil, &ar)
if err != nil {
wh.getLogger(&req).Error(err, "unable to decode the request")
wh.getLogger(nil).Error(err, "unable to decode the request")
reviewResponse = Errored(err)
wh.writeResponse(w, reviewResponse)
return
}
wh.getLogger(&req).V(1).Info("received request")
wh.getLogger(&req).V(4).Info("received request")

if req.Spec.Token == "" {
err = errors.New("token is empty")
Expand Down Expand Up @@ -135,9 +135,7 @@ func (wh *Webhook) writeTokenResponse(w io.Writer, ar authenticationv1.TokenRevi
wh.writeResponse(w, Errored(err))
}
res := ar
if wh.getLogger(nil).V(1).Enabled() {
wh.getLogger(nil).V(1).Info("wrote response", "requestID", res.UID, "authenticated", res.Status.Authenticated)
}
wh.getLogger(nil).V(4).Info("wrote response", "requestID", res.UID, "authenticated", res.Status.Authenticated)
}

// unversionedTokenReview is used to decode both v1 and v1beta1 TokenReview types.
Expand Down

0 comments on commit e7b9407

Please sign in to comment.