Skip to content

Ingress NGINX - Support Redirect#299

Open
jgreeer wants to merge 24 commits intokubernetes-sigs:mainfrom
jgreeer:ingress-nginx/support-redirect
Open

Ingress NGINX - Support Redirect#299
jgreeer wants to merge 24 commits intokubernetes-sigs:mainfrom
jgreeer:ingress-nginx/support-redirect

Conversation

@jgreeer
Copy link
Contributor

@jgreeer jgreeer commented Jan 9, 2026

What type of PR is this?

Fixes #268

Does this PR introduce a user-facing change?:

Add support for `nginx.ingress.kubernetes.io/permanent-redirect` and `nginx.ingress.kubernetes.io/temporal-redirect` + warnings for `nginx.ingress.kubernetes.io/proxy-redirect-from` and `nginx.ingress.kubernetes.io/proxy-redirect-to`

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 9, 2026
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 9, 2026
@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 Jan 9, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @jgreeer. 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.

Details

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 9, 2026
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 13, 2026
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 13, 2026
@jgreeer
Copy link
Contributor Author

jgreeer commented Jan 15, 2026

nginx.ingress.kubernetes.io/from-to-www-redirect, nginx.ingress.kubernetes.io/permanent-redirect-code, and nginx.ingress.kubernetes.io/temporal-redirect-code require 307/308 status code support, so they cannot be implemented until v1.5 release.

@jgreeer jgreeer marked this pull request as ready for review January 16, 2026 18:16
@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 Jan 16, 2026
@k8s-ci-robot k8s-ci-robot requested a review from rikatz January 16, 2026 18:16
@Stevenjin8
Copy link
Contributor

tbh gwapi 1.5 is just around the corner. I think we can merge this as is. WDYT @mikemorris

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 23, 2026
@jgreeer
Copy link
Contributor Author

jgreeer commented Jan 23, 2026

tbh gwapi 1.5 is just around the corner. I think we can merge this as is. WDYT @mikemorris

this doesn't have the 307/308 status codes, it emits warnings for them. so we can merge now and then make another PR later for the status code annotations.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 23, 2026
@Stevenjin8
Copy link
Contributor

/ok-to-test

@Stevenjin8
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jgreeer, Stevenjin8

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Feb 3, 2026

// Set port if present
if parsedURL.Port() != "" {
port, err := strconv.Atoi(parsedURL.Port())
Copy link

Choose a reason for hiding this comment

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

Why are we ignoring this error? Let's append to errs.

Copy link
Contributor

Choose a reason for hiding this comment

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

This did get me thinking... we could have named ports here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this does gets caught by url.Parse() before we reach this, but i added a check to be safe. also not sure what you mean steven?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jgreeer i just reread this and what I said makes no sense

Copy link
Contributor

Choose a reason for hiding this comment

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

@jgreeer Atoi can only really fail if the port overflows int, which shouldn't be possible unless you are actively trying to mess up. This seems fine.

[]gatewayv1.HTTPRouteRule{redirectRule},
httpRouteContext.HTTPRoute.Spec.Rules...,
)

Copy link
Member

Choose a reason for hiding this comment

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

should we add BackendSource to adjust rule index?

RuleBackendSources[i][j] is the source of the jth backend in the ith element of HTTPRoute.Spec.Rules.
https://github.com/kubernetes-sigs/ingress2gateway/blob/main/pkg/i2gw/provider_intermediate/intermediate_representation.go#L70-L71

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, fixed this by adding the rule in backendsources but with no backends since it just redirects

Copy link
Contributor

Choose a reason for hiding this comment

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

the semantics are a bit weird on this but this sounds reasonable to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, couldn't you just add the requestRedirect to the existing rule? that might be better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this breaks when you have a path that redirects and a path that doesn't, trying to fix now

Copy link
Member

Choose a reason for hiding this comment

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

nits:
current tests look removed. e.g. TestAddDefaultSSLRedirect_disabledByAnnotation
could you rebase or merge main branch?

@jgreeer
Copy link
Contributor Author

jgreeer commented Feb 13, 2026

Changed approach to the following:

  • Iterate through all rules in the IR
  • Find a rule that has a source ingress with a redirect annotation
  • Add the redirect filter to that rule using values from URL.parse()
  • Remove backendRef from that rule (yaml isn't accepted if we don't do this)
  • Keep existing backendSource since it still contributed that rule

Also, always override the path with "/". Gateway api will keep the path from the match in the redirect, ingress-nginx does not.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Ingress NGINX] Support Redirect

5 participants