Normalize serviceName added to the service backend names
This commit is contained in:
parent
718fc7a79d
commit
e8e8b41eed
3 changed files with 20 additions and 10 deletions
|
@ -12,14 +12,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConsulCatalogGetFrontendRule(t *testing.T) {
|
func TestConsulCatalogGetFrontendRule(t *testing.T) {
|
||||||
provider := &CatalogProvider{
|
|
||||||
Domain: "localhost",
|
|
||||||
Prefix: "traefik",
|
|
||||||
FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}",
|
|
||||||
frontEndRuleTemplate: template.New("consul catalog frontend rule"),
|
|
||||||
}
|
|
||||||
provider.setupFrontEndTemplate()
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
service serviceUpdate
|
service serviceUpdate
|
||||||
|
@ -71,6 +63,14 @@ func TestConsulCatalogGetFrontendRule(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
provider := &CatalogProvider{
|
||||||
|
Domain: "localhost",
|
||||||
|
Prefix: "traefik",
|
||||||
|
FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}",
|
||||||
|
frontEndRuleTemplate: template.New("consul catalog frontend rule"),
|
||||||
|
}
|
||||||
|
provider.setupFrontEndTemplate()
|
||||||
|
|
||||||
actual := provider.getFrontendRule(test.service)
|
actual := provider.getFrontendRule(test.service)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
})
|
})
|
||||||
|
|
|
@ -433,9 +433,9 @@ func (p *Provider) getServicePriority(container dockerData, serviceName string)
|
||||||
// Extract backend from labels for a given service and a given docker container
|
// Extract backend from labels for a given service and a given docker container
|
||||||
func (p *Provider) getServiceBackend(container dockerData, serviceName string) string {
|
func (p *Provider) getServiceBackend(container dockerData, serviceName string) string {
|
||||||
if value, ok := getContainerServiceLabel(container, serviceName, "frontend.backend"); ok {
|
if value, ok := getContainerServiceLabel(container, serviceName, "frontend.backend"); ok {
|
||||||
return container.ServiceName + "-" + value
|
return provider.Normalize(container.ServiceName + "-" + value)
|
||||||
}
|
}
|
||||||
return strings.TrimPrefix(container.ServiceName, "/") + "-" + p.getBackend(container) + "-" + provider.Normalize(serviceName)
|
return provider.Normalize(container.ServiceName + "-" + p.getBackend(container) + "-" + serviceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract rule from labels for a given service and a given docker container
|
// Extract rule from labels for a given service and a given docker container
|
||||||
|
|
|
@ -173,12 +173,22 @@ func TestDockerGetServiceBackend(t *testing.T) {
|
||||||
container: containerJSON(name("foo")),
|
container: containerJSON(name("foo")),
|
||||||
expected: "foo-foo-myservice",
|
expected: "foo-foo-myservice",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
container: containerJSON(name("foo.bar")),
|
||||||
|
expected: "foo-bar-foo-bar-myservice",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
container: containerJSON(labels(map[string]string{
|
container: containerJSON(labels(map[string]string{
|
||||||
types.LabelBackend: "another-backend",
|
types.LabelBackend: "another-backend",
|
||||||
})),
|
})),
|
||||||
expected: "fake-another-backend-myservice",
|
expected: "fake-another-backend-myservice",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
container: containerJSON(labels(map[string]string{
|
||||||
|
types.LabelBackend: "another.backend",
|
||||||
|
})),
|
||||||
|
expected: "fake-another-backend-myservice",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
container: containerJSON(labels(map[string]string{
|
container: containerJSON(labels(map[string]string{
|
||||||
"traefik.myservice.frontend.backend": "custom-backend",
|
"traefik.myservice.frontend.backend": "custom-backend",
|
||||||
|
|
Loading…
Reference in a new issue