Remove the trailing dot if the domain is not defined.
This commit is contained in:
parent
638960284e
commit
c7df82e695
8 changed files with 46 additions and 15 deletions
|
@ -111,7 +111,7 @@ func (p *Provider) getFrontendRule(service serviceUpdate) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.String()
|
return strings.TrimSuffix(buffer.String(), ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getServer(node *api.ServiceEntry) types.Server {
|
func (p *Provider) getServer(node *api.ServiceEntry) types.Server {
|
||||||
|
|
|
@ -1029,6 +1029,7 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
service serviceUpdate
|
service serviceUpdate
|
||||||
|
domain string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -1037,8 +1038,18 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
ServiceName: "foo",
|
ServiceName: "foo",
|
||||||
Attributes: []string{},
|
Attributes: []string{},
|
||||||
},
|
},
|
||||||
|
domain: "localhost",
|
||||||
expected: "Host:foo.localhost",
|
expected: "Host:foo.localhost",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "When no domain should return default host foo",
|
||||||
|
service: serviceUpdate{
|
||||||
|
ServiceName: "foo",
|
||||||
|
Attributes: []string{},
|
||||||
|
},
|
||||||
|
domain: "",
|
||||||
|
expected: "Host:foo",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "Should return host *.example.com",
|
desc: "Should return host *.example.com",
|
||||||
service: serviceUpdate{
|
service: serviceUpdate{
|
||||||
|
@ -1047,6 +1058,7 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
"traefik.frontend.rule=Host:*.example.com",
|
"traefik.frontend.rule=Host:*.example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
domain: "localhost",
|
||||||
expected: "Host:*.example.com",
|
expected: "Host:*.example.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1057,6 +1069,7 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
"traefik.frontend.rule=Host:{{.ServiceName}}.example.com",
|
"traefik.frontend.rule=Host:{{.ServiceName}}.example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
domain: "localhost",
|
||||||
expected: "Host:foo.example.com",
|
expected: "Host:foo.example.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1068,6 +1081,7 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
"contextPath=/bar",
|
"contextPath=/bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
domain: "localhost",
|
||||||
expected: "PathPrefix:/bar",
|
expected: "PathPrefix:/bar",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1078,7 +1092,7 @@ func TestProviderGetFrontendRule(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
p := &Provider{
|
p := &Provider{
|
||||||
Domain: "localhost",
|
Domain: test.domain,
|
||||||
Prefix: "traefik",
|
Prefix: "traefik",
|
||||||
FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}",
|
FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}",
|
||||||
frontEndRuleTemplate: template.New("consul catalog frontend rule"),
|
frontEndRuleTemplate: template.New("consul catalog frontend rule"),
|
||||||
|
|
|
@ -186,13 +186,16 @@ func (p *Provider) getFrontendRule(container dockerData, segmentLabels map[strin
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := label.GetStringValue(segmentLabels, label.TraefikDomain, p.Domain)
|
domain := label.GetStringValue(segmentLabels, label.TraefikDomain, p.Domain)
|
||||||
|
if len(domain) > 0 {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
if values, err := label.GetStringMultipleStrict(container.Labels, labelDockerComposeProject, labelDockerComposeService); err == nil {
|
if values, err := label.GetStringMultipleStrict(container.Labels, labelDockerComposeProject, labelDockerComposeService); err == nil {
|
||||||
return "Host:" + getSubDomain(values[labelDockerComposeService]+"."+values[labelDockerComposeProject]) + "." + domain
|
return "Host:" + getSubDomain(values[labelDockerComposeService]+"."+values[labelDockerComposeProject]) + domain
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(domain) > 0 {
|
if len(domain) > 0 {
|
||||||
return "Host:" + getSubDomain(container.ServiceName) + "." + domain
|
return "Host:" + getSubDomain(container.ServiceName) + domain
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -141,7 +141,11 @@ func (p *Provider) getFrontendRule(i ecsInstance) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := label.GetStringValue(i.SegmentLabels, label.TraefikDomain, p.Domain)
|
domain := label.GetStringValue(i.SegmentLabels, label.TraefikDomain, p.Domain)
|
||||||
defaultRule := "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + domain
|
if len(domain) > 0 {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultRule := "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + domain
|
||||||
|
|
||||||
return label.GetStringValue(i.TraefikLabels, label.TraefikFrontendRule, defaultRule)
|
return label.GetStringValue(i.TraefikLabels, label.TraefikFrontendRule, defaultRule)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
|
@ -99,7 +99,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
|
@ -144,7 +144,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Auth: &types.Auth{
|
Auth: &types.Auth{
|
||||||
|
@ -195,7 +195,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Auth: &types.Auth{
|
Auth: &types.Auth{
|
||||||
|
@ -246,7 +246,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Auth: &types.Auth{
|
Auth: &types.Auth{
|
||||||
|
@ -305,7 +305,7 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
Backend: "backend-instance",
|
Backend: "backend-instance",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"route-frontend-instance": {
|
"route-frontend-instance": {
|
||||||
Rule: "Host:instance.",
|
Rule: "Host:instance",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Auth: &types.Auth{
|
Auth: &types.Auth{
|
||||||
|
|
|
@ -214,11 +214,14 @@ func (p *Provider) getFrontendRule(app appData) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := label.GetStringValue(app.SegmentLabels, label.TraefikDomain, p.Domain)
|
domain := label.GetStringValue(app.SegmentLabels, label.TraefikDomain, p.Domain)
|
||||||
|
if len(domain) > 0 {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
if len(app.SegmentName) > 0 {
|
if len(app.SegmentName) > 0 {
|
||||||
return "Host:" + strings.ToLower(provider.Normalize(app.SegmentName)) + "." + p.getSubDomain(app.ID) + "." + domain
|
return "Host:" + strings.ToLower(provider.Normalize(app.SegmentName)) + "." + p.getSubDomain(app.ID) + domain
|
||||||
}
|
}
|
||||||
return "Host:" + p.getSubDomain(app.ID) + "." + domain
|
return "Host:" + p.getSubDomain(app.ID) + domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPort(task marathon.Task, app appData) string {
|
func getPort(task marathon.Task, app appData) string {
|
||||||
|
|
|
@ -222,8 +222,11 @@ func (p *Provider) getFrontendRule(task taskData) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
domain := label.GetStringValue(task.TraefikLabels, label.TraefikDomain, p.Domain)
|
domain := label.GetStringValue(task.TraefikLabels, label.TraefikDomain, p.Domain)
|
||||||
|
if len(domain) > 0 {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
return "Host:" + p.getSegmentSubDomain(task) + "." + domain
|
return "Host:" + p.getSegmentSubDomain(task) + domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getServers(tasks []taskData) map[string]types.Server {
|
func (p *Provider) getServers(tasks []taskData) map[string]types.Server {
|
||||||
|
|
|
@ -128,7 +128,11 @@ func (p *Provider) serviceFilter(service rancherData) bool {
|
||||||
|
|
||||||
func (p *Provider) getFrontendRule(serviceName string, labels map[string]string) string {
|
func (p *Provider) getFrontendRule(serviceName string, labels map[string]string) string {
|
||||||
domain := label.GetStringValue(labels, label.TraefikDomain, p.Domain)
|
domain := label.GetStringValue(labels, label.TraefikDomain, p.Domain)
|
||||||
defaultRule := "Host:" + strings.ToLower(strings.Replace(serviceName, "/", ".", -1)) + "." + domain
|
if len(domain) > 0 {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultRule := "Host:" + strings.ToLower(strings.Replace(serviceName, "/", ".", -1)) + domain
|
||||||
|
|
||||||
return label.GetStringValue(labels, label.TraefikFrontendRule, defaultRule)
|
return label.GetStringValue(labels, label.TraefikFrontendRule, defaultRule)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue