1
0
Fork 0

Stickiness cookie name.

This commit is contained in:
Ludovic Fernandez 2017-10-12 17:50:03 +02:00 committed by Traefiker
parent cba0898e4f
commit 8cb3f0835a
21 changed files with 525 additions and 148 deletions

View file

@ -398,7 +398,7 @@ func (p *CatalogProvider) hasStickinessLabel(tags []string) bool {
stickyTag := p.getTag(types.LabelBackendLoadbalancerSticky, tags, "")
if len(stickyTag) > 0 {
log.Warn("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
log.Warnf("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
}
stickiness := len(stickinessTag) > 0 && strings.EqualFold(strings.TrimSpace(stickinessTag), "true")

View file

@ -9,6 +9,7 @@ import (
"github.com/BurntSushi/ty/fun"
"github.com/containous/traefik/types"
"github.com/hashicorp/consul/api"
"github.com/stretchr/testify/assert"
)
func TestConsulCatalogGetFrontendRule(t *testing.T) {
@ -891,3 +892,69 @@ func TestConsulCatalogGetBasicAuth(t *testing.T) {
})
}
}
func TestConsulCatalogHasStickinessLabel(t *testing.T) {
testCases := []struct {
desc string
tags []string
expected bool
}{
{
desc: "label missing",
tags: []string{},
expected: false,
},
{
desc: "sticky=true",
tags: []string{
"traefik.backend.loadbalancer.sticky=true",
},
expected: true,
},
{
desc: "stickiness=true",
tags: []string{
"traefik.backend.loadbalancer.stickiness=true",
},
expected: true,
},
{
desc: "sticky=true and stickiness=true",
tags: []string{
"traefik.backend.loadbalancer.sticky=true",
"traefik.backend.loadbalancer.stickiness=true",
},
expected: true,
},
{
desc: "sticky=false and stickiness=true",
tags: []string{
"traefik.backend.loadbalancer.sticky=true",
"traefik.backend.loadbalancer.stickiness=false",
},
expected: true,
},
{
desc: "sticky=true and stickiness=false",
tags: []string{
"traefik.backend.loadbalancer.sticky=true",
"traefik.backend.loadbalancer.stickiness=false",
},
expected: true,
},
}
provider := &CatalogProvider{
Prefix: "traefik",
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
actual := provider.hasStickinessLabel(test.tags)
assert.Equal(t, actual, test.expected)
})
}
}