Skip to content

Commit

Permalink
Adapt response logging in webhook handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranzke committed May 25, 2021
1 parent aa4347a commit 2767220
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
14 changes: 6 additions & 8 deletions pkg/webhook/admission/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ func (wh *Webhook) writeAdmissionResponse(w io.Writer, ar v1.AdmissionReview) {
if err != nil {
wh.log.Error(err, "unable to encode the response")
wh.writeResponse(w, Errored(http.StatusInternalServerError, err))
} else {
res := ar.Response
if log := wh.log; log.V(1).Enabled() {
if res.Result != nil {
log = log.WithValues("code", res.Result.Code, "reason", res.Result.Reason)
}
log.V(1).Info("wrote response", "UID", res.UID, "allowed", res.Allowed)
}
}

log := wh.log.V(1)
if result := ar.Response.Result; result != nil {
log = log.WithValues("code", result.Code, "reason", result.Reason)
}
log.V(1).Info("wrote response", "UID", ar.Response.UID, "allowed", ar.Response.Allowed)
}

// unversionedAdmissionReview is used to decode both v1 and v1beta1 AdmissionReview types.
Expand Down
5 changes: 1 addition & 4 deletions pkg/webhook/authentication/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ func (wh *Webhook) writeTokenResponse(w io.Writer, ar authenticationv1.TokenRevi
wh.log.Error(err, "unable to encode the response")
wh.writeResponse(w, Errored(err))
}
res := ar
if log := wh.log; log.V(1).Enabled() {
log.V(1).Info("wrote response", "UID", res.UID, "authenticated", res.Status.Authenticated)
}
log.V(1).Info("wrote response", "UID", ar.UID, "authenticated", ar.Status.Authenticated)
return
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/webhook/authorization/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ func (wh *Webhook) writeSubjectAccessReviewResponse(w io.Writer, ar authorizatio
wh.log.Error(err, "unable to encode the response")
wh.writeResponse(w, Errored(err))
}
res := ar
if log := wh.log; log.V(1).Enabled() {
log.V(1).Info("wrote response", "UID", res.UID, "authorized", res.Status.Allowed)
}
return
log.V(1).Info("wrote response", "UID", ar.UID, "authorized", ar.Status.Allowed)
}

func (wh *Webhook) decodeRequestBody(body []byte) (unversionedSubjectAccessReview, *schema.GroupVersionKind, error) {
Expand Down

0 comments on commit 2767220

Please sign in to comment.