Commit 1b2fd94b authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch...

Merge branch 'pedropombeiro/337690/2-rest-api-return-instance-runners-only-if-enabled' into 'master'

REST: Follow shared runners setting

See merge request gitlab-org/gitlab!79448
parents 5ce28f9b cbc010ad
...@@ -152,11 +152,13 @@ module Ci ...@@ -152,11 +152,13 @@ module Ci
} }
scope :owned_or_instance_wide, -> (project_id) do scope :owned_or_instance_wide, -> (project_id) do
project = project_id.respond_to?(:shared_runners) ? project_id : Project.find(project_id)
from_union( from_union(
[ [
belonging_to_project(project_id), belonging_to_project(project_id),
belonging_to_parent_group_of_project(project_id), belonging_to_parent_group_of_project(project_id),
instance_type project.shared_runners
], ],
remove_duplicates: false remove_duplicates: false
) )
...@@ -173,7 +175,7 @@ module Ci ...@@ -173,7 +175,7 @@ module Ci
from_union( from_union(
[ [
group_and_ancestor_runners, group_and_ancestor_runners,
instance_type group.shared_runners
], ],
remove_duplicates: false remove_duplicates: false
) )
......
...@@ -492,6 +492,10 @@ class Namespace < ApplicationRecord ...@@ -492,6 +492,10 @@ class Namespace < ApplicationRecord
end end
end end
def shared_runners
@shared_runners ||= shared_runners_enabled ? Ci::Runner.instance_type : Ci::Runner.none
end
def root? def root?
!has_parent? !has_parent?
end end
......
...@@ -448,7 +448,7 @@ Example response: ...@@ -448,7 +448,7 @@ Example response:
## List project's runners ## List project's runners
List all runners available in the project, including from ancestor groups and any shared runners. List all runners available in the project, including from ancestor groups and [any allowed shared runners](../ci/runners/runners_scope.md#enable-shared-runners).
```plaintext ```plaintext
GET /projects/:id/runners GET /projects/:id/runners
...@@ -566,7 +566,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git ...@@ -566,7 +566,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git
## List group's runners ## List group's runners
List all runners available in the group as well as its ancestor groups, including any shared runners. List all runners available in the group as well as its ancestor groups, including [any allowed shared runners](../ci/runners/runners_scope.md#enable-shared-runners).
```plaintext ```plaintext
GET /groups/:id/runners GET /groups/:id/runners
......
...@@ -265,10 +265,10 @@ RSpec.describe Ci::Runner do ...@@ -265,10 +265,10 @@ RSpec.describe Ci::Runner do
it_behaves_like '.belonging_to_parent_group_of_project' it_behaves_like '.belonging_to_parent_group_of_project'
end end
context 'with existing system wide, group and project runners' do context 'with instance runners sharing enabled' do
# group specific # group specific
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group, shared_runners_enabled: true) }
let_it_be(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group, shared_runners_enabled: true) }
let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) } let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) }
# project specific # project specific
...@@ -299,6 +299,40 @@ RSpec.describe Ci::Runner do ...@@ -299,6 +299,40 @@ RSpec.describe Ci::Runner do
end end
end end
context 'with instance runners sharing disabled' do
# group specific
let_it_be(:group) { create(:group, shared_runners_enabled: false) }
let_it_be(:project) { create(:project, group: group, shared_runners_enabled: false) }
let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) }
# project specific
let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) }
# globally shared
let_it_be(:shared_runner) { create(:ci_runner, :instance) }
describe '.owned_or_instance_wide' do
subject { described_class.owned_or_instance_wide(project.id) }
it 'returns a project specific and a group specific runner' do
is_expected.to contain_exactly(group_runner, project_runner)
end
end
describe '.group_or_instance_wide' do
subject { described_class.group_or_instance_wide(group) }
before do
# Ensure the project runner is instantiated
project_runner
end
it 'returns a group specific runner' do
is_expected.to contain_exactly(group_runner)
end
end
end
describe '#display_name' do describe '#display_name' do
it 'returns the description if it has a value' do it 'returns the description if it has a value' do
runner = build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448') runner = build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
......
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