mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
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
|
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
|
// Format the build string
|
||||||
revision := a.config.Revision
|
revision := a.config.Revision
|
||||||
if len(revision) > 8 {
|
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.Status)
|
||||||
s.rpcServer.Register(s.endpoints.Txn)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.rpcListener = list
|
s.rpcListener = ln
|
||||||
|
|
||||||
var advertise net.Addr
|
|
||||||
if s.config.RPCAdvertise != nil {
|
|
||||||
advertise = s.config.RPCAdvertise
|
|
||||||
} else {
|
|
||||||
advertise = s.rpcListener.Addr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that we have a usable advertise address
|
// Verify that we have a usable advertise address
|
||||||
addr, ok := advertise.(*net.TCPAddr)
|
if s.config.RPCAdvertise.IP.IsUnspecified() {
|
||||||
if !ok {
|
ln.Close()
|
||||||
list.Close()
|
return fmt.Errorf("RPC advertise address is not advertisable: %v", s.config.RPCAdvertise)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide a DC specific wrapper. Raft replication is only
|
// Provide a DC specific wrapper. Raft replication is only
|
||||||
// ever done in the same datacenter, so we can provide it as a constant.
|
// ever done in the same datacenter, so we can provide it as a constant.
|
||||||
wrapper := tlsutil.SpecificDC(s.config.Datacenter, tlsWrap)
|
wrapper := tlsutil.SpecificDC(s.config.Datacenter, tlsWrap)
|
||||||
s.raftLayer = NewRaftLayer(advertise, wrapper)
|
s.raftLayer = NewRaftLayer(s.config.RPCAdvertise, wrapper)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user