Fixes prefixed annotations support.
This commit is contained in:
parent
a820585f56
commit
a179c3b399
2 changed files with 54 additions and 2 deletions
|
@ -77,13 +77,13 @@ func getAnnotationName(annotations map[string]string, name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := annotations[label.Prefix+name]; ok {
|
if _, ok := annotations[label.Prefix+name]; ok {
|
||||||
return name
|
return label.Prefix + name
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO [breaking] remove label support
|
// TODO [breaking] remove label support
|
||||||
if lbl, compat := compatibilityMapping[name]; compat {
|
if lbl, compat := compatibilityMapping[name]; compat {
|
||||||
if _, ok := annotations[lbl]; ok {
|
if _, ok := annotations[lbl]; ok {
|
||||||
return name
|
return lbl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
provider/kubernetes/annotations_test.go
Normal file
52
provider/kubernetes/annotations_test.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package kubernetes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/containous/traefik/provider/label"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetAnnotationName(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
annotations map[string]string
|
||||||
|
name string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "with standard annotation",
|
||||||
|
name: annotationKubernetesPreserveHost,
|
||||||
|
annotations: map[string]string{
|
||||||
|
annotationKubernetesPreserveHost: "true",
|
||||||
|
},
|
||||||
|
expected: annotationKubernetesPreserveHost,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "with prefixed annotation",
|
||||||
|
name: annotationKubernetesPreserveHost,
|
||||||
|
annotations: map[string]string{
|
||||||
|
label.Prefix + annotationKubernetesPreserveHost: "true",
|
||||||
|
},
|
||||||
|
expected: label.Prefix + annotationKubernetesPreserveHost,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "with label",
|
||||||
|
name: annotationKubernetesPreserveHost,
|
||||||
|
annotations: map[string]string{
|
||||||
|
label.TraefikFrontendPassHostHeader: "true",
|
||||||
|
},
|
||||||
|
expected: label.TraefikFrontendPassHostHeader,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
test := test
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
actual := getAnnotationName(test.annotations, test.name)
|
||||||
|
assert.Equal(t, test.expected, actual)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue