-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let webhook controller uses a local scheme that understand admissionReview #60995
Let webhook controller uses a local scheme that understand admissionReview #60995
Conversation
Created a PR to see if I missed any test. |
@@ -130,10 +130,12 @@ func (a *MutatingWebhook) SetServiceResolver(sr config.ServiceResolver) { | |||
|
|||
// SetScheme sets a serializer(NegotiatedSerializer) which is derived from the scheme | |||
func (a *MutatingWebhook) SetScheme(scheme *runtime.Scheme) { | |||
admissionScheme := runtime.NewScheme() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can set the client manager serializer statically then, can't we? We should. Not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Let's wait for the test to finish?
I'll also test it with the sample apiserver to see if it fixes the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, am fine with the change if you move the code into the main constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k can lgtm
@hzxuzhonghu this was even easier than expected. Ptal. |
@@ -130,10 +130,12 @@ func (a *MutatingWebhook) SetServiceResolver(sr config.ServiceResolver) { | |||
|
|||
// SetScheme sets a serializer(NegotiatedSerializer) which is derived from the scheme | |||
func (a *MutatingWebhook) SetScheme(scheme *runtime.Scheme) { | |||
admissionScheme := runtime.NewScheme() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that the schemes we used had to be passed in so that the internal objects the admission plugin gets could be reliably converted to the external representations. Different schemes for different layers or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compare the converter below. The new scheme is about the versioned AdmissionReview with encoded payload objects.
Tests passed. Sending the commit that statically build the clientManager. |
I'll squash before merging. Got trouble setting up a test with the sample apiserver. Will seek for help in the sig slack. |
lgtm |
Created a scheme that only understands admission/v1beta1 and use it to encode/decode admissionReviews. Also made the NegotiationSerializer setup static
6e9e4b3
to
3ab5160
Compare
Verified it solved kubernetes/sample-apiserver#21.
I used the e2e test webhook, which expected a pod, thus the error. The presence of the error proved that the apiserver was able to build an admissionReview and sent it to the webhook. |
Squashed. |
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: caesarxuchao, deads2k The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/release-note-none |
@@ -54,8 +56,13 @@ func NewClientManager() (ClientManager, error) { | |||
if err != nil { | |||
return ClientManager{}, err | |||
} | |||
admissionScheme := runtime.NewScheme() | |||
admissionv1beta1.AddToScheme(admissionScheme) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can return an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ash2k Not necessary, because admissionv1beta1.AddToScheme
will never return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it will never return an error why does the function return an error? :) Tomorrow the implementation will change and something will not be right. E.g. some other code would be added before this function is called and it will cause it to error out. The worst thing about such situations is that it will be impossible to see the problem directly.
Russian proverb: "Even a stick shoots once a year" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should at least wrap those calls and trigger a panic. But this must be a pattern through the whole code base.
@deads2k can you label for 1.10? |
/status approved-for-milestone |
[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process Pull Request Labels
|
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
Moved to 1.9 milestone to request a cherry-pick. |
Commit found in the "release-1.9" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked. |
An alternative to #60965.
Fix #60963.
Fix kubernetes/sample-apiserver#21.
Created a scheme that only understands admission/v1beta1 and use it to
encode/decode admissionReviews.
cc @sttts