pkg
pkg copied to clipboard
Consider putting the admission review on the webhook context
> The use case is that I need to parse again the AdmissionRequest from Request.Body to perform further checks in the validating/mutating phase.
Would it make more sense for the AdmissionRequest go object to be on the context - instead of having the raw request body and parsing it again yourself?
Originally posted by @dprotaso in https://github.com/knative/pkg/issues/2583#issuecomment-1331507771
Yes it does. It does not only help to prevent us from parsing the request again, but also helps not to consume the Request.Body bytes when we do so.
/good-first-issue
@dprotaso: This request has been marked as suitable for new contributors.
Please ensure the request meets the requirements listed here.
If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.
In response to this:
/good-first-issue
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/assign
hey @dprotaso @elfotografo007 , could you give some pointers to where could I start looking into? thanks!
First, you can check this PR. Reading the HTTP request body r.Body will consume the bytes and you are not able to read it again afterwards. The PR reads it and sets a copy again in r.Body so it can be read a second time. The purpose of this issue is to make the AdmissionRequest go object to be available in the context cxt for later use.
To accomplish this, you may need to create something similar to ctx = apis.WithHTTPRequest(ctx, r) like ctx = apis.WithAdmissionRequest(ctx, r) to set it and apis.GetAdmissionRequest(ctx) to read it afterwards.
I really don't know about Knative internals so I cannot help you any further than this.
I would also remove apis.WithHTTPRequest - since we would want folks to use these GetAdmissionRequest helper
First, you can check this PR. Reading the HTTP request body
r.Bodywill consume the bytes and you are not able to read it again afterwards. The PR reads it and sets a copy again inr.Bodyso it can be read a second time. The purpose of this issue is to make theAdmissionRequestgo object to be available in the contextcxtfor later use.
@elfotografo007 got it .
I gad one naive doubt though - why can't it read for the second time? In the previous PR its mentioned it returns EOF? 🤔
When you read the bytes, they are consumed and gone forever. I mitigated the issue by using a TeeReader that reads the bytes and copies them back so they can be read again. This has a problem that if you read them again and don't copy them back, they are gone.
This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.
/lifecycle frozen
Is this issue being worked on ? If not, i'd love to look into the issue @elfotografo007
I am not working on it, so I guess you can take it.