fix: separate the gossip listen address from the advertised one (#8)
KNOX_PEER_ADDR doubled as the bind address, so a container tried to bind the host's overlay IP and the gossip server never started. KNOX_LISTEN_ADDR now controls the bind (defaulting to KNOX_PEER_ADDR for compatibility) and the advertised address stays what peers dial.
This commit is contained in:
@@ -416,14 +416,29 @@ func isLoopbackAddr(addr string) bool {
|
||||
return host == "localhost"
|
||||
}
|
||||
|
||||
// ListenAddr returns the advertised HTTP address (KNOX_PEER_ADDR or default).
|
||||
// ListenAddr is the address the gossip server binds. It is separate from the
|
||||
// advertised address because a container cannot bind the host's public or
|
||||
// overlay IP: inside the netns it listens on all interfaces while advertising
|
||||
// something peers can dial (KNOX_PEER_ADDR).
|
||||
func ListenAddr() (addr string) {
|
||||
if addr = os.Getenv("KNOX_LISTEN_ADDR"); addr != "" {
|
||||
return addr
|
||||
}
|
||||
if addr = os.Getenv("KNOX_PEER_ADDR"); addr != "" {
|
||||
return addr
|
||||
}
|
||||
return "localhost:" + defaultPort
|
||||
}
|
||||
|
||||
// AdvertiseAddr is the base URL this node publishes to peers (/v1/ping), which
|
||||
// is what they store and dial. Falls back to the listen address.
|
||||
func AdvertiseAddr() string {
|
||||
if addr := os.Getenv("KNOX_PEER_ADDR"); addr != "" {
|
||||
return addr
|
||||
}
|
||||
return ListenAddr()
|
||||
}
|
||||
|
||||
const defaultMetricsPort = "8932"
|
||||
|
||||
// MetricsAddr returns the Prometheus scrape address (KNOX_METRICS_ADDR or
|
||||
|
||||
Reference in New Issue
Block a user