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

Use Request Object interfaces instead of static scheme that is more appropriate for CRDs #74154

Merged
merged 5 commits into from
Feb 19, 2019

Conversation

mbohlool
Copy link
Contributor

@mbohlool mbohlool commented Feb 16, 2019

The admission plugin implementation uses an static scheme (set by .SetScheme method of the Plugin). While this works for standard types, it does not work for CRDs and resulted in bugs such as #73752. This change remove the static schema, and added an ObjectInterfaces which implemented by RequestScope and passed to .Admit and .Validate calls.

fixes #73752

@parhamdoustdar @liggitt

Fixes use of webhook admission plugins with multi-version custom resources

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 16, 2019
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 16, 2019
@liggitt
Copy link
Member

liggitt commented Feb 16, 2019

Approach looks good overall. One compile issue, and a couple import order issues

@mbohlool
Copy link
Contributor Author

/test pull-kubernetes-integration

*/

package admission

Copy link
Member

Choose a reason for hiding this comment

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

name this something other than test.go. is there a reason to limit this impl to tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is only used in test now. I think I can just move it somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to util.go

@liggitt
Copy link
Member

liggitt commented Feb 16, 2019

One nit on the helper filename, and the comment about not making patcher use the admission interface to collect object methods (leaving as is or declaring its own interface would be ok… I'd probably leave as is for this PR)

@mbohlool
Copy link
Contributor Author

All green. Ready to go! @liggitt

// ObjectInterfaces is an interface used by AdmissionController to get object interfaces
// such as Converter or Defaulter. These interfaces are normally coming from Request Scope
// to handle special cases like CRDs.
type ObjectInterfaces interface {
Copy link
Member

Choose a reason for hiding this comment

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

@mbohlool @liggitt adding this as a parameter to all admission controller would widely change all the admissions' interface. how about injecting a dynamic scheme getter func from the initializers instead a fixed scheme? sth like func GetScheme(gvk), if the gvk's not registered in the legacy scheme(which is, the requesting resource is not standard), it returns the extension scheme.

Copy link
Member

Choose a reason for hiding this comment

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

how about injecting a dynamic scheme getter func from the initializers instead a fixed scheme? sth like func GetScheme(gvk), if the gvk's not registered in the legacy scheme(which is, the requesting resource is not standard), it returns the extension scheme.

That seems more complex and error-prone. The choice is not between the legacy scheme and the extensions scheme, but between the legacy scheme and a per-resource converter/typer/defaulter for each custom resource. The object interfaces for the object being handled are in the rest handler, and fit much more naturally as a parameter to admit/validate.

@liggitt
Copy link
Member

liggitt commented Feb 19, 2019

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, mbohlool

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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 Feb 19, 2019
@liggitt liggitt added kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Feb 19, 2019
@k8s-ci-robot k8s-ci-robot removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 19, 2019
@k8s-ci-robot k8s-ci-robot merged commit 0ffd59e into kubernetes:master Feb 19, 2019
kanatohodets added a commit to kanatohodets/kubernetes that referenced this pull request Mar 8, 2019
}

// ValidationInterface is an abstract, pluggable interface for Admission Control decisions.
type ValidationInterface interface {
Interface

// Validate makes an admission decision based on the request attributes. It is NOT allowed to mutate
Validate(a Attributes) (err error)
Validate(a Attributes, o ObjectInterfaces) (err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

This silently disabled validation plugins of 3rdparty code bases. We should start caring about compatibility. We could have added ObjectInterfaces to the attributes without damaging third parties.

Copy link
Member

Choose a reason for hiding this comment

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

Changing either interface would have broken compatibility. I'd strongly recommend type assertions downstream to ensure interface matching.

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. area/apiserver 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. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
6 participants