-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
E2E cases for APF #94925
Conversation
c411305
to
c599dd9
Compare
/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" |
There was a problem hiding this comment.
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") | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Name: testingFlowSchemaName, | ||
}, | ||
Spec: flowcontrolv1alpha1.FlowSchemaSpec{ | ||
MatchingPrecedence: 1000, // a rather higher precedence to ensure it make effect |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly
b4ade4f
to
698c501
Compare
/test pull-kubernetes-e2e-gce-alpha-features |
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) |
4d3ecd5
to
c37de0b
Compare
@adtac thanks for the diff, applied to the latest commit |
/test pull-kubernetes-e2e-gce-alpha-features |
/milestone v1.20 |
/retest |
/lgtm |
[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 |
/test pull-kubernetes-e2e-gce-alpha-features |
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") | ||
} |
There was a problem hiding this comment.
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)
}
@MikeSpreitzer @yue9944882 It's failing with the following error:
The non matching user will be matched via the |
@tkashem that error is from an older version of the commit. |
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.