Commit be4538b5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'feature/gb/update-pending-builds-namespace-traversal-ids' into 'master'

Update pending builds namespace traversal ids when needed

See merge request gitlab-org/gitlab!70691
parents aa29d65f a90a4974
......@@ -105,7 +105,7 @@ module Projects
end
update_pages_config if changing_pages_related_config?
update_pending_builds if shared_runners_toggled?
update_pending_builds if runners_settings_toggled?
end
def after_rename_service(project)
......@@ -181,13 +181,36 @@ module Projects
end
def update_pending_builds
update_params = { instance_runners_enabled: project.shared_runners_enabled }
update_params = {
instance_runners_enabled: project.shared_runners_enabled?,
namespace_traversal_ids: group_runner_traversal_ids
}
::Ci::UpdatePendingBuildService.new(project, update_params).execute
::Ci::UpdatePendingBuildService
.new(project, update_params)
.execute
end
def shared_runners_toggled?
project.previous_changes.include?('shared_runners_enabled')
def shared_runners_settings_toggled?
project.previous_changes.include?(:shared_runners_enabled)
end
def group_runners_settings_toggled?
return false unless project.ci_cd_settings.present?
project.ci_cd_settings.previous_changes.include?(:group_runners_enabled)
end
def runners_settings_toggled?
shared_runners_settings_toggled? || group_runners_settings_toggled?
end
def group_runner_traversal_ids
if project.group_runners_enabled?
project.namespace.traversal_ids
else
[]
end
end
end
end
......
......@@ -441,26 +441,62 @@ RSpec.describe Projects::UpdateService do
end
end
context 'when updating #shared_runners', :https_pages_enabled do
let!(:pending_build) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
context 'when updating runners settings' do
let(:settings) do
{ instance_runners_enabled: true, namespace_traversal_ids: [123] }
end
subject(:call_service) do
update_project(project, admin, shared_runners_enabled: shared_runners_enabled)
let!(:pending_build) do
create(:ci_pending_build, project: project, **settings)
end
context 'when project has shared runners enabled' do
let(:project) { create(:project, shared_runners_enabled: true) }
it 'updates builds queue when shared runners get disabled' do
expect { update_project(project, admin, shared_runners_enabled: false) }
.to change { pending_build.reload.instance_runners_enabled }.to(false)
expect(pending_build.reload.instance_runners_enabled).to be false
end
end
context 'when project has shared runners disabled' do
let(:project) { create(:project, shared_runners_enabled: false) }
it 'updates builds queue when shared runners get enabled' do
expect { update_project(project, admin, shared_runners_enabled: true) }
.to not_change { pending_build.reload.instance_runners_enabled }
expect(pending_build.reload.instance_runners_enabled).to be true
end
end
context 'when shared runners is toggled' do
let(:shared_runners_enabled) { false }
context 'when project has group runners enabled' do
let(:project) { create(:project, group_runners_enabled: true) }
before do
project.ci_cd_settings.update!(group_runners_enabled: true)
end
it 'updates builds queue when group runners get disabled' do
update_project(project, admin, group_runners_enabled: false)
it 'updates ci pending builds' do
expect { call_service }.to change { pending_build.reload.instance_runners_enabled }.to(false)
expect(pending_build.reload.namespace_traversal_ids).to be_empty
end
end
context 'when shared runners is not toggled' do
let(:shared_runners_enabled) { true }
context 'when project has group runners disabled' do
let(:project) { create(:project, :in_subgroup, group_runners_enabled: false) }
before do
project.reload.ci_cd_settings.update!(group_runners_enabled: false)
end
it 'updates builds queue when group runners get enabled' do
update_project(project, admin, group_runners_enabled: true)
it 'updates ci pending builds' do
expect { call_service }.to not_change { pending_build.reload.instance_runners_enabled }
expect(pending_build.reload.namespace_traversal_ids).to include(project.namespace.id)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment