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

Add path field for RequestRedirect Filter #2979

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

salonichf5
Copy link
Contributor

@salonichf5 salonichf5 commented Jan 6, 2025

Proposed changes

Write a clear and concise description that helps reviewers understand the purpose and impact of your changes. Use the
following format:

Problem: Users want to be able to provide path with the RequestRedirect filter.

Solution: Added functionality for path in RequestRedirect filter.

  • Extracted common functionality for MainRewrite in createMainRewriteForFilters.
  • Extracted common functionality for Path validator.

Testing:

Added unit tests, conformance test and manual testing.

Configure the following HTTPRoutes for tea and soda applications following tutorial

HTTPRoutes

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: tea-redirect
spec:
  parentRefs:
  - name: gateway
    sectionName: http
  hostnames:
  - "cafe.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /tea
    filters:
    - type: RequestRedirect
      requestRedirect:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /organic
        port: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: tea
spec:
  parentRefs:
  - name: gateway
    sectionName: http
  hostnames:
  - "cafe.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /organic
    backendRefs:
    - name: tea
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: soda-redirect
spec:
  parentRefs:
  - name: gateway
    sectionName: http
  hostnames:
  - "cafe.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /soda
    filters:
    - type: RequestRedirect
      requestRedirect:
        path:
          type: ReplaceFullPath
          replaceFullPath: /flavors
        port: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: soda
spec:
  parentRefs:
  - name: gateway
    sectionName: http
  hostnames:
  - "cafe.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /flavors
    backendRefs:
    - name: soda
      port: 80
EOF

Response for Request Redirect /tea

curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:44:29 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/organic
curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea/type --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:44:55 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/organic/type
curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea/type\?test\=v1 --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:45:18 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/organic/type?test=v1

Server address: 10.244.0.73:8080
Server name: tea-7b7d6c947d-s8djx
Date: 06/Jan/2025:16:45:18 +0000
URI: /organic/type?test=v1
Request ID: 74b1c95d02d9c07710672c6ea9690824
curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/soda --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:46:00 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/flavors
curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/soda/pepsi --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:46:29 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/flavors
curl -L --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/soda/pepsi\?test\=v1 --include
Handling connection for 8080
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Mon, 06 Jan 2025 16:53:24 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
Location: http://cafe.example.com:8080/flavors?test=v1

Server address: 10.244.0.74:8080
Server name: soda-7c76d95586-dnc4n
Date: 06/Jan/2025:16:53:24 +0000
URI: /flavors?test=v1
Request ID: ada01eabdcada8c32347b087971fb356

Please focus on (optional): If you any specific areas where you would like reviewers to focus their attention or provide
specific feedback, add them here.

Closes #1413

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Add path field for RequestRedirect filter.

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request tests Pull requests that update tests labels Jan 6, 2025
Copy link
Contributor

github-actions bot commented Jan 6, 2025

Deploy Preview will be available once build job completes!

Name Link
😎 Deploy Preview https://frontdoor-test-docs.nginx.com/previews/nginx-gateway-fabric/2979/

@salonichf5 salonichf5 force-pushed the feat/request-redirect-filter branch 3 times, most recently from 071a022 to 573d175 Compare January 6, 2025 17:24
@nginx nginx deleted a comment from codecov bot Jan 6, 2025
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.95%. Comparing base (3683b58) to head (17012b4).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2979      +/-   ##
==========================================
+ Coverage   89.93%   89.95%   +0.02%     
==========================================
  Files         111      111              
  Lines       11423    11452      +29     
  Branches       50       50              
==========================================
+ Hits        10273    10302      +29     
  Misses       1089     1089              
  Partials       61       61              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@salonichf5 salonichf5 force-pushed the feat/request-redirect-filter branch from 573d175 to 2c335e5 Compare January 6, 2025 18:04
@salonichf5 salonichf5 marked this pull request as ready for review January 6, 2025 18:12
@salonichf5 salonichf5 requested review from a team as code owners January 6, 2025 18:12
@salonichf5 salonichf5 requested a review from sjberman January 6, 2025 21:34
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

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

Great work on this @salonichf5. Just a few suggestions.

internal/mode/static/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/servers_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/httproute.go Show resolved Hide resolved
@salonichf5 salonichf5 requested a review from kate-osborn January 6, 2025 23:25
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@sjberman sjberman left a comment

Choose a reason for hiding this comment

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

Let's try to get @ADubhlaoich's approval as well if possible

@salonichf5 salonichf5 force-pushed the feat/request-redirect-filter branch from f9130e5 to 2d20bed Compare January 7, 2025 00:27
@salonichf5 salonichf5 requested a review from sjberman January 7, 2025 00:27
@salonichf5 salonichf5 force-pushed the feat/request-redirect-filter branch from 2d20bed to 2a614de Compare January 7, 2025 17:24
@salonichf5 salonichf5 requested a review from a team as a code owner January 7, 2025 17:24
@salonichf5 salonichf5 requested a review from a team as a code owner January 7, 2025 17:24
Copy link
Contributor

@ADubhlaoich ADubhlaoich left a comment

Choose a reason for hiding this comment

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

LGTM!

@salonichf5 salonichf5 merged commit 10db5e4 into main Jan 7, 2025
40 checks passed
@salonichf5 salonichf5 deleted the feat/request-redirect-filter branch January 7, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request tests Pull requests that update tests
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Filter: path support for RequestRedirectFilter
4 participants