Add app-root annotation support for kubernetes ingress

This commit is contained in:
Kim Min 2018-02-19 09:36:03 -05:00 committed by Traefiker Bot
parent d47c1a7975
commit 5ef55dd8b4
4 changed files with 96 additions and 6 deletions

View file

@ -226,7 +226,13 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
}
}
if rule := getRuleForPath(pa, i); rule != "" {
rule, err := getRuleForPath(pa, i)
if err != nil {
log.Errorf("Failed to get rule for ingress %s/%s: %s", i.Namespace, i.Name, err)
delete(templateObjects.Frontends, baseName)
continue
}
if rule != "" {
templateObjects.Frontends[baseName].Routes[pa.Path] = types.Route{
Rule: rule,
}
@ -313,19 +319,34 @@ func (p *Provider) loadConfig(templateObjects types.Configuration) *types.Config
return configuration
}
func getRuleForPath(pa extensionsv1beta1.HTTPIngressPath, i *extensionsv1beta1.Ingress) string {
func getRuleForPath(pa extensionsv1beta1.HTTPIngressPath, i *extensionsv1beta1.Ingress) (string, error) {
if len(pa.Path) == 0 {
return ""
return "", nil
}
ruleType := getStringValue(i.Annotations, annotationKubernetesRuleType, ruleTypePathPrefix)
rules := []string{ruleType + ":" + pa.Path}
if rewriteTarget := getStringValue(i.Annotations, annotationKubernetesRewriteTarget, ""); rewriteTarget != "" {
rules = append(rules, ruleTypeReplacePath+":"+rewriteTarget)
var pathReplaceAnnotation string
if ruleType == ruleTypeReplacePath {
pathReplaceAnnotation = annotationKubernetesRuleType
}
return strings.Join(rules, ";")
if rewriteTarget := getStringValue(i.Annotations, annotationKubernetesRewriteTarget, ""); rewriteTarget != "" {
if pathReplaceAnnotation != "" {
return "", fmt.Errorf("rewrite-target must not be used together with annotation %q", pathReplaceAnnotation)
}
rules = append(rules, ruleTypeReplacePath+":"+rewriteTarget)
pathReplaceAnnotation = annotationKubernetesRewriteTarget
}
if rootPath := label.GetStringValue(i.Annotations, annotationKubernetesAppRoot, ""); rootPath != "" && pa.Path == "/" {
if pathReplaceAnnotation != "" {
return "", fmt.Errorf("app-root must not be used together with annotation %q", pathReplaceAnnotation)
}
rules = append(rules, ruleTypeReplacePath+":"+rootPath)
}
return strings.Join(rules, ";"), nil
}
func getRuleForHost(host string) string {