Merge pull request #782 from guilhem/defaultToIndex1
Use first port by default
This commit is contained in:
commit
0c1e06199c
6 changed files with 40 additions and 30 deletions
|
@ -364,10 +364,6 @@ func (provider *Docker) containerFilter(container dockerData) bool {
|
||||||
log.Debugf("Filtering container without port and no traefik.port label %s", container.Name)
|
log.Debugf("Filtering container without port and no traefik.port label %s", container.Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(container.NetworkSettings.Ports) > 1 && err != nil {
|
|
||||||
log.Debugf("Filtering container with more than 1 port and no traefik.port label %s", container.Name)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isContainerEnabled(container, provider.ExposedByDefault) {
|
if !isContainerEnabled(container, provider.ExposedByDefault) {
|
||||||
log.Debugf("Filtering disabled container %s", container.Name)
|
log.Debugf("Filtering disabled container %s", container.Name)
|
||||||
|
|
|
@ -390,6 +390,27 @@ func TestDockerGetPort(t *testing.T) {
|
||||||
},
|
},
|
||||||
expected: "8080",
|
expected: "8080",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
container: docker.ContainerJSON{
|
||||||
|
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||||
|
Name: "test-multi-ports",
|
||||||
|
},
|
||||||
|
Config: &container.Config{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"traefik.port": "8080",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NetworkSettings: &docker.NetworkSettings{
|
||||||
|
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||||
|
Ports: nat.PortMap{
|
||||||
|
"8080/tcp": {},
|
||||||
|
"80/tcp": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: "8080",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range containers {
|
for _, e := range containers {
|
||||||
|
@ -735,7 +756,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
||||||
{
|
{
|
||||||
container: docker.ContainerJSON{
|
container: docker.ContainerJSON{
|
||||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||||
Name: "container",
|
Name: "container-multi-ports",
|
||||||
},
|
},
|
||||||
Config: &container.Config{},
|
Config: &container.Config{},
|
||||||
NetworkSettings: &docker.NetworkSettings{
|
NetworkSettings: &docker.NetworkSettings{
|
||||||
|
@ -748,7 +769,7 @@ func TestDockerTraefikFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
exposedByDefault: true,
|
exposedByDefault: true,
|
||||||
expected: false,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
container: docker.ContainerJSON{
|
container: docker.ContainerJSON{
|
||||||
|
|
|
@ -219,10 +219,7 @@ func (provider *Marathon) taskFilter(task marathon.Task, applications *marathon.
|
||||||
log.Debugf("Filtering marathon task %s specifying both traefik.portIndex and traefik.port labels", task.AppID)
|
log.Debugf("Filtering marathon task %s specifying both traefik.portIndex and traefik.port labels", task.AppID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if portIndexLabel == "" && portValueLabel == "" && len(application.Ports) > 1 {
|
|
||||||
log.Debugf("Filtering marathon task %s with more than 1 port and no traefik.portIndex or traefik.port label", task.AppID)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if portIndexLabel != "" {
|
if portIndexLabel != "" {
|
||||||
index, err := strconv.Atoi((*application.Labels)["traefik.portIndex"])
|
index, err := strconv.Atoi((*application.Labels)["traefik.portIndex"])
|
||||||
if err != nil || index < 0 || index > len(application.Ports)-1 {
|
if err != nil || index < 0 || index > len(application.Ports)-1 {
|
||||||
|
|
|
@ -371,30 +371,30 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "foo",
|
AppID: "multiple-ports",
|
||||||
Ports: []int{80},
|
Ports: []int{80, 443},
|
||||||
},
|
},
|
||||||
applications: &marathon.Applications{
|
applications: &marathon.Applications{
|
||||||
Apps: []marathon.Application{
|
Apps: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "foo",
|
ID: "multiple-ports",
|
||||||
Ports: []int{80, 443},
|
Ports: []int{80, 443},
|
||||||
Labels: &map[string]string{},
|
Labels: &map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: false,
|
expected: true,
|
||||||
exposedByDefault: true,
|
exposedByDefault: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "foo",
|
AppID: "disable",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
},
|
},
|
||||||
applications: &marathon.Applications{
|
applications: &marathon.Applications{
|
||||||
Apps: []marathon.Application{
|
Apps: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "foo",
|
ID: "disable",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
Labels: &map[string]string{
|
Labels: &map[string]string{
|
||||||
"traefik.enable": "false",
|
"traefik.enable": "false",
|
||||||
|
@ -523,7 +523,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "foo",
|
AppID: "healthcheck-false",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
HealthCheckResults: []*marathon.HealthCheckResult{
|
HealthCheckResults: []*marathon.HealthCheckResult{
|
||||||
{
|
{
|
||||||
|
@ -534,7 +534,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
applications: &marathon.Applications{
|
applications: &marathon.Applications{
|
||||||
Apps: []marathon.Application{
|
Apps: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "foo",
|
ID: "healthcheck-false",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
Labels: &map[string]string{},
|
Labels: &map[string]string{},
|
||||||
HealthChecks: &[]marathon.HealthCheck{
|
HealthChecks: &[]marathon.HealthCheck{
|
||||||
|
@ -576,13 +576,13 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "foo",
|
AppID: "single-port",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
},
|
},
|
||||||
applications: &marathon.Applications{
|
applications: &marathon.Applications{
|
||||||
Apps: []marathon.Application{
|
Apps: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "foo",
|
ID: "single-port",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
Labels: &map[string]string{},
|
Labels: &map[string]string{},
|
||||||
},
|
},
|
||||||
|
@ -593,7 +593,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "foo",
|
AppID: "healthcheck-alive",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
HealthCheckResults: []*marathon.HealthCheckResult{
|
HealthCheckResults: []*marathon.HealthCheckResult{
|
||||||
{
|
{
|
||||||
|
@ -604,7 +604,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
applications: &marathon.Applications{
|
applications: &marathon.Applications{
|
||||||
Apps: []marathon.Application{
|
Apps: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "foo",
|
ID: "healthcheck-alive",
|
||||||
Ports: []int{80},
|
Ports: []int{80},
|
||||||
Labels: &map[string]string{},
|
Labels: &map[string]string{},
|
||||||
HealthChecks: &[]marathon.HealthCheck{
|
HealthChecks: &[]marathon.HealthCheck{
|
||||||
|
@ -677,7 +677,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
actual := provider.taskFilter(c.task, c.applications, c.exposedByDefault)
|
actual := provider.taskFilter(c.task, c.applications, c.exposedByDefault)
|
||||||
if actual != c.expected {
|
if actual != c.expected {
|
||||||
t.Fatalf("expected %v, got %v", c.expected, actual)
|
t.Fatalf("App %s: expected %v, got %v", c.task.AppID, c.expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -927,12 +927,12 @@ func TestMarathonGetPort(t *testing.T) {
|
||||||
{
|
{
|
||||||
applications: []marathon.Application{
|
applications: []marathon.Application{
|
||||||
{
|
{
|
||||||
ID: "test1",
|
ID: "multiple-ports-take-first",
|
||||||
Labels: &map[string]string{},
|
Labels: &map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
task: marathon.Task{
|
task: marathon.Task{
|
||||||
AppID: "test1",
|
AppID: "multiple-ports-take-first",
|
||||||
Ports: []int{80, 443},
|
Ports: []int{80, 443},
|
||||||
},
|
},
|
||||||
expected: "80",
|
expected: "80",
|
||||||
|
|
|
@ -212,10 +212,6 @@ func mesosTaskFilter(task state.Task, exposedByDefaultFlag bool) bool {
|
||||||
log.Debugf("Filtering mesos task %s specifying both traefik.portIndex and traefik.port labels", task.Name)
|
log.Debugf("Filtering mesos task %s specifying both traefik.portIndex and traefik.port labels", task.Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if portIndexLabel == "" && portValueLabel == "" && len(task.DiscoveryInfo.Ports.DiscoveryPorts) > 1 {
|
|
||||||
log.Debugf("Filtering mesos task %s with more than 1 port and no traefik.portIndex or traefik.port label", task.Name)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if portIndexLabel != "" {
|
if portIndexLabel != "" {
|
||||||
index, err := strconv.Atoi(labels(task, "traefik.portIndex"))
|
index, err := strconv.Atoi(labels(task, "traefik.portIndex"))
|
||||||
if err != nil || index < 0 || index > len(task.DiscoveryInfo.Ports.DiscoveryPorts)-1 {
|
if err != nil || index < 0 || index > len(task.DiscoveryInfo.Ports.DiscoveryPorts)-1 {
|
||||||
|
|
|
@ -95,7 +95,7 @@ func TestMesosTaskFilter(t *testing.T) {
|
||||||
setLabels("traefik.enable", "true"),
|
setLabels("traefik.enable", "true"),
|
||||||
discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")),
|
discovery(setDiscoveryPorts("TCP", 80, "WEB HTTP", "TCP", 443, "WEB HTTPS")),
|
||||||
),
|
),
|
||||||
expected: false, // more than 1 discovery port but no traefik.port* label
|
expected: true, // Default to first index
|
||||||
exposedByDefault: true,
|
exposedByDefault: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue