1
0
Fork 0

Stickiness cookie name

This commit is contained in:
Ludovic Fernandez 2017-10-10 11:10:02 +02:00 committed by Traefiker
parent ed2eb7b5a6
commit a9d4b09bdb
24 changed files with 434 additions and 224 deletions

View file

@ -188,7 +188,8 @@ func (p *Provider) loadMarathonConfig() *types.Configuration {
"getMaxConnAmount": p.getMaxConnAmount,
"getLoadBalancerMethod": p.getLoadBalancerMethod,
"getCircuitBreakerExpression": p.getCircuitBreakerExpression,
"getSticky": p.getSticky,
"getStickinessCookieName": p.getStickinessCookieName,
"hasStickinessLabel": p.hasStickinessLabel,
"hasHealthCheckLabels": p.hasHealthCheckLabels,
"getHealthCheckPath": p.getHealthCheckPath,
"getHealthCheckInterval": p.getHealthCheckInterval,
@ -428,11 +429,22 @@ 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 {
return sticky
func (p *Provider) hasStickinessLabel(application marathon.Application) bool {
_, 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)
}
return "false"
return okStickiness || (okSticky && strings.EqualFold(strings.TrimSpace(label), "true"))
}
func (p *Provider) getStickinessCookieName(application marathon.Application) string {
if label, ok := p.getAppLabel(application, types.LabelBackendLoadbalancerStickinessCookieName); ok {
return label
}
return ""
}
func (p *Provider) getPassHostHeader(application marathon.Application, serviceName string) string {

View file

@ -855,21 +855,36 @@ func TestMarathonGetProtocol(t *testing.T) {
}
}
func TestMarathonGetSticky(t *testing.T) {
func TestMarathonHasStickinessLabel(t *testing.T) {
cases := []struct {
desc string
application marathon.Application
expected string
expected bool
}{
{
desc: "label missing",
application: application(),
expected: "false",
expected: false,
},
{
desc: "label existing",
desc: "label existing and value equals true (deprecated)",
application: application(label(types.LabelBackendLoadbalancerSticky, "true")),
expected: "true",
expected: true,
},
{
desc: "label existing and value equals false (deprecated)",
application: application(label(types.LabelBackendLoadbalancerSticky, "false")),
expected: false,
},
{
desc: "label existing and value equals true",
application: application(label(types.LabelBackendLoadbalancerStickiness, "true")),
expected: true,
},
{
desc: "label existing and value equals false ",
application: application(label(types.LabelBackendLoadbalancerStickiness, "true")),
expected: true,
},
}
@ -878,7 +893,7 @@ func TestMarathonGetSticky(t *testing.T) {
t.Run(c.desc, func(t *testing.T) {
t.Parallel()
provider := &Provider{}
actual := provider.getSticky(c.application)
actual := provider.hasStickinessLabel(c.application)
if actual != c.expected {
t.Errorf("actual %q, expected %q", actual, c.expected)
}