From 7bdc0aee7c9830038b8917f95caf36716be5bda2 Mon Sep 17 00:00:00 2001 From: Baptiste Courtois Date: Tue, 4 Jun 2024 16:38:46 +0200 Subject: [PATCH] Pass the user specified token to consul maintenance primitive Otherwise we use the "globally configured" token, that may change at any point in the chef run (because of diplomat model). Let's specify the token when requested. i.e. all checks calls. If an incorrect token is used, it may lacks permission to detect the node/service maintenance. Change-Id: I00b6a512e487151931d9b811eaead162b4ddde57 --- libraries/primitive_consul_maintenance.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/primitive_consul_maintenance.rb b/libraries/primitive_consul_maintenance.rb index 58ef559..45d072e 100644 --- a/libraries/primitive_consul_maintenance.rb +++ b/libraries/primitive_consul_maintenance.rb @@ -28,7 +28,7 @@ def maintenance? # we observed in very rare cases that maintenance status could be not up to date # for ~5s after a restart results = 3.times.map do - checks = Diplomat::Agent.checks + checks = Diplomat::Agent.checks(token: @options[:consul_token]) maint_status = checks.dig(@maintenance_key, 'Status') sleep(@options[:check_interval]) maint_status == 'critical' && !checks.dig(@maintenance_key, 'Notes').nil? @@ -40,7 +40,7 @@ def maintenance? # @return [String, nil] reason of the maintenance, if any. Nil otherwise def maintenance_reason - checks = Diplomat::Agent.checks + checks = Diplomat::Agent.checks(token: @options[:consul_token]) checks.dig(@maintenance_key, 'Notes') end