Backward compatibility for sticky
This commit is contained in:
parent
3afd6024b5
commit
08503655d9
22 changed files with 140 additions and 260 deletions
|
@ -188,8 +188,9 @@ func (p *Provider) loadMarathonConfig() *types.Configuration {
|
|||
"getMaxConnAmount": p.getMaxConnAmount,
|
||||
"getLoadBalancerMethod": p.getLoadBalancerMethod,
|
||||
"getCircuitBreakerExpression": p.getCircuitBreakerExpression,
|
||||
"getStickinessCookieName": p.getStickinessCookieName,
|
||||
"getSticky": p.getSticky,
|
||||
"hasStickinessLabel": p.hasStickinessLabel,
|
||||
"getStickinessCookieName": p.getStickinessCookieName,
|
||||
"hasHealthCheckLabels": p.hasHealthCheckLabels,
|
||||
"getHealthCheckPath": p.getHealthCheckPath,
|
||||
"getHealthCheckInterval": p.getHealthCheckInterval,
|
||||
|
@ -429,17 +430,17 @@ func (p *Provider) getProtocol(application marathon.Application, serviceName str
|
|||
return "http"
|
||||
}
|
||||
|
||||
func (p *Provider) getSticky(application marathon.Application) string {
|
||||
if sticky, ok := p.getAppLabel(application, types.LabelBackendLoadbalancerSticky); ok {
|
||||
log.Warnf("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
|
||||
return sticky
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
func (p *Provider) hasStickinessLabel(application marathon.Application) bool {
|
||||
labelStickiness, okStickiness := p.getAppLabel(application, 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)
|
||||
}
|
||||
|
||||
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
|
||||
return okStickiness && len(labelStickiness) > 0 && strings.EqualFold(strings.TrimSpace(labelStickiness), "true")
|
||||
}
|
||||
|
||||
func (p *Provider) getStickinessCookieName(application marathon.Application) string {
|
||||
|
|
|
@ -854,6 +854,36 @@ func TestMarathonGetProtocol(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
func TestMarathonGetSticky(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
application marathon.Application
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "label missing",
|
||||
application: application(),
|
||||
expected: "false",
|
||||
},
|
||||
{
|
||||
desc: "label existing",
|
||||
application: application(label(types.LabelBackendLoadbalancerSticky, "true")),
|
||||
expected: "true",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
provider := &Provider{}
|
||||
actual := provider.getSticky(test.application)
|
||||
if actual != test.expected {
|
||||
t.Errorf("actual %q, expected %q", actual, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarathonHasStickinessLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
@ -866,16 +896,6 @@ func TestMarathonHasStickinessLabel(t *testing.T) {
|
|||
application: application(),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "sticky=true (deprecated)",
|
||||
application: application(label(types.LabelBackendLoadbalancerSticky, "true")),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "sticky=false (deprecated)",
|
||||
application: application(label(types.LabelBackendLoadbalancerSticky, "false")),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "stickiness=true",
|
||||
application: application(label(types.LabelBackendLoadbalancerStickiness, "true")),
|
||||
|
@ -886,20 +906,6 @@ func TestMarathonHasStickinessLabel(t *testing.T) {
|
|||
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 _, test := range testCases {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue