From b60f115ba90356434314f5cd9d2c740489ee91f3 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 29 Nov 2021 11:00:50 -0500 Subject: [PATCH] client: respect `client_auto_join` after connection loss The `consul.client_auto_join` configuration block tells the Nomad client whether to use Consul service discovery to find Nomad servers. By default it is set to `true`, but contrary to the documentation it was only respected during the initial client registration. If a client missed a heartbeat, failed a `Node.UpdateStatus` RPC, or if there was no Nomad leader, the client would fallback to Consul even if `client_auto_join` was set to `false`. This changeset returns early from the client's trigger for Consul discovery if the `client_auto_join` field is set to `false`. --- client/client.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 5bc142406cf8..8b6d0ad75e2a 100644 --- a/client/client.go +++ b/client/client.go @@ -2690,11 +2690,13 @@ func taskIsPresent(taskName string, tasks []*structs.Task) bool { // triggerDiscovery causes a Consul discovery to begin (if one hasn't already) func (c *Client) triggerDiscovery() { - select { - case c.triggerDiscoveryCh <- struct{}{}: - // Discovery goroutine was released to execute - default: - // Discovery goroutine was already running + if c.configCopy.ConsulConfig.ClientAutoJoin != nil && *c.configCopy.ConsulConfig.ClientAutoJoin { + select { + case c.triggerDiscoveryCh <- struct{}{}: + // Discovery goroutine was released to execute + default: + // Discovery goroutine was already running + } } }