Backward compatibility for sticky
This commit is contained in:
parent
3afd6024b5
commit
08503655d9
22 changed files with 140 additions and 260 deletions
|
@ -275,6 +275,7 @@ func (p *Provider) loadDockerConfig(containersInspected []dockerData) *types.Con
|
|||
"hasMaxConnLabels": p.hasMaxConnLabels,
|
||||
"getMaxConnAmount": p.getMaxConnAmount,
|
||||
"getMaxConnExtractorFunc": p.getMaxConnExtractorFunc,
|
||||
"getSticky": p.getSticky,
|
||||
"getStickinessCookieName": p.getStickinessCookieName,
|
||||
"hasStickinessLabel": p.hasStickinessLabel,
|
||||
"getIsBackendLBSwarm": p.getIsBackendLBSwarm,
|
||||
|
@ -465,10 +466,10 @@ func (p *Provider) getServiceProtocol(container dockerData, serviceName string)
|
|||
func (p *Provider) hasLoadBalancerLabel(container dockerData) bool {
|
||||
_, errMethod := getLabel(container, types.LabelBackendLoadbalancerMethod)
|
||||
_, errSticky := getLabel(container, types.LabelBackendLoadbalancerSticky)
|
||||
if errMethod != nil && errSticky != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
_, errStickiness := getLabel(container, types.LabelBackendLoadbalancerStickiness)
|
||||
_, errCookieName := getLabel(container, types.LabelBackendLoadbalancerStickinessCookieName)
|
||||
|
||||
return errMethod == nil || errSticky == nil || errStickiness == nil || errCookieName == nil
|
||||
}
|
||||
|
||||
func (p *Provider) hasMaxConnLabels(container dockerData) bool {
|
||||
|
@ -646,15 +647,17 @@ func (p *Provider) getWeight(container dockerData) string {
|
|||
|
||||
func (p *Provider) hasStickinessLabel(container dockerData) bool {
|
||||
labelStickiness, errStickiness := getLabel(container, types.LabelBackendLoadbalancerStickiness)
|
||||
return errStickiness == nil && len(labelStickiness) > 0 && strings.EqualFold(strings.TrimSpace(labelStickiness), "true")
|
||||
}
|
||||
|
||||
labelSticky, errSticky := getLabel(container, types.LabelBackendLoadbalancerSticky)
|
||||
if len(labelSticky) > 0 {
|
||||
log.Warnf("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
|
||||
func (p *Provider) getSticky(container dockerData) string {
|
||||
if label, err := getLabel(container, types.LabelBackendLoadbalancerSticky); err == nil {
|
||||
if len(label) > 0 {
|
||||
log.Warnf("Deprecated configuration found: %s. Please use %s.", types.LabelBackendLoadbalancerSticky, types.LabelBackendLoadbalancerStickiness)
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
stickiness := errStickiness == nil && len(labelStickiness) > 0 && strings.EqualFold(strings.TrimSpace(labelStickiness), "true")
|
||||
sticky := errSticky == nil && len(labelSticky) > 0 && strings.EqualFold(strings.TrimSpace(labelSticky), "true")
|
||||
return stickiness || sticky
|
||||
return "false"
|
||||
}
|
||||
|
||||
func (p *Provider) getStickinessCookieName(container dockerData) string {
|
||||
|
|
|
@ -1060,24 +1060,10 @@ func TestDockerHasStickinessLabel(t *testing.T) {
|
|||
expected bool
|
||||
}{
|
||||
{
|
||||
desc: "no sticky/stickiness-label",
|
||||
desc: "no stickiness-label",
|
||||
container: containerJSON(),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "sticky true",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
types.LabelBackendLoadbalancerSticky: "true",
|
||||
})),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "sticky false",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
types.LabelBackendLoadbalancerSticky: "false",
|
||||
})),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "stickiness true",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
|
@ -1092,30 +1078,6 @@ func TestDockerHasStickinessLabel(t *testing.T) {
|
|||
})),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
desc: "sticky true + stickiness false",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
types.LabelBackendLoadbalancerSticky: "true",
|
||||
types.LabelBackendLoadbalancerStickiness: "false",
|
||||
})),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "sticky false + stickiness true",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
types.LabelBackendLoadbalancerSticky: "false",
|
||||
types.LabelBackendLoadbalancerStickiness: "true",
|
||||
})),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "sticky false + stickiness false",
|
||||
container: containerJSON(labels(map[string]string{
|
||||
types.LabelBackendLoadbalancerSticky: "false",
|
||||
types.LabelBackendLoadbalancerStickiness: "false",
|
||||
})),
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue