Commit b14c20b3 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '339186-fj-use-runner-linear-scopes' into 'master'

Replace Ci::Runner with linear scopes

See merge request gitlab-org/gitlab!70385
parents 4a71cb34 af61def7
...@@ -84,7 +84,11 @@ module Ci ...@@ -84,7 +84,11 @@ module Ci
groups = ::Group.where(id: group_id) groups = ::Group.where(id: group_id)
if include_ancestors if include_ancestors
groups = Gitlab::ObjectHierarchy.new(groups).base_and_ancestors groups = if Feature.enabled?(:linear_runner_ancestor_scopes, default_enabled: :yaml)
groups.self_and_ancestors
else
Gitlab::ObjectHierarchy.new(groups).base_and_ancestors
end
end end
joins(:runner_namespaces) joins(:runner_namespaces)
...@@ -106,7 +110,11 @@ module Ci ...@@ -106,7 +110,11 @@ module Ci
scope :belonging_to_parent_group_of_project, -> (project_id) { scope :belonging_to_parent_group_of_project, -> (project_id) {
project_groups = ::Group.joins(:projects).where(projects: { id: project_id }) project_groups = ::Group.joins(:projects).where(projects: { id: project_id })
hierarchy_groups = Gitlab::ObjectHierarchy.new(project_groups).base_and_ancestors hierarchy_groups = if Feature.enabled?(:linear_runner_ancestor_scopes, default_enabled: :yaml)
project_groups.self_and_ancestors.as_ids
else
Gitlab::ObjectHierarchy.new(project_groups).base_and_ancestors
end
joins(:groups) joins(:groups)
.where(namespaces: { id: hierarchy_groups }) .where(namespaces: { id: hierarchy_groups })
......
---
name: linear_runner_ancestor_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70385
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341114
milestone: '14.6'
type: development
group: group::access
default_enabled: false
...@@ -208,26 +208,38 @@ RSpec.describe Ci::Runner do ...@@ -208,26 +208,38 @@ RSpec.describe Ci::Runner do
end end
describe '.belonging_to_parent_group_of_project' do describe '.belonging_to_parent_group_of_project' do
let(:project) { create(:project, group: group) } shared_examples 'returns parent group project runners' do
let(:group) { create(:group) } let(:project) { create(:project, group: group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) } let(:group) { create(:group) }
let!(:unrelated_group) { create(:group) } let(:runner) { create(:ci_runner, :group, groups: [group]) }
let!(:unrelated_project) { create(:project, group: unrelated_group) } let!(:unrelated_group) { create(:group) }
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) } let!(:unrelated_project) { create(:project, group: unrelated_group) }
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) }
it 'returns the specific group runner' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
it 'returns the specific group runner' do context 'with a parent group with a runner' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner) let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
it 'returns the group runner from the parent group' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
end
end end
context 'with a parent group with a runner' do it_behaves_like 'returns parent group project runners'
let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
it 'returns the group runner from the parent group' do context 'when feature flag :linear_runner_ancestor_scopes is disabled' do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner) before do
stub_feature_flags(linear_runner_ancestor_scopes: false)
end end
it_behaves_like 'returns parent group project runners'
end end
end end
...@@ -1259,31 +1271,43 @@ RSpec.describe Ci::Runner do ...@@ -1259,31 +1271,43 @@ RSpec.describe Ci::Runner do
end end
describe '.belonging_to_group' do describe '.belonging_to_group' do
it 'returns the specific group runner' do shared_examples 'returns group runners' do
group = create(:group) it 'returns the specific group runner' do
runner = create(:ci_runner, :group, groups: [group]) group = create(:group)
unrelated_group = create(:group) runner = create(:ci_runner, :group, groups: [group])
create(:ci_runner, :group, groups: [unrelated_group]) unrelated_group = create(:group)
create(:ci_runner, :group, groups: [unrelated_group])
expect(described_class.belonging_to_group(group.id)).to contain_exactly(runner) expect(described_class.belonging_to_group(group.id)).to contain_exactly(runner)
end end
context 'runner belonging to parent group' do context 'runner belonging to parent group' do
let_it_be(:parent_group) { create(:group) } let_it_be(:parent_group) { create(:group) }
let_it_be(:parent_runner) { create(:ci_runner, :group, groups: [parent_group]) } let_it_be(:parent_runner) { create(:ci_runner, :group, groups: [parent_group]) }
let_it_be(:group) { create(:group, parent: parent_group) } let_it_be(:group) { create(:group, parent: parent_group) }
context 'when include_parent option is passed' do context 'when include_parent option is passed' do
it 'returns the group runner from the parent group' do it 'returns the group runner from the parent group' do
expect(described_class.belonging_to_group(group.id, include_ancestors: true)).to contain_exactly(parent_runner) expect(described_class.belonging_to_group(group.id, include_ancestors: true)).to contain_exactly(parent_runner)
end
end end
end
context 'when include_parent option is not passed' do context 'when include_parent option is not passed' do
it 'does not return the group runner from the parent group' do it 'does not return the group runner from the parent group' do
expect(described_class.belonging_to_group(group.id)).to be_empty expect(described_class.belonging_to_group(group.id)).to be_empty
end
end end
end end
end end
it_behaves_like 'returns group runners'
context 'when feature flag :linear_runner_ancestor_scopes is disabled' do
before do
stub_feature_flags(linear_runner_ancestor_scopes: false)
end
it_behaves_like 'returns group runners'
end
end 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