Skip to content

Commit

Permalink
Merge commit '8d904c60949e310893a25c8af3636b0151334dd4'
Browse files Browse the repository at this point in the history
From gliderlabs/pull/596

Conflicts:
	bridge/types.go
	registrator.go
  • Loading branch information
aya committed Jun 3, 2022
2 parents 378a4ea + 8d904c6 commit 5ee8069
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
12 changes: 12 additions & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
}
}

if b.config.UseIpFromNetwork != "" {
containerNetwork, ok := container.NetworkSettings.Networks[b.config.UseIpFromNetwork]
if ok {
service.IP = containerNetwork.IPAddress
log.Printf("using container IP %s from network '%s'",
service.IP, b.config.UseIpFromLabel)
} else {
log.Printf("Network '%s' not found in container configuration.",
b.config.UseIpFromNetwork)
}
}

// NetworkMode can point to another container (kuberenetes pods)
networkMode := container.HostConfig.NetworkMode
if networkMode != "" {
Expand Down
21 changes: 11 additions & 10 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ type RegistryAdapter interface {
}

type Config struct {
HostIp string
Internal bool
Explicit bool
UseIpFromLabel string
ForceTags string
RefreshTtl int
RefreshInterval int
DeregisterCheck string
Cleanup bool
CleanupDyingTtl int
HostIp string
Internal bool
Explicit bool
UseIpFromLabel string
UseIpFromNetwork string
ForceTags string
RefreshTtl int
RefreshInterval int
DeregisterCheck string
Cleanup bool
CleanupDyingTtl int
}

type Service struct {
Expand Down
22 changes: 12 additions & 10 deletions registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored in a label assigned to the container")
var useIpFromNetwork = flag.String("useIpFromNetwork", "", "Use IP that is assigned on to a containers network")
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)")
var forceTags = flag.String("tags", "", "Append tags for all registered services")
Expand Down Expand Up @@ -105,16 +106,17 @@ func main() {
}

b, err := bridge.New(docker, flag.Arg(0), bridge.Config{
HostIp: *hostIp,
Internal: *internal,
Explicit: *explicit,
UseIpFromLabel: *useIpFromLabel,
ForceTags: *forceTags,
RefreshTtl: *refreshTtl,
RefreshInterval: *refreshInterval,
DeregisterCheck: *deregister,
Cleanup: *cleanup,
CleanupDyingTtl: *cleanupDyingTtl,
HostIp: *hostIp,
Internal: *internal,
Explicit: *explicit,
UseIpFromLabel: *useIpFromLabel,
UseIpFromNetwork: *useIpFromNetwork,
ForceTags: *forceTags,
RefreshTtl: *refreshTtl,
RefreshInterval: *refreshInterval,
DeregisterCheck: *deregister,
Cleanup: *cleanup,
CleanupDyingTtl: *cleanupDyingTtl,
})

assert(err)
Expand Down

0 comments on commit 5ee8069

Please sign in to comment.