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

Docs: Clarify from-to-www redirect direction. #11682

Merged
merged 2 commits into from
Jul 29, 2024

Conversation

chakrit
Copy link
Contributor

@chakrit chakrit commented Jul 26, 2024

This was not clear to me when reading the docs whether the ingress will redirect from non-www to with-www or the reverse. It's also not very clear from just grepping around the codebase. I found the answer by reading from this reddit link:

https://www.reddit.com/r/kubernetes/comments/pbl033/k8s_ingress_redirecting_www_to_nonwww_domains/

So, to save time for other people doing the same, which I assumes is a lot of people since it's a common scenario, I believe this little revision in the docs is warranted.

What this PR does / why we need it:

Update the docs to clarify, when setting from-to-www-redirect, which direction of redirection is going to be performed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

How Has This Been Tested?

Ran mkdocs and things seemed fine.

Checklist:

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

This was not clear to me when reading the docs whether the ingress will
redirect from non-www to with-www or the reverse. It's also not very
clear from just grepping around the codebase. I found the answer by
reading from this reddit link:

https://www.reddit.com/r/kubernetes/comments/pbl033/k8s_ingress_redirecting_www_to_nonwww_domains/

So, to save time for other people doing the same, which I assumes is a
lot of people since it's a common scenario, this little revision in the
docs is warranted.
Copy link

linux-foundation-easycla bot commented Jul 26, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: chakrit / name: Chakrit Wichian (e1a5d5c)
  • ✅ login: Gacko / name: Marco Ebert (d0199ab)

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 26, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @chakrit!

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 needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority labels Jul 26, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @chakrit. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 26, 2024
Copy link

netlify bot commented Jul 26, 2024

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit d0199ab
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/66a47e8ebde4a5000816159c

@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 Jul 26, 2024
@Gacko
Copy link
Member

Gacko commented Jul 26, 2024

/triage accepted
/kind documentation
/priority backlog
/lgtm
/hold
/cc @longwuyuan

@longwuyuan Unhold if LGTY.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/documentation Categorizes issue or PR as related to documentation. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 26, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Jul 26, 2024
@Gacko
Copy link
Member

Gacko commented Jul 26, 2024

/cherry-pick release-1.10

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed needs-priority labels Jul 26, 2024
@Gacko
Copy link
Member

Gacko commented Jul 26, 2024

/cherry-pick release-1.11

@chakrit
Copy link
Contributor Author

chakrit commented Jul 26, 2024

I'm burned out today, will comeback in a day or so and try looking at the tests and adding that paragraph if someone hasn't already added it. Thanks!

@Gacko
Copy link
Member

Gacko commented Jul 26, 2024

From to.app.gacko.io to www.to.app.gacko.io:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: www-to-app-gacko-io
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
  ingressClassName: nginx
  rules:
  - host: www.to.app.gacko.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: hello-world
            port:
              number: 80
% curl --verbose --silent "http://to.app.gacko.io" --output /dev/null
* Host to.app.gacko.io:80 was resolved.
* IPv6: (none)
* IPv4: 18.170.90.51, 18.175.29.196, 13.42.193.94
*   Trying 18.170.90.51:80...
* Connected to to.app.gacko.io (18.170.90.51) port 80
> GET / HTTP/1.1
> Host: to.app.gacko.io
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 308 Permanent Redirect
< Date: Fri, 26 Jul 2024 14:27:40 GMT
< Content-Type: text/html
< Content-Length: 164
< Connection: keep-alive
< Location: http://www.to.app.gacko.io
< 
{ [164 bytes data]
* Connection #0 to host to.app.gacko.io left intact

From www.from.app.gacko.io to from.app.gacko.io:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: from-app-gacko-io
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
  ingressClassName: nginx
  rules:
  - host: from.app.gacko.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: hello-world
            port:
              number: 80
% curl --verbose --silent "http://www.from.app.gacko.io" --output /dev/null  
* Host www.from.app.gacko.io:80 was resolved.
* IPv6: (none)
* IPv4: 18.170.90.51, 18.175.29.196, 13.42.193.94
*   Trying 18.170.90.51:80...
* Connected to www.from.app.gacko.io (18.170.90.51) port 80
> GET / HTTP/1.1
> Host: www.from.app.gacko.io
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 308 Permanent Redirect
< Date: Fri, 26 Jul 2024 14:28:13 GMT
< Content-Type: text/html
< Content-Length: 164
< Connection: keep-alive
< Location: http://from.app.gacko.io
< 
{ [164 bytes data]
* Connection #0 to host www.from.app.gacko.io left intact

@longwuyuan
Copy link
Contributor

thanks. my test was wrong.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 27, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 27, 2024
@Gacko Gacko changed the title Docs: Clarify from-to-www redirect direction. Docs: Clarify from-to-www redirect direction. Jul 27, 2024
@Gacko
Copy link
Member

Gacko commented Jul 27, 2024

I implemented the suggestions, hope this is fine for you @chakrit!

@Gacko
Copy link
Member

Gacko commented Jul 27, 2024

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chakrit, Gacko

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

@Gacko
Copy link
Member

Gacko commented Jul 29, 2024

@longwuyuan Can we get this PR merged in its current state?

@longwuyuan
Copy link
Contributor

longwuyuan commented Jul 29, 2024 via email

@Gacko
Copy link
Member

Gacko commented Jul 29, 2024

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 29, 2024
@k8s-ci-robot k8s-ci-robot merged commit e1d81b7 into kubernetes:main Jul 29, 2024
49 checks passed
@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #11692

In response to this:

/cherry-pick release-1.10

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-sigs/prow repository.

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #11693

In response to this:

/cherry-pick release-1.11

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-sigs/prow repository.

@dvglab
Copy link
Contributor

dvglab commented Jul 31, 2024

Hey guys, it looks like new documentation totally wrong:
For example, if .spec.rules.host is configured with a value like www.example.com, then this annotation will redirect to example.com.

But in reality it should be like this:
For example, if .spec.rules.host is configured with a value like example.com, then this annotation will redirect www.example.com to example.com

Waste about 3 hours of life before got it.

@Gacko
Copy link
Member

Gacko commented Jul 31, 2024

It's working in both ways. We tested this. See my comments from above. 🙂

@Gacko
Copy link
Member

Gacko commented Jul 31, 2024

But yeah, thinking about it, it's not really the best. Feel free to open a PR!

@dvglab
Copy link
Contributor

dvglab commented Aug 1, 2024

It's working in both ways. We tested this. See my comments from above. 🙂

Yep, but the problem is in the description. Once again, reading documentation literally "if .spec.rules.host is configured with a value like www.example.com, then this annotation will redirect to example.com." But it will NOT redirect to example.com, it will redirect FROM example.com TO www.example.com. That's the trick. And yes we can see it in your comments from above.

I'll open PR, thank you.

@dvglab
Copy link
Contributor

dvglab commented Aug 1, 2024

Opened PR #11712 (comment)

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/docs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants