Skip to content

Commit 79de63c

Browse files
committed
Avoid marshalling error in debug log line
Currently every webhook requests ended up logging this in debug: ``` 2020-06-10T16:04:20.883+0200 DEBUG controller-runtime.webhook.webhooks wrote response {"webhook": "/validate-some-resource", "UID": "e5d00608-7f47-4d00-bd91-b1a8955dc5a7", "allowed": true, "result": {}, "resultError": "got runtime.Object without object metadata: &Status{ListMeta:ListMeta{SelfLink:,ResourceVersion:,Continue:,RemainingItemCount:nil,},Status:,Message:,Reason:,Details:nil,Code:200,}"} ``` The problem is that a `Status` Object is a runtime.Object but which has no metadata which is not well received the `KubeAwareEncoder`. Signed-off-by: Fabian Ruff <[email protected]>
1 parent eb68324 commit 79de63c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/webhook/admission/http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ func (wh *Webhook) writeResponse(w io.Writer, response Response) {
9999
wh.writeResponse(w, Errored(http.StatusInternalServerError, err))
100100
} else {
101101
res := responseAdmissionReview.Response
102-
wh.log.V(1).Info("wrote response", "UID", res.UID, "allowed", res.Allowed, "result", res.Result)
102+
if log := wh.log; log.V(1).Enabled() {
103+
if res.Result != nil {
104+
log = log.WithValues("code", res.Result.Code, "reason", res.Result.Reason)
105+
}
106+
log.V(1).Info("wrote response", "UID", res.UID, "allowed", res.Allowed)
107+
}
103108
}
104109
}

0 commit comments

Comments
 (0)