From 14c231aeb98cb91686c72d5686da354f32aacbf9 Mon Sep 17 00:00:00 2001 From: Danielle Lancashire Date: Thu, 25 Apr 2019 13:48:19 +0200 Subject: [PATCH] consul: Do not deregister external checks This commit causes sync to skip deregistering checks that are not managed by nomad, such as service maintenance mode checks. This is handled in the same way as service registrations - by doing a Nomad specific prefix match. --- command/agent/consul/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/agent/consul/client.go b/command/agent/consul/client.go index ce882ab6c..ff5af7282 100644 --- a/command/agent/consul/client.go +++ b/command/agent/consul/client.go @@ -513,7 +513,7 @@ func (c *ServiceClient) sync() error { // Nomad managed checks if this is not a client agent. // This is to prevent server agents from removing checks // registered by client agents - if !isNomadService(check.ServiceID) || !c.isClientAgent { + if !isNomadService(check.ServiceID) || !c.isClientAgent || !isNomadCheck(check.CheckID) { // Service not managed by Nomad, skip continue } @@ -1182,6 +1182,12 @@ func createCheckReg(serviceID, checkID string, check *structs.ServiceCheck, host return &chkReg, nil } +// isNomadCheck returns true if the ID matches the pattern of a Nomad managed +// check. +func isNomadCheck(id string) bool { + return strings.HasPrefix(id, nomadCheckPrefix) +} + // isNomadService returns true if the ID matches the pattern of a Nomad managed // service (new or old formats). Agent services return false as independent // client and server agents may be running on the same machine. #2827