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
}
scope :owned_or_instance_wide, -> (project_id) do
project = project_id.respond_to?(:shared_runners) ? project_id : Project.find(project_id)
from_union(
[
belonging_to_project(project_id),
belonging_to_parent_group_of_project(project_id),
instance_type
project.shared_runners
],
remove_duplicates: false
)
......@@ -173,7 +175,7 @@ module Ci
from_union(
[
group_and_ancestor_runners,
instance_type
group.shared_runners
],
remove_duplicates: false
)
......
......@@ -492,6 +492,10 @@ class Namespace < ApplicationRecord
end
end
def shared_runners
@shared_runners ||= shared_runners_enabled ? Ci::Runner.instance_type : Ci::Runner.none
end
def root?
!has_parent?
end
......
......@@ -448,7 +448,7 @@ Example response:
## 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
GET /projects/:id/runners
......@@ -566,7 +566,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git
## 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
GET /groups/:id/runners
......
......@@ -265,10 +265,10 @@ RSpec.describe Ci::Runner do
it_behaves_like '.belonging_to_parent_group_of_project'
end
context 'with existing system wide, group and project runners' do
context 'with instance runners sharing enabled' do
# group specific
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:group) { create(:group, shared_runners_enabled: true) }
let_it_be(:project) { create(:project, group: group, shared_runners_enabled: true) }
let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) }
# project specific
......@@ -299,6 +299,40 @@ RSpec.describe Ci::Runner do
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
it 'returns the description if it has a value' do
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