[k8s] Remove rule type path list.

Instead of doing sanity checks in the Kubernetes provider, we just
accept any non-empty value from the annotation and rely on the server
part to filter out unknown rules.

This allows us to automatically stay in sync with the currently
supported Path matchers/modifiers.
This commit is contained in:
Timo Reimann 2017-05-18 23:27:10 +02:00 committed by Ludovic Fernandez
parent 219a6372b0
commit f7d9dfafd0
2 changed files with 6 additions and 99 deletions

View file

@ -27,9 +27,6 @@ var _ provider.Provider = (*Provider)(nil)
const ( const (
annotationFrontendRuleType = "traefik.frontend.rule.type" annotationFrontendRuleType = "traefik.frontend.rule.type"
ruleTypePathPrefixStrip = "PathPrefixStrip"
ruleTypePathStrip = "PathStrip"
ruleTypePath = "Path"
ruleTypePathPrefix = "PathPrefix" ruleTypePathPrefix = "PathPrefix"
) )
@ -199,12 +196,8 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
} }
if len(pa.Path) > 0 { if len(pa.Path) > 0 {
ruleType, unknown := getRuleTypeFromAnnotation(i.Annotations) ruleType := i.Annotations[annotationFrontendRuleType]
switch { if ruleType == "" {
case unknown:
log.Warnf("Unknown RuleType '%s' for Ingress %s/%s, falling back to PathPrefix", ruleType, i.ObjectMeta.Namespace, i.ObjectMeta.Name)
fallthrough
case ruleType == "":
ruleType = ruleTypePathPrefix ruleType = ruleTypePathPrefix
} }
@ -392,24 +385,3 @@ func (p *Provider) loadConfig(templateObjects types.Configuration) *types.Config
} }
return configuration return configuration
} }
func getRuleTypeFromAnnotation(annotations map[string]string) (ruleType string, unknown bool) {
ruleType = annotations[annotationFrontendRuleType]
for _, knownRuleType := range []string{
ruleTypePathPrefixStrip,
ruleTypePathStrip,
ruleTypePath,
ruleTypePathPrefix,
} {
if strings.ToLower(ruleType) == strings.ToLower(knownRuleType) {
return knownRuleType, false
}
}
if ruleType != "" {
// Annotation is set but does not match anything we know.
unknown = true
}
return ruleType, unknown
}

View file

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"strings"
"testing" "testing"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
@ -333,19 +332,14 @@ func TestRuleType(t *testing.T) {
frontendRuleType string frontendRuleType string
}{ }{
{ {
desc: "implicit default", desc: "rule type annotation missing",
ingressRuleType: "", ingressRuleType: "",
frontendRuleType: ruleTypePathPrefix, frontendRuleType: ruleTypePathPrefix,
}, },
{ {
desc: "unknown ingress / explicit default", desc: "rule type annotation set",
ingressRuleType: "unknown", ingressRuleType: "Path",
frontendRuleType: ruleTypePathPrefix, frontendRuleType: "Path",
},
{
desc: "explicit ingress",
ingressRuleType: ruleTypePath,
frontendRuleType: ruleTypePath,
}, },
} }
@ -1773,65 +1767,6 @@ func TestInvalidPassHostHeaderValue(t *testing.T) {
} }
} }
func TestGetRuleTypeFromAnnotation(t *testing.T) {
tests := []struct {
in string
wantedUnknown bool
}{
{
in: ruleTypePathPrefixStrip,
wantedUnknown: false,
},
{
in: ruleTypePathStrip,
wantedUnknown: false,
},
{
in: ruleTypePath,
wantedUnknown: false,
},
{
in: ruleTypePathPrefix,
wantedUnknown: false,
},
{
wantedUnknown: false,
},
{
in: "Unknown",
wantedUnknown: true,
},
}
for _, test := range tests {
test := test
inputs := []string{test.in, strings.ToLower(test.in)}
if inputs[0] == inputs[1] {
// Lower-casing makes no difference -- truncating to single case.
inputs = inputs[:1]
}
for _, input := range inputs {
t.Run(fmt.Sprintf("in='%s'", input), func(t *testing.T) {
t.Parallel()
annotations := map[string]string{}
if test.in != "" {
annotations[annotationFrontendRuleType] = test.in
}
gotRuleType, gotUnknown := getRuleTypeFromAnnotation(annotations)
if gotUnknown != test.wantedUnknown {
t.Errorf("got unknown '%t', wanted '%t'", gotUnknown, test.wantedUnknown)
}
if gotRuleType != test.in {
t.Errorf("got rule type '%s', wanted '%s'", gotRuleType, test.in)
}
})
}
}
}
func TestKubeAPIErrors(t *testing.T) { func TestKubeAPIErrors(t *testing.T) {
ingresses := []*v1beta1.Ingress{{ ingresses := []*v1beta1.Ingress{{
ObjectMeta: v1.ObjectMeta{ ObjectMeta: v1.ObjectMeta{