Commit 79d2a8b0 authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Dylan Griffith

Remove runners <-> groups cross-joins where possible

parent 0f4009ad
......@@ -438,10 +438,8 @@ module Ci
end
def no_groups
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do
if groups.any?
errors.add(:runner, 'cannot have groups assigned')
end
if runner_namespaces.any?
errors.add(:runner, 'cannot have groups assigned')
end
end
......@@ -452,10 +450,8 @@ module Ci
end
def exactly_one_group
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do
unless groups.one?
errors.add(:runner, 'needs to be assigned to exactly one group')
end
unless runner_namespaces.one?
errors.add(:runner, 'needs to be assigned to exactly one group')
end
end
......
......@@ -70,7 +70,7 @@ module Clusters
}
if cluster.group_type?
attributes[:groups] = [group]
attributes[:runner_namespaces] = [::Ci::RunnerNamespace.new(namespace: group)]
elsif cluster.project_type?
attributes[:runner_projects] = [::Ci::RunnerProject.new(project: project)]
end
......
......@@ -2,7 +2,14 @@
FactoryBot.define do
factory :ci_runner_namespace, class: 'Ci::RunnerNamespace' do
runner factory: [:ci_runner, :group]
group
after(:build) do |runner_namespace, evaluator|
unless runner_namespace.runner.present?
runner_namespace.runner = build(
:ci_runner, :group, runner_namespaces: [runner_namespace]
)
end
end
end
end
......@@ -11,6 +11,7 @@ FactoryBot.define do
runner_type { :instance_type }
transient do
groups { [] }
projects { [] }
end
......@@ -18,6 +19,10 @@ FactoryBot.define do
evaluator.projects.each do |proj|
runner.runner_projects << build(:ci_runner_project, project: proj)
end
evaluator.groups.each do |group|
runner.runner_namespaces << build(:ci_runner_namespace, namespace: group)
end
end
trait :online do
......@@ -32,7 +37,9 @@ FactoryBot.define do
runner_type { :group_type }
after(:build) do |runner, evaluator|
runner.groups << build(:group) if runner.groups.empty?
if runner.runner_namespaces.empty?
runner.runner_namespaces << build(:ci_runner_namespace)
end
end
end
......
......@@ -44,7 +44,7 @@ RSpec.describe Ci::Runner do
let(:runner) { create(:ci_runner, :group, groups: [group]) }
it 'disallows assigning group if already assigned to a group' do
runner.groups << build(:group)
runner.runner_namespaces << build(:ci_runner_namespace)
expect(runner).not_to be_valid
expect(runner.errors.full_messages).to include('Runner needs to be assigned to exactly one group')
......
......@@ -112,7 +112,7 @@ RSpec.describe Clusters::Applications::Runner do
subject
expect(runner).to be_group_type
expect(runner.groups).to eq [group]
expect(runner.runner_namespaces.pluck(:namespace_id)).to match_array [group.id]
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