Cosmetic changes.

This commit is contained in:
Timo Reimann 2017-04-21 16:06:14 +02:00
parent e615e833bc
commit 16c86022bb
2 changed files with 15 additions and 11 deletions

View file

@ -42,7 +42,7 @@ type Provider struct {
TLS *provider.ClientTLS `description:"Enable Docker TLS support"` TLS *provider.ClientTLS `description:"Enable Docker TLS support"`
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon"` 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"` 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 Basic *Basic
marathonClient marathon.Marathon 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) log.Errorf("Unable to get marathon application from task %s", task.AppID)
return "" return ""
} }
numTaskIPAddresses := len(task.IPAddresses)
switch { switch {
case application.IPAddressPerTask == nil || p.ForceTaskHostname: case application.IPAddressPerTask == nil || p.ForceTaskHostname:
return task.Host return task.Host
case len(task.IPAddresses) == 0: case numTaskIPAddresses == 0:
log.Errorf("Missing marathon IPAddress from task %s", task.AppID) log.Errorf("Missing IP address for Marathon application %s on task %s", application.ID, task.ID)
return "" return ""
case len(task.IPAddresses) == 1: case numTaskIPAddresses == 1:
return task.IPAddresses[0].IPAddress return task.IPAddresses[0].IPAddress
default: default:
ipAddressIdxStr, ok := p.getLabel(application, "traefik.ipAddressIdx") ipAddressIdxStr, ok := p.getLabel(application, "traefik.ipAddressIdx")
if !ok { 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 "" return ""
} }
ipAddressIdx, err := strconv.Atoi(ipAddressIdxStr) ipAddressIdx, err := strconv.Atoi(ipAddressIdxStr)
if err != nil { 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 ""
} }
return task.IPAddresses[ipAddressIdx].IPAddress return task.IPAddresses[ipAddressIdx].IPAddress
} }
} }

View file

@ -344,7 +344,8 @@ func TestMarathonLoadConfig(t *testing.T) {
if len(c.applications.Apps) > 0 { if len(c.applications.Apps) > 0 {
appID = c.applications.Apps[0].ID 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) fakeClient := newFakeClient(c.applicationsError, c.applications, c.tasksError, c.tasks)
provider := &Provider{ provider := &Provider{
Domain: "docker.localhost", Domain: "docker.localhost",
@ -355,15 +356,15 @@ func TestMarathonLoadConfig(t *testing.T) {
fakeClient.AssertExpectations(t) fakeClient.AssertExpectations(t)
if c.expectedNil { if c.expectedNil {
if actualConfig != nil { if actualConfig != nil {
t.Fatalf("Should have been nil, got %v", actualConfig) t.Fatalf("configuration should have been nil, got %v", actualConfig)
} }
} else { } else {
// Compare backends // Compare backends
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) { 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) { 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 { 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 := &Provider{}
provider.ForceTaskHostname = app.forceTaskHostname provider.ForceTaskHostname = app.forceTaskHostname