PDGGK opened a new pull request, #2911:
URL: https://github.com/apache/apisix-ingress-controller/pull/2911

   ### Type of change:
   
   - [x] Bugfix
   
   ### What this PR does / why we need it:
   
   An Ingress path `/foo/` with `pathType: Prefix` is translated to the APISIX 
URIs `["/foo/", "/foo/*"]`. A request to `/foo` matches neither, so APISIX 
answers `404 Route Not Found`. The Ingress API defines Prefix matching so that 
the trailing slash does not matter: the `PathTypePrefix` doc in 
`k8s.io/api/networking/v1` says "/foo and /foo/ both match requests to /foo and 
/foo/".
   
   The translator now also adds the path without its trailing slash as an exact 
URI, so `/foo/` becomes `["/foo/", "/foo", "/foo/*"]`. The change only adds a 
URI. Paths without a trailing slash and `/` are translated as before, and 
`/foobar` still does not match.
   
   I checked the routing with the real data plane. I took the URIs the 
translator produces for that Ingress, served them from APISIX 3.17.0 in 
standalone mode, and sent requests to it:
   
   ```
   before: uris ["/foo/","/foo/*"]
   /foo      -> 404 {"error_msg":"404 Route Not Found"}
   /foo/     -> 200
   /foo/bar  -> 200
   /foobar   -> 404
   
   after: uris ["/foo/","/foo","/foo/*"]
   /foo      -> 200
   /foo/     -> 200
   /foo/bar  -> 200
   /foobar   -> 404
   /foo/bar/ -> 200
   ```
   
   `TestTranslateIngress_PrefixPathURIs` covers `/`, `/foo`, `/foo/` and 
`/foo/bar/`. Without the change, the two trailing-slash cases fail with 
`expected: []string{"/foo/", "/foo", "/foo/*"}` and `actual: []string{"/foo/", 
"/foo/*"}`. `go test ./internal/adc/... ./internal/provider/...` passes. `go 
vet`, gofmt, goimports-reviser and `golangci-lint` v2.7.1 (the version the 
Makefile pins) report nothing for the translator package.
   
   What I did not test: I did not run the e2e suite or a kind cluster. The 
check above feeds the translator output to APISIX directly, without the 
controller and ADC in between. One edge case stays as it is. If the same host 
has both `/foo` and `/foo/` as Prefix paths to different backends, the spec 
gives `/foo/` priority, but the Ingress translator does not set route 
priorities. A request to `/foo` now matches both routes, as `/foo/bar` already 
did before, and APISIX picks one by route order. With both routes loaded into 
standalone APISIX, `/foo`, `/foo/` and `/foo/bar` reached the same backends 
before and after the change.
   
   HTTPRoute `PathPrefix` has the same trailing-slash behavior in 
`translateGatewayHTTPRouteMatch`. I left it alone because #2897 is reworking 
that path matching.
   
   ### Pre-submission checklist:
   
   - [x] Did you explain what problem does this PR solve? Or what new features 
have been added?
   - [x] Have you added corresponding test cases?
   - [ ] Have you modified the corresponding document?
   - [x] Is this PR backward compatible? **If it is not backward compatible, 
please discuss on the [mailing 
list](https://github.com/apache/apisix-ingress-controller#community) first**
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to