Skip to content
Snippets Groups Projects
Commit 7109ae4cebc9 authored by Balasankar 'Balu' C's avatar Balasankar 'Balu' C
Browse files

Merge branch 'fix-consul-cleanup' into 'master'

Fix consul cleanup removes service files

Closes #7717

See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/6791



Merged-by: default avatarBalasankar 'Balu' C <balasankar@gitlab.com>
Approved-by: default avatarBalasankar 'Balu' C <balasankar@gitlab.com>
Co-authored-by: default avatarClemens Beck <cbeck@gitlab.com>
No related branches found
No related tags found
3 merge requests!102heptapod#1237: making 0.38 the new oldstable,!96Merged heptapod branch for upstream 15.11 in heptapod-stable,!93Merged upstream 15.11.0+rc42+ce.0
require 'json'
module WatchHelper
WATCHER_FILENAME_PREFIX = 'watcher_'.freeze
class Watcher
attr_reader :name, :handler_script, :handler_template, :type, :consul_config_file, :template_variables, :service_name
......@@ -9,7 +11,7 @@
@handler_script = handler_script
@handler_template = handler_template
@type = type
@consul_config_file = "#{consul_watch_config_directory}/watcher_#{name}.json"
@consul_config_file = "#{consul_watch_config_directory}/#{WATCHER_FILENAME_PREFIX}#{name}.json"
@service_name = "service:#{name}"
@template_variables = template_variables.merge({ "watcher_service_name" => @service_name })
end
......@@ -73,6 +75,6 @@
@all_watchers.select { |watcher| @enabled_watchers.include? watcher.name }
end
def excess_configs
enabled_configs = watchers.map { |w| File.basename w.consul_config_file }
def excess_watcher_configs
enabled_watcher_configs = watchers.map { |w| File.basename w.consul_config_file }
Dir.glob("#{@consul_config_directory}/*")
......@@ -78,5 +80,6 @@
Dir.glob("#{@consul_config_directory}/*")
.reject { |c| enabled_configs.include? c }
.reject { |f| !File.basename(f).start_with? WATCHER_FILENAME_PREFIX }
.reject { |f| enabled_watcher_configs.include? f }
end
def excess_handler_scripts
......
......@@ -18,7 +18,7 @@
# Remove excess watcher configurations and handlers
to_cleanup = watch_helper.excess_handler_scripts
to_cleanup += watch_helper.excess_configs
to_cleanup += watch_helper.excess_watcher_configs
to_cleanup.each do |f|
file f do
......
......@@ -4,8 +4,9 @@
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab-ee::default') }
let(:watcher_conf) { '/var/opt/gitlab/consul/config.d/watcher_postgresql.json' }
let(:watcher_check) { '/var/opt/gitlab/consul/scripts/failover_postgresql_in_pgbouncer' }
let(:any_service_conf) { '/var/opt/gitlab/consul/config.d/any_service.conf' }
let(:excess_watcher_conf) { '/var/opt/gitlab/consul/config.d/watcher_postgresql_old.json' }
let(:excess_watcher_check) { '/var/opt/gitlab/consul/scripts/failover_postgresql_old_in_pgbouncer' }
def stub_excess_consul_config_files
allow(Dir).to receive(:glob).with(anything).and_call_original
......@@ -7,9 +8,9 @@
let(:excess_watcher_conf) { '/var/opt/gitlab/consul/config.d/watcher_postgresql_old.json' }
let(:excess_watcher_check) { '/var/opt/gitlab/consul/scripts/failover_postgresql_old_in_pgbouncer' }
def stub_excess_consul_config_files
allow(Dir).to receive(:glob).with(anything).and_call_original
allow(Dir).to receive(:glob).with("/var/opt/gitlab/consul/config.d/*").and_return [excess_watcher_conf]
allow(Dir).to receive(:glob).with("/var/opt/gitlab/consul/config.d/*").and_return [excess_watcher_conf, any_service_conf]
allow(Dir).to receive(:glob).with("/var/opt/gitlab/consul/scripts/*").and_return [excess_watcher_check]
end
......@@ -48,6 +49,7 @@
it 'removes config and watch files of removed watchers' do
expect(chef_run).to delete_file(excess_watcher_conf)
expect(chef_run).to delete_file(excess_watcher_check)
expect(chef_run).to_not delete_file(any_service_conf)
end
it 'creates the watcher handler file' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment