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

@ -430,14 +430,16 @@ func (p *Provider) getProtocol(application marathon.Application, serviceName str
}
func (p *Provider) hasStickinessLabel(application marathon.Application) bool {
_, okStickiness := p.getAppLabel(application, types.LabelBackendLoadbalancerStickiness)
labelStickiness, okStickiness := p.getAppLabel(application, types.LabelBackendLoadbalancerStickiness)
label, okSticky := p.getAppLabel(application, types.LabelBackendLoadbalancerSticky)
if len(label) > 0 {
log.Warn("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
labelSticky, okSticky := p.getAppLabel(application, types.LabelBackendLoadbalancerSticky)
if len(labelSticky) > 0 {
log.Warnf("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
}
return okStickiness || (okSticky && strings.EqualFold(strings.TrimSpace(label), "true"))
stickiness := okStickiness && len(labelStickiness) > 0 && strings.EqualFold(strings.TrimSpace(labelStickiness), "true")
sticky := okSticky && len(labelSticky) > 0 && strings.EqualFold(strings.TrimSpace(labelSticky), "true")
return stickiness || sticky
}
func (p *Provider) getStickinessCookieName(application marathon.Application) string {

View file

@ -856,7 +856,7 @@ func TestMarathonGetProtocol(t *testing.T) {
}
func TestMarathonHasStickinessLabel(t *testing.T) {
cases := []struct {
testCases := []struct {
desc string
application marathon.Application
expected bool
@ -867,35 +867,50 @@ func TestMarathonHasStickinessLabel(t *testing.T) {
expected: false,
},
{
desc: "label existing and value equals true (deprecated)",
desc: "sticky=true (deprecated)",
application: application(label(types.LabelBackendLoadbalancerSticky, "true")),
expected: true,
},
{
desc: "label existing and value equals false (deprecated)",
desc: "sticky=false (deprecated)",
application: application(label(types.LabelBackendLoadbalancerSticky, "false")),
expected: false,
},
{
desc: "label existing and value equals true",
desc: "stickiness=true",
application: application(label(types.LabelBackendLoadbalancerStickiness, "true")),
expected: true,
},
{
desc: "label existing and value equals false ",
desc: "stickiness=false ",
application: application(label(types.LabelBackendLoadbalancerStickiness, "true")),
expected: true,
},
{
desc: "sticky=false stickiness=true ",
application: application(
label(types.LabelBackendLoadbalancerStickiness, "true"),
label(types.LabelBackendLoadbalancerSticky, "false")),
expected: true,
},
{
desc: "sticky=true stickiness=false ",
application: application(
label(types.LabelBackendLoadbalancerStickiness, "false"),
label(types.LabelBackendLoadbalancerSticky, "true")),
expected: true,
},
}
for _, c := range cases {
c := c
t.Run(c.desc, func(t *testing.T) {
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
provider := &Provider{}
actual := provider.hasStickinessLabel(c.application)
if actual != c.expected {
t.Errorf("actual %q, expected %q", actual, c.expected)
actual := provider.hasStickinessLabel(test.application)
if actual != test.expected {
t.Errorf("actual %q, expected %q", actual, test.expected)
}
})
}