Skip to content
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

Merged
merged 1 commit into from
Mar 12, 2018

Conversation

caesarxuchao
Copy link
Member

@caesarxuchao caesarxuchao commented Mar 9, 2018

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.

The webhook admission controller in a custom apiserver now works off-the-shelf.

cc @sttts

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 9, 2018
@caesarxuchao caesarxuchao self-assigned this Mar 9, 2018
@k8s-ci-robot k8s-ci-robot requested review from deads2k and sttts March 9, 2018 19:30
@caesarxuchao caesarxuchao changed the title Let webhook controller uses a local scheme that understand admissionReview [WIP] Let webhook controller uses a local scheme that understand admissionReview Mar 9, 2018
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2018
@caesarxuchao
Copy link
Member Author

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()
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k can lgtm

@sttts
Copy link
Contributor

sttts commented Mar 9, 2018

@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()
Copy link
Contributor

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?

Copy link
Contributor

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.

@caesarxuchao
Copy link
Member Author

Tests passed. Sending the commit that statically build the clientManager.

@caesarxuchao caesarxuchao changed the title [WIP] Let webhook controller uses a local scheme that understand admissionReview Let webhook controller uses a local scheme that understand admissionReview Mar 9, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2018
@caesarxuchao
Copy link
Member Author

I'll squash before merging.

Got trouble setting up a test with the sample apiserver. Will seek for help in the sig slack.

@deads2k
Copy link
Contributor

deads2k commented Mar 9, 2018

lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2018
Created a scheme that only understands admission/v1beta1 and use it to
encode/decode admissionReviews.

Also made the NegotiationSerializer setup static
@caesarxuchao
Copy link
Member Author

Verified it solved kubernetes/sample-apiserver#21.

$ kubectl create -f ../flunders/01-flunder.yaml
Error from server: error when creating "../flunders/01-flunder.yaml": admission webhook "deny-unwanted-pod-container-name-and-label.k8s.io" denied the request: expect resource to be { v1 pods}

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.

@caesarxuchao caesarxuchao assigned deads2k and sttts and unassigned caesarxuchao Mar 9, 2018
@caesarxuchao
Copy link
Member Author

Squashed.

@caesarxuchao
Copy link
Member Author

/retest

@deads2k
Copy link
Contributor

deads2k commented Mar 9, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 9, 2018
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caesarxuchao
Copy link
Member Author

/release-note-none
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 9, 2018
@@ -54,8 +56,13 @@ func NewClientManager() (ClientManager, error) {
if err != nil {
return ClientManager{}, err
}
admissionScheme := runtime.NewScheme()
admissionv1beta1.AddToScheme(admissionScheme)
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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" :)

Copy link
Contributor

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.

@sttts
Copy link
Contributor

sttts commented Mar 12, 2018

@deads2k can you label for 1.10?

@deads2k
Copy link
Contributor

deads2k commented Mar 12, 2018

/status approved-for-milestone
/kind bug
/priority important-soon
/milestone v1.10

@k8s-ci-robot k8s-ci-robot added status/approved-for-milestone kind/bug Categorizes issue or PR as related to a bug. labels Mar 12, 2018
@k8s-ci-robot k8s-ci-robot added this to the v1.10 milestone Mar 12, 2018
@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Mar 12, 2018
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@caesarxuchao @deads2k @sttts

Pull Request Labels
  • sig/api-machinery: Pull Request will be escalated to these SIGs if needed.
  • priority/important-soon: Escalate to the pull request owners and SIG owner; move out of milestone after several unsuccessful escalation attempts.
  • kind/bug: Fixes a bug discovered during the current release.
Help

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@caesarxuchao
Copy link
Member Author

Moved to 1.9 milestone to request a cherry-pick.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 13, 2018
@k8s-github-robot
Copy link

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.

k8s-github-robot pushed a commit that referenced this pull request Mar 22, 2018
…#60995-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #60995: Make admission webhooks work in custom apiservers.

Cherry pick of #60995 on release-1.9.

#60995: Make admission webhooks work in custom apiservers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants