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

fix: remove unnecessary if statement when redirect annotation is defined #5340

Conversation

artemlive
Copy link
Contributor

@artemlive artemlive commented Apr 8, 2020

What this PR does / why we need it:

The problem has been described in the linked issue.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Which issue/s this PR fixes

fixes #5339

How Has This Been Tested?

The template has been tested at our company test/production environments for a month. Configuration generates correctly, redirects work as expected.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot
Copy link
Contributor

Welcome @artemlive!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. 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/ingress-nginx 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 8, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @artemlive. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 8, 2020
@aledbf
Copy link
Member

aledbf commented Apr 8, 2020

@artemlive please add e2e tests for this change.

It would be great if you could use this test

func TestStripLocationModifer(t *testing.T) {

@artemlive
Copy link
Contributor Author

artemlive commented Apr 8, 2020

@artemlive please add e2e tests for this change.

It would be great if you could use this test

func TestStripLocationModifer(t *testing.T) {

Thank you for the reply @aledbf ! I don't fully understand your advice, I've deleted unnecessary if statement which uses functionality covered by this test. Could you explain what do you mean?

@aledbf
Copy link
Member

aledbf commented Apr 8, 2020

Could you explain what do you mean?

Sorry. I meant, add an e2e test, testing the redirect and another one doing the redirect with a path like in the test.

Also, please remove the function stripLocationModifer and test. This is the only place where is being used.

@aledbf
Copy link
Member

aledbf commented Apr 8, 2020

@artemlive also, please sign the CLA.

@artemlive artemlive force-pushed the fix/remove-unnecessary-if-in-redirect branch from cd6b690 to eefb32c Compare April 8, 2020 16:03
@aledbf
Copy link
Member

aledbf commented Apr 8, 2020

/check-cla

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 8, 2020
@aledbf
Copy link
Member

aledbf commented Apr 8, 2020

/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 Apr 8, 2020
@codecov-io
Copy link

codecov-io commented Apr 8, 2020

Codecov Report

Merging #5340 into master will increase coverage by 0.03%.
The diff coverage is 81.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5340      +/-   ##
==========================================
+ Coverage   58.70%   58.73%   +0.03%     
==========================================
  Files          88       88              
  Lines        6908     6917       +9     
==========================================
+ Hits         4055     4063       +8     
- Misses       2410     2411       +1     
  Partials      443      443              
Impacted Files Coverage Δ
internal/ingress/controller/store/store.go 60.08% <66.66%> (+0.12%) ⬆️
internal/ingress/controller/controller.go 49.40% <100.00%> (ø)
internal/ingress/controller/template/template.go 80.10% <100.00%> (ø)
internal/ingress/metric/collectors/process.go 90.62% <0.00%> (+2.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2cc8282...39c01c6. Read the comment docs.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 8, 2020
@artemlive
Copy link
Contributor Author

/retest

1 similar comment
@artemlive
Copy link
Contributor Author

/retest

@artemlive
Copy link
Contributor Author

@aledbf I've fixed failed e2e tests, I think they cover redirect functionality testing you asked me to add.

var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code", func() {
f := framework.NewDefaultFramework("redirect")
ginkgo.It("should respond with a standard redirect code", func() {
ginkgo.By("setting permanent-redirect annotation")
host := "redirect"
redirectPath := "/something"
redirectURL := "http://redirect.example.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/permanent-redirect": redirectURL,
}
ing := framework.NewSingleIngress(host, redirectPath, host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
})
ginkgo.By("sending request to redirected URL path")
f.HTTPTestClient().
GET(redirectPath).
WithHeader("Host", host).
Expect().
Status(http.StatusMovedPermanently).
Header("Location").Equal(redirectURL)
})
ginkgo.It("should respond with a custom redirect code", func() {
ginkgo.By("setting permanent-redirect-code annotation")
host := "redirect"
redirectPath := "/something"
redirectURL := "http://redirect.example.com"
redirectCode := http.StatusFound
annotations := map[string]string{
"nginx.ingress.kubernetes.io/permanent-redirect": redirectURL,
"nginx.ingress.kubernetes.io/permanent-redirect-code": strconv.Itoa(redirectCode),
}
ing := framework.NewSingleIngress(host, redirectPath, host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
})
ginkgo.By("sending request to redirected URL path")
f.HTTPTestClient().
GET(redirectPath).
WithHeader("Host", host).
Expect().
Status(redirectCode).
Header("Location").Equal(redirectURL)
})
})

@aledbf
Copy link
Member

aledbf commented Apr 9, 2020

/lgtm
/approve

@aledbf
Copy link
Member

aledbf commented Apr 9, 2020

@artemlive thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, artemlive

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 9, 2020
@k8s-ci-robot k8s-ci-robot merged commit 55052c0 into kubernetes:master Apr 9, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration snippet with if statement and redirect annotation
4 participants