Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Commit

Permalink
Support obtaining the IP from a container sharing its network namespa…
Browse files Browse the repository at this point in the history
…ce, such as with Kubernetes pods (gliderlabs#507)
  • Loading branch information
balexx authored and mattatcha committed Dec 15, 2016
1 parent 990e6d0 commit d2c9de8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ 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 port.PortType == "udp" {
service.Tags = combineTags(
mapDefault(metadata, "tags", ""), b.config.ForceTags, "udp")
Expand Down

0 comments on commit d2c9de8

Please sign in to comment.