Merge pull request #3174 from Shopify/rewrite-regex

Generalize Rewrite Block Creation and Deprecate AddBaseUrl (not backwards compatible)
This commit is contained in:
Kubernetes Prow Robot 2019-01-02 12:30:18 -08:00 committed by GitHub
commit 71cc6df74f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 71 additions and 396 deletions

View file

@ -57,11 +57,11 @@ spec:
paths:
- path: /foo/bar
backend:
serviceName: test
serviceName: service1
servicePort: 80
- path: /foo/bar/
backend:
serviceName: test
serviceName: service2
servicePort: 80
```
@ -79,14 +79,14 @@ spec:
paths:
- path: /foo/bar/.+
backend:
serviceName: test
serviceName: service3
servicePort: 80
```
The ingress controller would define the following location blocks, in order of descending length, within the NGINX template for the `test.com` server:
```txt
location ~* "^/foo/bar/.+\/?(?<baseuri>.*)" {
location ~* ^/foo/bar/.+ {
...
}
@ -101,13 +101,12 @@ location ~* "^/foo/bar" {
The following request URI's would match the corresponding location blocks:
- `test.com/foo/bar/1` matches `~* "^/foo/bar/.+\/?(?<baseuri>.*)"`
- `test.com/foo/bar/` matches `~* "^/foo/bar/"`
- `test.com/foo/bar` matches `~* "^/foo/bar"`
- `test.com/foo/bar/1` matches `~* ^/foo/bar/.+` and will go to service 3.
- `test.com/foo/bar/` matches `~* ^/foo/bar/` and will go to service 2.
- `test.com/foo/bar` matches `~* ^/foo/bar` and will go to service 1.
**IMPORTANT NOTES**:
- paths created under the `rewrite-ingress` are sorted before `\/?(?<baseuri>.*)` is appended. For example if the path defined within `test-ingress-2` was `/foo/.+` then the location block for `^/foo/.+\/?(?<baseuri>.*)` would be the LAST block listed.
- If the `use-regex` OR `rewrite-target` annotation is used on any Ingress for a given host, then the case insensitive regular expression [location modifier](https://nginx.org/en/docs/http/ngx_http_core_module.html#location) will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.
## Warning