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

E2E cases for APF #94925

Merged
merged 1 commit into from
Nov 2, 2020
Merged

E2E cases for APF #94925

merged 1 commit into from
Nov 2, 2020

Conversation

yue9944882
Copy link
Member

@yue9944882 yue9944882 commented Sep 21, 2020

this pull adds a E2E test that verifies the response headers should contain the information (for now which is object UID) corresponding flow-schema and priority-level upon enabling the APIPriorityAndFairness feature.

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Sep 21, 2020
@k8s-ci-robot k8s-ci-robot added area/apiserver area/test 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. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 21, 2020
@fedebongio
Copy link
Contributor

/cc @lavalamp

responseHeaderMatchedPriorityLevelConfigurationUID = "X-Kubernetes-PF-PriorityLevel-UID"
responseHeaderMatchedFlowSchemaUID = "X-Kubernetes-PF-FlowSchema-UID"
ResponseHeaderMatchedPriorityLevelConfigurationUID = "X-Kubernetes-PF-PriorityLevel-UID"
ResponseHeaderMatchedFlowSchemaUID = "X-Kubernetes-PF-FlowSchema-UID"
Copy link
Member

Choose a reason for hiding this comment

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

We should move these definitions to an api package, people should not be importing this package to get them.

}
if plUID := resp.Header.Get(filters.ResponseHeaderMatchedPriorityLevelConfigurationUID); plUID != string(createdPriorityLevel.ObjectMeta.UID) {
framework.Failf("uid mismatch from the testing flow-schema")
}
Copy link
Member

Choose a reason for hiding this comment

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

Also check that a non-matching request doesn't get the same headers?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2020
Name: testingFlowSchemaName,
},
Spec: flowcontrolv1alpha1.FlowSchemaSpec{
MatchingPrecedence: 1000, // a rather higher precedence to ensure it make effect
Copy link
Member

Choose a reason for hiding this comment

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

is this so that default flow schemas don't interfere?

Copy link
Member Author

Choose a reason for hiding this comment

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

exactly

@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 30, 2020
@yue9944882 yue9944882 force-pushed the apf-e2e branch 3 times, most recently from b4ade4f to 698c501 Compare October 30, 2020 03:22
@liggitt liggitt removed their request for review October 30, 2020 17:00
@adtac
Copy link
Member

adtac commented Oct 30, 2020

/test pull-kubernetes-e2e-gce-alpha-features

@adtac
Copy link
Member

adtac commented Oct 30, 2020

the test passes with the following diff applied:

diff --git a/test/e2e/apimachinery/flowcontrol.go b/test/e2e/apimachinery/flowcontrol.go
index 3c357cdb191..b017e84e5ca 100644
--- a/test/e2e/apimachinery/flowcontrol.go
+++ b/test/e2e/apimachinery/flowcontrol.go
@@ -97,23 +97,23 @@ var _ = SIGDescribe("[Feature:APIPriorityAndFairness][Alpha] response header sho
 
                ginkgo.By("response headers should contain flow-schema/priority-level uid")
 
-               if !testResponseHeaderMatches(f.ClientConfig(), matchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) {
+               if !testResponseHeaderMatches(f, matchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) {
                        framework.Failf("matching user doesnt received UID for the testing priority-level and flow-schema")
                }
-               if !testResponseHeaderMatches(f.ClientConfig(), nonMatchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) {
+               if testResponseHeaderMatches(f, nonMatchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) {
                        framework.Failf("non-matching user unexpectedly received UID for the testing priority-level and flow-schema")
                }
        })
 
 })
 
-func testResponseHeaderMatches(clientCfg *rest.Config, impersonatingUser, plUID, fsUID string) bool {
-       config := rest.CopyConfig(clientCfg)
+func testResponseHeaderMatches(f *framework.Framework, impersonatingUser, plUID, fsUID string) bool {
+       config := rest.CopyConfig(f.ClientConfig())
        config.Impersonate.UserName = impersonatingUser
        roundTripper, err := rest.TransportFor(config)
        framework.ExpectNoError(err)
 
-       req, err := http.NewRequest(http.MethodGet, "/version", nil)
+       req, err := http.NewRequest(http.MethodGet, f.ClientSet.CoreV1().RESTClient().Get().AbsPath("version").URL().String(), nil)
        framework.ExpectNoError(err)
 
        response, err := roundTripper.RoundTrip(req)

@yue9944882 yue9944882 force-pushed the apf-e2e branch 2 times, most recently from 4d3ecd5 to c37de0b Compare November 2, 2020 02:47
@yue9944882
Copy link
Member Author

@adtac thanks for the diff, applied to the latest commit

@adtac
Copy link
Member

adtac commented Nov 2, 2020

/test pull-kubernetes-e2e-gce-alpha-features

@ahg-g
Copy link
Member

ahg-g commented Nov 2, 2020

/milestone v1.20

@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Nov 2, 2020
@MikeSpreitzer
Copy link
Member

@MikeSpreitzer

@ahg-g
Copy link
Member

ahg-g commented Nov 2, 2020

/retest

@lavalamp
Copy link
Member

lavalamp commented Nov 2, 2020

/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 Nov 2, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, yue9944882

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 Nov 2, 2020
@adtac
Copy link
Member

adtac commented Nov 2, 2020

/test pull-kubernetes-e2e-gce-alpha-features

Comment on lines +108 to +113
if !testResponseHeaderMatches(f, matchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) {
framework.Failf("matching user doesnt received UID for the testing priority-level and flow-schema")
}
if testResponseHeaderMatches(f, nonMatchingUsername, string(createdPriorityLevel.UID), string(createdPriorityLevel.UID)) {
framework.Failf("non-matching user unexpectedly received UID for the testing priority-level and flow-schema")
}
Copy link
Contributor

@tkashem tkashem Nov 2, 2020

Choose a reason for hiding this comment

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

Nit: if we decompose the testResponseHeaderMatches function, we can report on the specific header that does not match.

{
        ginkgo.By("invoke API impersonating the matching user")
 
        response, err := invokeAPI(f, matchingUsername)
	if  err != nil {
		framework.Failf("Failed to invoke API with matching user impersonation")
	}

       ginkgo.By("response headers should contain flow-schema/priority-level uid for matching user")
       framework.ExpectEqual(fsUID, getMatchedFlowSchemaUID(response), "FlowSchema UID does not match")
       framework.ExpectEqual(plUID, getMatchedPriorityLevelConfigurationUID(response), "PriorityLevelConfiguration  UID does not match")       

       ginkgo.By("invoke API impersonating the non-matching user")
       //  non matching follows here.
}

func invokeAPI(f *framework.Framework, impersonatingUser string) (http.Response, error) {
	config := rest.CopyConfig(f.ClientConfig())
	config.Impersonate.UserName = impersonatingUser
	roundTripper, err := rest.TransportFor(config)
	framework.ExpectNoError(err)

	req, err := http.NewRequest(http.MethodGet, f.ClientSet.CoreV1().RESTClient().Get().AbsPath("version").URL().String(), nil)	
        framework.ExpectNoError(err)

	return roundTripper.RoundTrip(req)
}

func getMatchedFlowSchemaUID(response *http.Response) string {
        return response.Header.Get(flowcontrolv1alpha1.ResponseHeaderMatchedFlowSchemaUID)
}

func getMatchedPriorityLevelConfigurationUID(response *http.Response) string {
        return response.Header.Get(flowcontrolv1alpha1.ResponseHeaderMatchedPriorityLevelConfigurationUID)
}

@tkashem
Copy link
Contributor

tkashem commented Nov 2, 2020

@MikeSpreitzer @yue9944882 It's failing with the following error:

Nov  2 16:59:12.623: FAIL: non-matching user unexpectedly received UID for the testing priority-level and flow-schema

The non matching user will be matched via the global-default or catch-all, right?

@k8s-ci-robot k8s-ci-robot merged commit e947440 into kubernetes:master Nov 2, 2020
@adtac
Copy link
Member

adtac commented Nov 2, 2020

Nov 2 16:59:12.623: FAIL: non-matching user unexpectedly received UID for the testing priority-level and flow-schema

@tkashem that error is from an older version of the commit.

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 area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. 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/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

9 participants