Commit 4f12dcf7 authored by Pedro Pombeiro's avatar Pedro Pombeiro

REST: Follow shared runners setting

When listing shared runners, follow the `Enable shared runners` setting:
https://docs.gitlab.com/ee/ci/runners/runners_scope.html#enable-shared-runners

Changelog: fixed
parent 9fcc3738
...@@ -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
......
...@@ -280,8 +280,20 @@ RSpec.describe Ci::Runner do ...@@ -280,8 +280,20 @@ RSpec.describe Ci::Runner do
describe '.owned_or_instance_wide' do describe '.owned_or_instance_wide' do
subject { described_class.owned_or_instance_wide(project.id) } subject { described_class.owned_or_instance_wide(project.id) }
it 'returns a globally shared, a project specific and a group specific runner' do context 'with instance runners sharing enabled' do
is_expected.to contain_exactly(group_runner, project_runner, shared_runner) let(:shared_runners_enabled) { true }
it 'returns a globally shared, a project specific and a group specific runner' do
is_expected.to contain_exactly(group_runner, project_runner, shared_runner)
end
end
context 'with instance runners sharing disabled' do
let(:shared_runners_enabled) { false }
it 'returns a project specific and a group specific runner' do
is_expected.to contain_exactly(group_runner, project_runner)
end
end end
end end
...@@ -293,8 +305,20 @@ RSpec.describe Ci::Runner do ...@@ -293,8 +305,20 @@ RSpec.describe Ci::Runner do
project_runner project_runner
end end
it 'returns a globally shared and a group specific runner' do context 'with instance runners sharing enabled' do
is_expected.to contain_exactly(group_runner, shared_runner) let(:shared_runners_enabled) { true }
it 'returns a globally shared and a group specific runner' do
is_expected.to contain_exactly(group_runner, shared_runner)
end
end
context 'with instance runners sharing disabled' do
let(:shared_runners_enabled) { false }
it 'returns a group specific runner' do
is_expected.to contain_exactly(group_runner)
end
end 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