-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 annotation to allow modifiers to be used properly in kubernetes #3481
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,13 @@ import ( | |
var _ provider.Provider = (*Provider)(nil) | ||
|
||
const ( | ||
ruleTypePath = "Path" | ||
ruleTypePathPrefix = "PathPrefix" | ||
ruleTypePathStrip = "PathStrip" | ||
ruleTypePathPrefixStrip = "PathPrefixStrip" | ||
ruleTypeAddPrefix = "AddPrefix" | ||
ruleTypeReplacePath = "ReplacePath" | ||
ruleTypeReplacePathRegex = "ReplacePathRegex" | ||
traefikDefaultRealm = "traefik" | ||
traefikDefaultIngressClass = "traefik" | ||
defaultBackendName = "global-default-backend" | ||
|
@@ -511,6 +516,17 @@ func getRuleForPath(pa extensionsv1beta1.HTTPIngressPath, i *extensionsv1beta1.I | |
} | ||
|
||
ruleType := getStringValue(i.Annotations, annotationKubernetesRuleType, ruleTypePathPrefix) | ||
|
||
switch ruleType { | ||
case ruleTypePath, ruleTypePathPrefix, ruleTypePathStrip, ruleTypePathPrefixStrip: | ||
case ruleTypeReplacePath: | ||
log.Warnf("Using %s as %s will be deprecated in the future. Please use the %s annotation instead", ruleType, annotationKubernetesRuleType, annotationKubernetesRequestModifier) | ||
case "": | ||
return "", errors.New("cannot use empty rule") | ||
default: | ||
return "", fmt.Errorf("cannot use non-matcher rule: %q", ruleType) | ||
} | ||
|
||
rules := []string{ruleType + ":" + pa.Path} | ||
|
||
var pathReplaceAnnotation string | ||
|
@@ -532,9 +548,48 @@ func getRuleForPath(pa extensionsv1beta1.HTTPIngressPath, i *extensionsv1beta1.I | |
} | ||
rules = append(rules, ruleTypeReplacePath+":"+rootPath) | ||
} | ||
|
||
if requestModifier := getStringValue(i.Annotations, annotationKubernetesRequestModifier, ""); requestModifier != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the annotation consists of all whitespaces only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rude There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, added tests to include a bunch of other oddities |
||
rule, err := parseRequestModifier(requestModifier, ruleType) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
rules = append(rules, rule) | ||
} | ||
return strings.Join(rules, ";"), nil | ||
} | ||
|
||
func parseRequestModifier(requestModifier, ruleType string) (string, error) { | ||
trimmedRequestModifier := strings.TrimRight(requestModifier, " :") | ||
if trimmedRequestModifier == "" { | ||
return "", fmt.Errorf("rule %q is empty", requestModifier) | ||
} | ||
|
||
// Split annotation to determine modifier type | ||
modifierParts := strings.Split(trimmedRequestModifier, ":") | ||
if len(modifierParts) < 2 { | ||
return "", fmt.Errorf("rule %q is missing type or value", requestModifier) | ||
} | ||
|
||
modifier := strings.TrimSpace(modifierParts[0]) | ||
value := strings.TrimSpace(modifierParts[1]) | ||
|
||
switch modifier { | ||
case ruleTypeAddPrefix, ruleTypeReplacePath, ruleTypeReplacePathRegex: | ||
if ruleType == ruleTypeReplacePath { | ||
return "", fmt.Errorf("cannot use '%s: %s' and '%s: %s', as this leads to rule duplication, and unintended behavior", | ||
annotationKubernetesRuleType, ruleTypeReplacePath, annotationKubernetesRequestModifier, modifier) | ||
} | ||
case "": | ||
return "", errors.New("cannot use empty rule") | ||
default: | ||
return "", fmt.Errorf("cannot use non-modifier rule: %q", modifier) | ||
} | ||
|
||
return modifier + ":" + value, nil | ||
} | ||
|
||
func getRuleForHost(host string) string { | ||
if strings.Contains(host, "*") { | ||
return "HostRegexp:" + strings.Replace(host, "*", "{subdomain:[A-Za-z0-9-_]+}", 1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is a type - should'n it be
AddPrefix
instead ofAddPath
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tompson thanks. After changing to
AddPrefix
my ingress started working :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ferrarimarco can you maybe share your ingress configuration? I still cannot get mine working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tompson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much!
Unfortunately I am still not able to get my desired configuration to work.
I got a backend that is available under
/app
and I want a traefik configuration that allows user to call it with/app
or with/oldapp
- both ways should work exactly the same.I thought my config should look something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @dtomcej ! should this already work with v1.6.5 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the commit history and it seems like this will be in included in 1.7.0 but is not part of 1.6.5 - so I will have to wait to try it