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

Split the resource semantic webhooks into separate AdmissionControllers #848

Merged
merged 1 commit into from
Nov 15, 2019

Conversation

mattmoor
Copy link
Member

@mattmoor mattmoor commented Nov 5, 2019

By combining our validation logic into our mutating webhook we were previously allowing for mutating webhooks evaluated after our own to modify our resources into invalid shapes. There are no guarantees around ordering of mutating webhooks (that I could find), so the only way to remedy this properly is to split apart the two into separate webhook configurations:

  • defaulting: which runs during the mutating admission webhook phase
  • validation: which runs during the validating admission webhook phase.

The diagram in this post is very helpful in illustrating the flow of webhooks.

Fixes: #847

/hold

I need to stage downstream PRs for this.

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 5, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Nov 5, 2019
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 5, 2019
@mattmoor
Copy link
Member Author

mattmoor commented Nov 5, 2019

This also removes the long-deprecated apis.Immutable support in the webhook.

apis/interfaces.go Outdated Show resolved Hide resolved
webhook/resourcesemantics/validation/validation.go Outdated Show resolved Hide resolved
webhook/resourcesemantics/validation/validation.go Outdated Show resolved Hide resolved
ctx = apis.WithUserInfo(ctx, &req.UserInfo)

// None of the validators will accept a nil value for newObj.
if newObj == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved quite a lot up. No reason to deal with deserialization of the oldObj.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is largely copy/pasta, so I'd rather leave it for a follow-up cleanup pass.

webhook/resourcesemantics/validation/validation.go Outdated Show resolved Hide resolved
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 6, 2019
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 6, 2019
@vagababov
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 6, 2019
@vaikas
Copy link
Contributor

vaikas commented Nov 7, 2019

/lgtm
/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattmoor, vaikas

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

@matzew
Copy link
Member

matzew commented Nov 8, 2019

hold can be removed ?

mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 14, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 14, 2019
mattmoor added a commit to mattmoor/sample-controller that referenced this pull request Nov 14, 2019
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 14, 2019
mattmoor added a commit to mattmoor/sample-controller that referenced this pull request Nov 15, 2019
By combining our validation logic into our mutating webhook we were previously allowing for mutating webhooks evaluated after our own to modify our resources into invalid shapes.  There are no guarantees around ordering of mutating webhooks (that I could find), so the only way to remedy this properly is to split apart the two into separate webhook configurations:
 - `defaulting`: which runs during the mutating admission webhook phase
 - `validation`: which runs during the validating admission webhook phase.

The diagram in [this post](https://kubernetes.io/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/) is very helpful in illustrating the flow of webhooks.

Fixes: knative#847
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-pkg-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
webhook/resourcesemantics/defaulting/controller.go Do not exist 100.0%
webhook/resourcesemantics/defaulting/defaulting.go Do not exist 88.5%
webhook/resourcesemantics/defaulting/user_info.go Do not exist 93.3%
webhook/resourcesemantics/validation/controller.go Do not exist 100.0%
webhook/resourcesemantics/validation/validation.go Do not exist 94.7%
webhook/webhook.go 83.6% 82.7% -0.9

mattmoor added a commit to mattmoor/sample-controller that referenced this pull request Nov 15, 2019
@n3wscott
Copy link
Contributor

/lgtm

This is gonna fix some weird bugs.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 15, 2019
@mattmoor
Copy link
Member Author

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 15, 2019
@knative-prow-robot knative-prow-robot merged commit 4836f68 into knative:master Nov 15, 2019
@mattmoor mattmoor deleted the split-webhook branch November 15, 2019 00:51
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2019
mattmoor added a commit to mattmoor/eventing that referenced this pull request Nov 15, 2019
mattmoor added a commit to mattmoor/sample-controller that referenced this pull request Nov 15, 2019
knative-prow-robot pushed a commit to knative-extensions/sample-controller that referenced this pull request Nov 15, 2019
knative-prow-robot pushed a commit to knative/eventing that referenced this pull request Nov 15, 2019
knative-prow-robot pushed a commit to knative/serving that referenced this pull request Nov 15, 2019
imjasonh added a commit to imjasonh/pkg that referenced this pull request Mar 22, 2021
`NewAdmissionController` was moved to `resourcesemantics/validation` in knative#848 and this doc wasn't updated.
knative-prow-robot pushed a commit that referenced this pull request Mar 30, 2021
`NewAdmissionController` was moved to `resourcesemantics/validation` in #848 and this doc wasn't updated.
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split apart resource webhook
9 participants