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

added redirect tests for core redirect features #1556

Merged

Conversation

LiorLieberman
Copy link
Member

What type of PR is this?
/kind feature
/area conformance

What this PR does / why we need it:
Add tests for core redirect features

Which issue(s) this PR fixes:

Issue #1103

Does this PR introduce a user-facing change?:
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. kind/feature Categorizes issue or PR as related to a new feature. area/conformance cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 21, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @LiorLieberman!

It looks like this is your first PR to kubernetes-sigs/gateway-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @LiorLieberman. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@LiorLieberman
Copy link
Member Author

This is a draft working implementation to check core features for redirect.
@robscott I am not a fan of my own implementation 😅 for reasons we discussed offline.
mainly around the fact that that we initilaize the http client inside CaptureRoundTrip() and custom roundtripper implementations would have to customize their logic in order to be able to test conformance for redirects.

As per #1496 I think that we should add a roundTripper under DefaultRoundTripper to implementations to override it.

Perhaps we should continue with this lean implementation and amend accordingly once #1496 is finished?

a few more nits;
I do not like adding RedirectRequest type and IsRedirect() func under the roundtripper package but I did have an import cycle so had to do it. strong thoughts on it ?

@LiorLieberman LiorLieberman marked this pull request as ready for review November 21, 2022 17:22
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2022
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @LiorLieberman, this LGTM, just a few minor nits.

conformance/utils/http/http.go Outdated Show resolved Hide resolved
conformance/tests/httproute-request-redirect.yaml Outdated Show resolved Hide resolved
@@ -153,3 +179,14 @@ func formatDump(data []byte, prefix string) string {
data = startLineRegex.ReplaceAllLiteral(data, []byte(prefix))
return string(data)
}

func IsRedirect(statusCode int) bool {
// Gateway allows only 301, and 302
Copy link
Member

Choose a reason for hiding this comment

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

Even though we only allow 301 and 302, I'd make this logic more future-proof to include the full set of redirect codes. There's a chance we'll add more in the future, but even if not, it will be more helpful to show a more useful error message than if we didn't capture the redirect info.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you elaborate? my thought was to put it in a function so we will have a one central place for adding more codes in the future. I think now we want to fail conformance if someone returns something other than 301/302 because we do not support it, correct?

Copy link
Member

@robscott robscott Nov 22, 2022

Choose a reason for hiding this comment

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

Let's say an implementation is actually returning a 307 or 308. With the current code, we wouldn't actually populate the rest of the redirect info for the rest of the test logic, so it would just look like everything failed instead of just having the wrong status code set.

I think the IsRedirect function is primarily a check on if we should populate the new redirect struct. The roundtripper itself should not care about what is conformant or not, just in making sure it populates as much information as possible so the tests can determine if the response was conformant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thats a good point, however we do check for wrong status code

if expected.Response.StatusCode != cRes.StatusCode {
return fmt.Errorf("expected status code to be %d, got %d", expected.Response.StatusCode, cRes.StatusCode)
}

I agree the roundtripper should not care about conformance, would you prefer to construct the redirect struct always? Whats the value you think it'll give us? it wont change the behavior of the above lines - we will have a failure with a wrong status code still.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should always construct the redirect struct for any 3xx status code. Although the test will still fail, it will likely provide more useful information to the person debugging the test. Instead of simply knowing the code is wrong, they'll also be able to see if the location they are redirecting to has any issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, I have added all the codes but if you prefer I will do something like this instead let me know

func IsRedirect(statusCode int) bool {
	switch {
	case statusCode >= 300 && statusCode < 400:
		return true
	}
	return false
}

conformance/tests/httproute-request-redirect.yaml Outdated Show resolved Hide resolved
@robscott
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 22, 2022
@shaneutt shaneutt self-requested a review December 12, 2022 17:47
Copy link
Member

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

+1 to Rob's comments but they appear to be resolved already.

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: LiorLieberman, shaneutt

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 Dec 12, 2022
@robscott
Copy link
Member

🤔 looks like @k8s-ci-robot got stuck on the LGTM, adding another.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2022
@robscott robscott added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Dec 12, 2022
@k8s-ci-robot k8s-ci-robot merged commit 027075b into kubernetes-sigs:main Dec 12, 2022
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/conformance cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants