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