mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Fix unnecessary deregistration in consul sync
This commit fixes an issue where if a nomad client and server shared the same consul instance, the server would deregister any services and checks registered by clients for running tasks.
This commit is contained in:
@@ -232,6 +232,10 @@ type ServiceClient struct {
|
|||||||
|
|
||||||
// checkWatcher restarts checks that are unhealthy.
|
// checkWatcher restarts checks that are unhealthy.
|
||||||
checkWatcher *checkWatcher
|
checkWatcher *checkWatcher
|
||||||
|
|
||||||
|
// agentRoleLock guards state about whether this agent is a client
|
||||||
|
agentRoleLock sync.Mutex
|
||||||
|
isClientAgent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServiceClient creates a new Consul ServiceClient from an existing Consul API
|
// NewServiceClient creates a new Consul ServiceClient from an existing Consul API
|
||||||
@@ -433,7 +437,7 @@ func (c *ServiceClient) sync() error {
|
|||||||
// Known service, skip
|
// Known service, skip
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !isNomadService(id) {
|
if !isNomadService(id) || !c.IsClient() {
|
||||||
// Not managed by Nomad, skip
|
// Not managed by Nomad, skip
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -470,7 +474,7 @@ func (c *ServiceClient) sync() error {
|
|||||||
// Known check, leave it
|
// Known check, leave it
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !isNomadService(check.ServiceID) {
|
if !isNomadService(check.ServiceID) || !c.IsClient() {
|
||||||
// Service not managed by Nomad, skip
|
// Service not managed by Nomad, skip
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -519,6 +523,12 @@ func (c *ServiceClient) sync() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ServiceClient) IsClient() bool {
|
||||||
|
c.agentRoleLock.Lock()
|
||||||
|
defer c.agentRoleLock.Unlock()
|
||||||
|
return c.isClientAgent
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterAgent registers Nomad agents (client or server). The
|
// RegisterAgent registers Nomad agents (client or server). The
|
||||||
// Service.PortLabel should be a literal port to be parsed with SplitHostPort.
|
// Service.PortLabel should be a literal port to be parsed with SplitHostPort.
|
||||||
// Script checks are not supported and will return an error. Registration is
|
// Script checks are not supported and will return an error. Registration is
|
||||||
@@ -528,6 +538,12 @@ func (c *ServiceClient) sync() error {
|
|||||||
func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error {
|
func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error {
|
||||||
ops := operations{}
|
ops := operations{}
|
||||||
|
|
||||||
|
if role == "client" {
|
||||||
|
c.agentRoleLock.Lock()
|
||||||
|
c.isClientAgent = true
|
||||||
|
c.agentRoleLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
id := makeAgentServiceID(role, service)
|
id := makeAgentServiceID(role, service)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user