Fix rancher host IP address
This commit is contained in:
parent
1a2544610d
commit
0a0cf87625
1 changed files with 22 additions and 3 deletions
|
@ -10,10 +10,14 @@ import (
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
rancher "github.com/rancher/go-rancher/client"
|
rancher "github.com/rancher/go-rancher/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
const labelRancheStackServiceName = "io.rancher.stack_service.name"
|
const (
|
||||||
|
labelRancherStackServiceName = "io.rancher.stack_service.name"
|
||||||
|
hostNetwork = "host"
|
||||||
|
)
|
||||||
|
|
||||||
var withoutPagination *rancher.ListOpts
|
var withoutPagination *rancher.ListOpts
|
||||||
|
|
||||||
|
@ -221,11 +225,26 @@ func parseAPISourcedRancherData(environments []*rancher.Environment, services []
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
if container.Labels[labelRancheStackServiceName] == rancherData.Name &&
|
if container.Labels[labelRancherStackServiceName] == rancherData.Name &&
|
||||||
containerFilter(container.Name, container.HealthState, container.State) {
|
containerFilter(container.Name, container.HealthState, container.State) {
|
||||||
|
|
||||||
|
if container.NetworkMode == hostNetwork {
|
||||||
|
var endpoints []*rancher.PublicEndpoint
|
||||||
|
err := mapstructure.Decode(service.PublicEndpoints, &endpoints)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to decode PublicEndpoint: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(endpoints) > 0 {
|
||||||
|
rancherData.Containers = append(rancherData.Containers, endpoints[0].IpAddress)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
rancherData.Containers = append(rancherData.Containers, container.PrimaryIpAddress)
|
rancherData.Containers = append(rancherData.Containers, container.PrimaryIpAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
rancherDataList = append(rancherDataList, rancherData)
|
rancherDataList = append(rancherDataList, rancherData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue