Cosmetic changes.
This commit is contained in:
parent
e615e833bc
commit
16c86022bb
2 changed files with 15 additions and 11 deletions
|
@ -42,7 +42,7 @@ type Provider struct {
|
|||
TLS *provider.ClientTLS `description:"Enable Docker TLS support"`
|
||||
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon"`
|
||||
KeepAlive flaeg.Duration `description:"Set a non-default TCP Keep Alive time in seconds"`
|
||||
ForceTaskHostname bool `description:"Force to use the task IP hostname."`
|
||||
ForceTaskHostname bool `description:"Force to use the task's hostname."`
|
||||
Basic *Basic
|
||||
marathonClient marathon.Marathon
|
||||
}
|
||||
|
@ -527,25 +527,28 @@ func (p *Provider) getBackendServer(task marathon.Task, applications []marathon.
|
|||
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
||||
return ""
|
||||
}
|
||||
|
||||
numTaskIPAddresses := len(task.IPAddresses)
|
||||
switch {
|
||||
case application.IPAddressPerTask == nil || p.ForceTaskHostname:
|
||||
return task.Host
|
||||
case len(task.IPAddresses) == 0:
|
||||
log.Errorf("Missing marathon IPAddress from task %s", task.AppID)
|
||||
case numTaskIPAddresses == 0:
|
||||
log.Errorf("Missing IP address for Marathon application %s on task %s", application.ID, task.ID)
|
||||
return ""
|
||||
case len(task.IPAddresses) == 1:
|
||||
case numTaskIPAddresses == 1:
|
||||
return task.IPAddresses[0].IPAddress
|
||||
default:
|
||||
ipAddressIdxStr, ok := p.getLabel(application, "traefik.ipAddressIdx")
|
||||
if !ok {
|
||||
log.Errorf("Unable to get marathon IPAddress from task %s", task.AppID)
|
||||
log.Errorf("Found %d task IP addresses but missing IP address index for Marathon application %s on task %s", numTaskIPAddresses, application.ID, task.ID)
|
||||
return ""
|
||||
}
|
||||
ipAddressIdx, err := strconv.Atoi(ipAddressIdxStr)
|
||||
if err != nil {
|
||||
log.Errorf("Invalid marathon IPAddress from task %s", task.AppID)
|
||||
log.Errorf("Cannot use IP address index to select from %d task IP addresses for Marathon application %s on task %s: %s", numTaskIPAddresses, application.ID, task.ID, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return task.IPAddresses[ipAddressIdx].IPAddress
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,7 +344,8 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
if len(c.applications.Apps) > 0 {
|
||||
appID = c.applications.Apps[0].ID
|
||||
}
|
||||
t.Run(fmt.Sprintf("Running case: %s", appID), func(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("app ID: %s", appID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
fakeClient := newFakeClient(c.applicationsError, c.applications, c.tasksError, c.tasks)
|
||||
provider := &Provider{
|
||||
Domain: "docker.localhost",
|
||||
|
@ -355,15 +356,15 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
fakeClient.AssertExpectations(t)
|
||||
if c.expectedNil {
|
||||
if actualConfig != nil {
|
||||
t.Fatalf("Should have been nil, got %v", actualConfig)
|
||||
t.Fatalf("configuration should have been nil, got %v", actualConfig)
|
||||
}
|
||||
} else {
|
||||
// Compare backends
|
||||
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
|
||||
t.Errorf("got %v, want %v", spew.Sdump(actualConfig.Backends), spew.Sdump(c.expectedBackends))
|
||||
t.Errorf("got backend %v, want %v", spew.Sdump(actualConfig.Backends), spew.Sdump(c.expectedBackends))
|
||||
}
|
||||
if !reflect.DeepEqual(actualConfig.Frontends, c.expectedFrontends) {
|
||||
t.Errorf("got %v, want %v", spew.Sdump(actualConfig.Frontends), spew.Sdump(c.expectedFrontends))
|
||||
t.Errorf("got frontend %v, want %v", spew.Sdump(actualConfig.Frontends), spew.Sdump(c.expectedFrontends))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1510,7 +1511,7 @@ func TestGetBackendServer(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, app := range applications {
|
||||
t.Run(fmt.Sprintf("running %s", app.application.ID), func(t *testing.T) {
|
||||
t.Run(app.application.ID, func(t *testing.T) {
|
||||
provider := &Provider{}
|
||||
provider.ForceTaskHostname = app.forceTaskHostname
|
||||
|
||||
|
|
Loading…
Reference in a new issue