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

webhook integration tests for non persistent resources #76959

Merged
merged 2 commits into from
Apr 24, 2019
Merged

webhook integration tests for non persistent resources #76959

merged 2 commits into from
Apr 24, 2019

Conversation

sbezverk
Copy link
Contributor

@sbezverk sbezverk commented Apr 23, 2019

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Adds integration tests for webhook admission for:
non persistent resources

Which issue(s) this PR fixes:
xref #76907

Does this PR introduce a user-facing change?:

Validating admission webhooks are now properly called for CREATE operations on the following resources: tokenreviews, subjectaccessreviews, localsubjectaccessreviews, selfsubjectaccessreviews, selfsubjectrulesreviews

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Apr 23, 2019
@k8s-ci-robot k8s-ci-robot added area/test 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 Apr 23, 2019
@sbezverk
Copy link
Contributor Author

/cc @liggitt

@sbezverk
Copy link
Contributor Author

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. 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 Apr 23, 2019
@@ -108,5 +108,11 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
tokenReview.Status.Audiences = resp.Audiences
}

if createValidation != nil {
Copy link
Member

Choose a reason for hiding this comment

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

do this on line 70, after we've validated but before we take action based on the review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -75,5 +75,11 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
localSubjectAccessReview.Status.EvaluationError = evaluationErr.Error()
}

if createValidation != nil {
Copy link
Member

Choose a reason for hiding this comment

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

move to line 65, after validation, before action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -78,5 +78,11 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
selfSAR.Status.EvaluationError = evaluationErr.Error()
}

if createValidation != nil {
Copy link
Member

Choose a reason for hiding this comment

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

move to line 62

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -79,6 +79,12 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
ret.Status.EvaluationError = err.Error()
}

if createValidation != nil {
Copy link
Member

Choose a reason for hiding this comment

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

move to line 68

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -67,5 +67,11 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation
subjectAccessReview.Status.EvaluationError = evaluationErr.Error()
}

if createValidation != nil {
Copy link
Member

Choose a reason for hiding this comment

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

move to line 57

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -852,6 +926,25 @@ func createOrGetResource(client dynamic.Interface, gvr schema.GroupVersionResour
return client.Resource(gvr).Namespace(ns).Create(stubObj, metav1.CreateOptions{})
}

func createOrGetNonPersistentResource(client dynamic.Interface, gvr schema.GroupVersionResource, resource metav1.APIResource) (*unstructured.Unstructured, error) {
Copy link
Member

Choose a reason for hiding this comment

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

this function isn't used, remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

gvr("", "v1", "namespaces"): {"delete": testNamespaceDelete},
gvr("apps", "v1beta1", "deployments/rollback"): {"create": testDeploymentRollback},
gvr("extensions", "v1beta1", "deployments/rollback"): {"create": testDeploymentRollback},
gvr("authentication.k8s.io", "v1", "tokenreviews"): {"create": testNonPersistentResourceCreate},
Copy link
Member

Choose a reason for hiding this comment

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

nit, add a blank line here to group all the types that use testNonPersistentResourceCreate (will need to be rebased anyway)

@@ -128,18 +129,52 @@ var (
parentResources = map[schema.GroupVersionResource]schema.GroupVersionResource{
gvr("extensions", "v1beta1", "replicationcontrollers/scale"): gvr("", "v1", "replicationcontrollers"),
}

nonPersistentObjects = map[schema.GroupVersionResource]etcd.StorageData{
Copy link
Member

Choose a reason for hiding this comment

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

nit: nonPersistentReviewObjects (to distinguish between this and other non-persistent subresources)

Copy link
Member

Choose a reason for hiding this comment

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

simplify this to map[schema.GroupVersionResource]string, no need to nest the Stub field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to keep the same name nonPersistentObjects in case GetStubObject can be used as a generic func to get stubs either from persistent or a non persistent data sources. If Reviews specific name is used then adding other non persistent type of object would require change of func..

Copy link
Member

Choose a reason for hiding this comment

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

ok

@@ -833,6 +894,19 @@ func getStubObj(gvr schema.GroupVersionResource, resource metav1.APIResource) (*
return stubObj, nil
}

func getNonPersistentStubObj(gvr schema.GroupVersionResource, resource metav1.APIResource) (*unstructured.Unstructured, error) {
Copy link
Member

Choose a reason for hiding this comment

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

inline this into testNonPersistentResourceCreate, we have no other callers

@liggitt
Copy link
Member

liggitt commented Apr 23, 2019

looks good, thanks for helping knock these out

a few comments, and will need a rebase once #76911 merges

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
}
// excludedResources lists resources / verb combinations that are not yet tested. this set should trend to zero.
excludedResources = map[schema.GroupVersionResource]sets.String{}
Copy link
Member

Choose a reason for hiding this comment

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

go ahead and delete excludedResources and drop the code that checks it. 100% coverage 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will do.. but we do not want to keep it as a place holder in case it is needed?

Copy link
Member

Choose a reason for hiding this comment

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

I don't want a convenient way for people to skip this test :)

if we really need it in the future for some unforeseen reason, we can add it back

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
@liggitt
Copy link
Member

liggitt commented Apr 23, 2019

/lgtm

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

/test pull-kubernetes-kubemark-e2e-gce-big

@sbezverk
Copy link
Contributor Author

@liggitt Could you approve it please..

@liggitt
Copy link
Member

liggitt commented Apr 24, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 24, 2019
@liggitt
Copy link
Member

liggitt commented Apr 24, 2019

/priority important-soon

@k8s-ci-robot k8s-ci-robot added 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. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. labels Apr 24, 2019
@k8s-ci-robot k8s-ci-robot merged commit 279d4e1 into kubernetes:master Apr 24, 2019
@liggitt liggitt removed the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Feb 18, 2020
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/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants