mirror of https://github.com/status-im/consul.git
Do not modify config after creation
Make sure the RPCAdvertise address is always set so that the configuration does not have to be modified after creation.
This commit is contained in:
parent
a226edd4a9
commit
a235986a28
|
@ -437,6 +437,11 @@ func (a *Agent) consulConfig() *consul.Config {
|
|||
base.AutopilotConfig.DisableUpgradeMigration = *a.config.Autopilot.DisableUpgradeMigration
|
||||
}
|
||||
|
||||
// make sure the advertise address is always set
|
||||
if base.RPCAdvertise == nil {
|
||||
base.RPCAdvertise = base.RPCAddr
|
||||
}
|
||||
|
||||
// Format the build string
|
||||
revision := a.config.Revision
|
||||
if len(revision) > 8 {
|
||||
|
|
|
@ -598,34 +598,22 @@ func (s *Server) setupRPC(tlsWrap tlsutil.DCWrapper) error {
|
|||
s.rpcServer.Register(s.endpoints.Status)
|
||||
s.rpcServer.Register(s.endpoints.Txn)
|
||||
|
||||
list, err := net.ListenTCP("tcp", s.config.RPCAddr)
|
||||
ln, err := net.ListenTCP("tcp", s.config.RPCAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.rpcListener = list
|
||||
|
||||
var advertise net.Addr
|
||||
if s.config.RPCAdvertise != nil {
|
||||
advertise = s.config.RPCAdvertise
|
||||
} else {
|
||||
advertise = s.rpcListener.Addr()
|
||||
}
|
||||
s.rpcListener = ln
|
||||
|
||||
// Verify that we have a usable advertise address
|
||||
addr, ok := advertise.(*net.TCPAddr)
|
||||
if !ok {
|
||||
list.Close()
|
||||
return fmt.Errorf("RPC advertise address is not a TCP Address: %v", addr)
|
||||
}
|
||||
if addr.IP.IsUnspecified() {
|
||||
list.Close()
|
||||
return fmt.Errorf("RPC advertise address is not advertisable: %v", addr)
|
||||
if s.config.RPCAdvertise.IP.IsUnspecified() {
|
||||
ln.Close()
|
||||
return fmt.Errorf("RPC advertise address is not advertisable: %v", s.config.RPCAdvertise)
|
||||
}
|
||||
|
||||
// Provide a DC specific wrapper. Raft replication is only
|
||||
// ever done in the same datacenter, so we can provide it as a constant.
|
||||
wrapper := tlsutil.SpecificDC(s.config.Datacenter, tlsWrap)
|
||||
s.raftLayer = NewRaftLayer(advertise, wrapper)
|
||||
s.raftLayer = NewRaftLayer(s.config.RPCAdvertise, wrapper)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue