Fix use-regex nginx annotation
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
862488569d
commit
1881434ac6
3 changed files with 68 additions and 1 deletions
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: ingress-with-use-regex
|
||||
namespace: default
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/use-regex: "true"
|
||||
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
rules:
|
||||
- host: use-regex.localhost
|
||||
http:
|
||||
paths:
|
||||
- path: /test(.*)
|
||||
pathType: ImplementationSpecific
|
||||
backend:
|
||||
service:
|
||||
name: whoami
|
||||
port:
|
||||
number: 80
|
||||
|
|
@ -1060,7 +1060,7 @@ func buildRule(host string, pa netv1.HTTPIngressPath, config ingressConfig) stri
|
|||
rules = append(rules, fmt.Sprintf("Path(`%s`)", pa.Path))
|
||||
case netv1.PathTypePrefix:
|
||||
if ptr.Deref(config.UseRegex, false) {
|
||||
rules = append(rules, fmt.Sprintf("PathRegexp(`^%s`)", regexp.QuoteMeta(pa.Path)))
|
||||
rules = append(rules, fmt.Sprintf("PathRegexp(`^%s`)", pa.Path))
|
||||
} else {
|
||||
rules = append(rules, buildPrefixRule(pa.Path))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -533,6 +533,51 @@ func TestLoadIngresses(t *testing.T) {
|
|||
TLS: &dynamic.TLSConfiguration{},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Use Regex",
|
||||
paths: []string{
|
||||
"services.yml",
|
||||
"ingressclasses.yml",
|
||||
"ingresses/10-ingress-with-use-regex.yml",
|
||||
},
|
||||
expected: &dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{},
|
||||
Services: map[string]*dynamic.TCPService{},
|
||||
},
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Routers: map[string]*dynamic.Router{
|
||||
"default-ingress-with-use-regex-rule-0-path-0": {
|
||||
Rule: "Host(`use-regex.localhost`) && PathRegexp(`^/test(.*)`)",
|
||||
RuleSyntax: "default",
|
||||
Service: "default-ingress-with-use-regex-whoami-80",
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Services: map[string]*dynamic.Service{
|
||||
"default-ingress-with-use-regex-whoami-80": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "http://10.10.0.1:80",
|
||||
},
|
||||
{
|
||||
URL: "http://10.10.0.2:80",
|
||||
},
|
||||
},
|
||||
Strategy: "wrr",
|
||||
PassHostHeader: ptr.To(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: dynamic.DefaultFlushInterval,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ServersTransports: map[string]*dynamic.ServersTransport{},
|
||||
},
|
||||
TLS: &dynamic.TLSConfiguration{},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Default Backend",
|
||||
defaultBackendServiceName: "whoami",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue