mirror of https://github.com/status-im/consul.git
Improve idempotence check for consul service registration
This commit is contained in:
parent
0507568a37
commit
27320017b9
|
@ -123,6 +123,7 @@ func (s *Server) handleAliveMember(member serf.Member) error {
|
||||||
var service *structs.NodeService
|
var service *structs.NodeService
|
||||||
if valid, _, port := isConsulServer(member); valid {
|
if valid, _, port := isConsulServer(member); valid {
|
||||||
service = &structs.NodeService{
|
service = &structs.NodeService{
|
||||||
|
ID: "consul",
|
||||||
Service: "consul",
|
Service: "consul",
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,21 @@ func (s *Server) handleAliveMember(member serf.Member) error {
|
||||||
|
|
||||||
// Check if the node exists
|
// Check if the node exists
|
||||||
found, addr := state.GetNode(member.Name)
|
found, addr := state.GetNode(member.Name)
|
||||||
if found && addr == member.Addr.String() && service == nil {
|
if found && addr == member.Addr.String() {
|
||||||
|
// Check if the associated service is available
|
||||||
|
if service != nil {
|
||||||
|
match := false
|
||||||
|
services := state.NodeServices(member.Name)
|
||||||
|
for id, _ := range services.Services {
|
||||||
|
if id == service.ID {
|
||||||
|
match = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !match {
|
||||||
|
goto AFTER_CHECK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the serfCheck is in the passing state
|
// Check if the serfCheck is in the passing state
|
||||||
checks := state.NodeChecks(member.Name)
|
checks := state.NodeChecks(member.Name)
|
||||||
for _, check := range checks {
|
for _, check := range checks {
|
||||||
|
@ -139,6 +154,7 @@ func (s *Server) handleAliveMember(member serf.Member) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AFTER_CHECK:
|
||||||
s.logger.Printf("[INFO] consul: member '%s' joined, marking health alive", member.Name)
|
s.logger.Printf("[INFO] consul: member '%s' joined, marking health alive", member.Name)
|
||||||
|
|
||||||
// Register with the catalog
|
// Register with the catalog
|
||||||
|
|
Loading…
Reference in New Issue