Add 'use regex' annotation to toggle nginx regex location modifier
This commit is contained in:
parent
f56e839134
commit
f29bdc3e8d
10 changed files with 325 additions and 39 deletions
|
|
@ -38,6 +38,8 @@ type Config struct {
|
|||
ForceSSLRedirect bool `json:"forceSSLRedirect"`
|
||||
// AppRoot defines the Application Root that the Controller must redirect if it's in '/' context
|
||||
AppRoot string `json:"appRoot"`
|
||||
// UseRegex indicates whether or not the locations use regex paths
|
||||
UseRegex bool `json:useRegex`
|
||||
}
|
||||
|
||||
// Equal tests for equality between two Redirect types
|
||||
|
|
@ -66,6 +68,9 @@ func (r1 *Config) Equal(r2 *Config) bool {
|
|||
if r1.AppRoot != r2.AppRoot {
|
||||
return false
|
||||
}
|
||||
if r1.UseRegex != r2.UseRegex {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
@ -94,6 +99,7 @@ func (a rewrite) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|||
abu, _ := parser.GetBoolAnnotation("add-base-url", ing)
|
||||
bus, _ := parser.GetStringAnnotation("base-url-scheme", ing)
|
||||
ar, _ := parser.GetStringAnnotation("app-root", ing)
|
||||
ur, _ := parser.GetBoolAnnotation("use-regex", ing)
|
||||
|
||||
return &Config{
|
||||
Target: rt,
|
||||
|
|
@ -102,5 +108,6 @@ func (a rewrite) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|||
SSLRedirect: sslRe,
|
||||
ForceSSLRedirect: fSslRe,
|
||||
AppRoot: ar,
|
||||
UseRegex: ur,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,3 +178,20 @@ func TestAppRoot(t *testing.T) {
|
|||
t.Errorf("Unexpected value got in AppRoot")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUseRegex(t *testing.T) {
|
||||
ing := buildIngress()
|
||||
|
||||
data := map[string]string{}
|
||||
data[parser.GetAnnotationWithPrefix("use-regex")] = "true"
|
||||
ing.SetAnnotations(data)
|
||||
|
||||
i, _ := NewParser(mockBackend{redirect: true}).Parse(ing)
|
||||
redirect, ok := i.(*Config)
|
||||
if !ok {
|
||||
t.Errorf("expected a App Context")
|
||||
}
|
||||
if redirect.UseRegex != true {
|
||||
t.Errorf("Unexpected value got in UseRegex")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue