From a179c3b399391080262b1e4925a3f91c92d29f91 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 3 Apr 2018 09:40:04 +0200 Subject: [PATCH] Fixes prefixed annotations support. --- provider/kubernetes/annotations.go | 4 +- provider/kubernetes/annotations_test.go | 52 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 provider/kubernetes/annotations_test.go diff --git a/provider/kubernetes/annotations.go b/provider/kubernetes/annotations.go index 9b2e6ab89..4b254ef1a 100644 --- a/provider/kubernetes/annotations.go +++ b/provider/kubernetes/annotations.go @@ -77,13 +77,13 @@ func getAnnotationName(annotations map[string]string, name string) string { } if _, ok := annotations[label.Prefix+name]; ok { - return name + return label.Prefix + name } // TODO [breaking] remove label support if lbl, compat := compatibilityMapping[name]; compat { if _, ok := annotations[lbl]; ok { - return name + return lbl } } diff --git a/provider/kubernetes/annotations_test.go b/provider/kubernetes/annotations_test.go new file mode 100644 index 000000000..d84e0d272 --- /dev/null +++ b/provider/kubernetes/annotations_test.go @@ -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) + }) + } +}