Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag is added to prevent publishing ip of the node, otherwise, traefi… #703

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,21 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
}
}


// NetworkMode can point to another container (kuberenetes pods)
networkMode := container.HostConfig.NetworkMode
if networkMode != "" {
if strings.HasPrefix(networkMode, "container:") {
networkContainerId := strings.Split(networkMode, ":")[1]
log.Println(service.Name + ": detected container NetworkMode, linked to: " + networkContainerId[:12])
networkContainer, err := b.docker.InspectContainer(networkContainerId)
if err != nil {
log.Println("unable to inspect network container:", networkContainerId[:12], err)
} else {
service.IP = networkContainer.NetworkSettings.IPAddress
log.Println(service.Name + ": using network container IP " + service.IP)
if b.config.UseIpFromContainer == "" {
networkMode := container.HostConfig.NetworkMode
if networkMode != "" {
if strings.HasPrefix(networkMode, "container:") {
networkContainerId := strings.Split(networkMode, ":")[1]
log.Println(service.Name + ": detected container NetworkMode, linked to: " + networkContainerId[:12])
networkContainer, err := b.docker.InspectContainer(networkContainerId)
if err != nil {
log.Println("unable to inspect network container:", networkContainerId[:12], err)
} else {
service.IP = networkContainer.NetworkSettings.IPAddress
log.Println(service.Name + ": using network container IP " + service.IP)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
HostIp string
Internal bool
Explicit bool
UseIpFromContainer string
UseIpFromLabel string
ForceTags string
RefreshTtl int
Expand Down
2 changes: 2 additions & 0 deletions registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var versionChecker = usage.NewChecker("registrator", Version)
var hostIp = flag.String("ip", "", "IP for ports mapped to the host")
var internal = flag.Bool("internal", false, "Use internal ports instead of published ones")
var explicit = flag.Bool("explicit", false, "Only register containers which have SERVICE_NAME label set")
var useIpFromContainer = flag.String("ip-from-container", "", "Use IP of the container instead of node")
var useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored in a label assigned to the container")
var refreshInterval = flag.Int("ttl-refresh", 0, "Frequency with which service TTLs are refreshed")
var refreshTtl = flag.Int("ttl", 0, "TTL for services (default is no expiry)")
Expand Down Expand Up @@ -106,6 +107,7 @@ func main() {
HostIp: *hostIp,
Internal: *internal,
Explicit: *explicit,
UseIpFromContainer: *useIpFromContainer,
UseIpFromLabel: *useIpFromLabel,
ForceTags: *forceTags,
RefreshTtl: *refreshTtl,
Expand Down