mirror of
https://github.com/containous/traefik.git
synced 2024-12-23 17:34:13 +03:00
[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:
parent
219a6372b0
commit
f7d9dfafd0
@ -27,9 +27,6 @@ var _ provider.Provider = (*Provider)(nil)
|
||||
|
||||
const (
|
||||
annotationFrontendRuleType = "traefik.frontend.rule.type"
|
||||
ruleTypePathPrefixStrip = "PathPrefixStrip"
|
||||
ruleTypePathStrip = "PathStrip"
|
||||
ruleTypePath = "Path"
|
||||
ruleTypePathPrefix = "PathPrefix"
|
||||
)
|
||||
|
||||
@ -199,12 +196,8 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
||||
}
|
||||
|
||||
if len(pa.Path) > 0 {
|
||||
ruleType, unknown := getRuleTypeFromAnnotation(i.Annotations)
|
||||
switch {
|
||||
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 := i.Annotations[annotationFrontendRuleType]
|
||||
if ruleType == "" {
|
||||
ruleType = ruleTypePathPrefix
|
||||
}
|
||||
|
||||
@ -392,24 +385,3 @@ func (p *Provider) loadConfig(templateObjects types.Configuration) *types.Config
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/types"
|
||||
@ -333,19 +332,14 @@ func TestRuleType(t *testing.T) {
|
||||
frontendRuleType string
|
||||
}{
|
||||
{
|
||||
desc: "implicit default",
|
||||
desc: "rule type annotation missing",
|
||||
ingressRuleType: "",
|
||||
frontendRuleType: ruleTypePathPrefix,
|
||||
},
|
||||
{
|
||||
desc: "unknown ingress / explicit default",
|
||||
ingressRuleType: "unknown",
|
||||
frontendRuleType: ruleTypePathPrefix,
|
||||
},
|
||||
{
|
||||
desc: "explicit ingress",
|
||||
ingressRuleType: ruleTypePath,
|
||||
frontendRuleType: ruleTypePath,
|
||||
desc: "rule type annotation set",
|
||||
ingressRuleType: "Path",
|
||||
frontendRuleType: "Path",
|
||||
},
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
ingresses := []*v1beta1.Ingress{{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
|
Loading…
Reference in New Issue
Block a user