Skip to content

Commit 23db6e1

Browse files
balasankarcAndrew Pattersontwk3
committed
Merge branch '8117-no-restart-for-stopped-service' into 'master'
Do not restart gitlab-kas service if stopped Closes #8117 See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7144 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Approved-by: João Alexandre Cunha <[email protected]> Co-authored-by: Andrew Patterson <[email protected]> Co-authored-by: DJ Mountney <[email protected]>
2 parents 856093b + ad5761e commit 23db6e1

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

files/gitlab-cookbooks/gitlab-kas/recipes/enable.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,31 @@
7979
version_file 'Create version file for Gitlab KAS' do
8080
version_file_path File.join(working_dir, 'VERSION')
8181
version_check_cmd '/opt/gitlab/embedded/bin/gitlab-kas --version'
82-
notifies :restart, 'runit_service[gitlab-kas]'
82+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
8383
end
8484

8585
file gitlab_kas_authentication_secret_file do
8686
content node['gitlab_kas']['api_secret_key']
8787
owner 'root'
8888
group account_helper.gitlab_group
8989
mode '0640'
90-
notifies :restart, 'runit_service[gitlab-kas]'
90+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
9191
end
9292

9393
file gitlab_kas_private_api_authentication_secret_file do
9494
content node['gitlab_kas']['private_api_secret_key']
9595
owner 'root'
9696
group account_helper.gitlab_group
9797
mode '0640'
98-
notifies :restart, 'runit_service[gitlab-kas]'
98+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
9999
end
100100

101101
file gitlab_kas_redis_password_file do
102102
content redis_password
103103
owner 'root'
104104
group account_helper.gitlab_group
105105
mode '0640'
106-
notifies :restart, 'runit_service[gitlab-kas]'
106+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
107107
only_if { redis_password_present }
108108
sensitive true
109109
end
@@ -113,7 +113,7 @@
113113
owner 'root'
114114
group account_helper.gitlab_group
115115
mode '0640'
116-
notifies :restart, 'runit_service[gitlab-kas]'
116+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
117117
only_if { redis_sentinels_password_present }
118118
sensitive true
119119
end
@@ -137,7 +137,7 @@
137137
redis_sentinels_password_file: redis_sentinels_password_present ? gitlab_kas_redis_sentinels_password_file : nil
138138
)
139139
)
140-
notifies :restart, 'runit_service[gitlab-kas]'
140+
notifies :restart, 'runit_service[gitlab-kas]' if omnibus_helper.should_notify?('gitlab-kas')
141141
end
142142

143143
env_dir env_directory do

spec/chef/cookbooks/gitlab-kas/recipes/gitlab-kas_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
end
2525

2626
it 'creates a default VERSION file and restarts service' do
27+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).and_call_original
28+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).with('gitlab-kas').and_return(true)
2729
expect(chef_run).to create_version_file('Create version file for Gitlab KAS').with(
2830
version_file_path: '/var/opt/gitlab/gitlab-kas/VERSION',
2931
version_check_cmd: '/opt/gitlab/embedded/bin/gitlab-kas --version'
@@ -32,6 +34,17 @@
3234
expect(chef_run.version_file('Create version file for Gitlab KAS')).to notify('runit_service[gitlab-kas]').to(:restart)
3335
end
3436

37+
it 'creates a default VERSION file and does not restart the service if stopped' do
38+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).and_call_original
39+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).with('gitlab-kas').and_return(false)
40+
expect(chef_run).to create_version_file('Create version file for Gitlab KAS').with(
41+
version_file_path: '/var/opt/gitlab/gitlab-kas/VERSION',
42+
version_check_cmd: '/opt/gitlab/embedded/bin/gitlab-kas --version'
43+
)
44+
45+
expect(chef_run.version_file('Create version file for Gitlab KAS')).to_not notify('runit_service[gitlab-kas]').to(:restart)
46+
end
47+
3548
it 'correctly renders the KAS service run file' do
3649
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-kas/run").with_content(%r{--configuration-file /var/opt/gitlab/gitlab-kas/gitlab-kas-config.yml})
3750
end
@@ -636,6 +649,45 @@
636649
end
637650
end
638651

652+
describe 'chef_run.file calls' do
653+
def files
654+
@files ||= %w(
655+
/var/opt/gitlab/gitlab-kas/authentication_secret_file
656+
/var/opt/gitlab/gitlab-kas/private_api_authentication_secret_file
657+
/var/opt/gitlab/gitlab-kas/redis_password_file
658+
/var/opt/gitlab/gitlab-kas/redis_sentinels_password_file
659+
)
660+
end
661+
662+
before do
663+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).and_call_original
664+
end
665+
666+
context "when omnibus_helper.should_notify?('gitlab-kas') returns true" do
667+
before do
668+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).with('gitlab-kas').and_return(true)
669+
end
670+
671+
it 'chef_run.file calls notify gitlab-kas to restart' do
672+
files.each do |file|
673+
expect(chef_run.file(file)).to notify('runit_service[gitlab-kas]').to(:restart)
674+
end
675+
end
676+
end
677+
678+
context "when omnibus_helper.should_notify?('gitlab-kas') returns false" do
679+
before do
680+
allow_any_instance_of(OmnibusHelper).to receive(:should_notify?).with('gitlab-kas').and_return(false)
681+
end
682+
683+
it 'chef_run.file calls do not notify gitlab-kas to restart' do
684+
files.each do |file|
685+
expect(chef_run.file(file)).to_not notify('runit_service[gitlab-kas]').to(:restart)
686+
end
687+
end
688+
end
689+
end
690+
639691
def chef_run_load_yaml_template(chef_run, path)
640692
template = chef_run.template(path)
641693
file_content = ChefSpec::Renderer.new(chef_run, template).content

0 commit comments

Comments
 (0)