Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
79d2a8b0
Commit
79d2a8b0
authored
Oct 25, 2021
by
Avielle Wolfe
Committed by
Dylan Griffith
Oct 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove runners <-> groups cross-joins where possible
parent
0f4009ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
13 deletions
+23
-13
app/models/ci/runner.rb
app/models/ci/runner.rb
+4
-8
app/models/clusters/applications/runner.rb
app/models/clusters/applications/runner.rb
+1
-1
spec/factories/ci/runner_namespaces.rb
spec/factories/ci/runner_namespaces.rb
+8
-1
spec/factories/ci/runners.rb
spec/factories/ci/runners.rb
+8
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+1
-1
spec/models/clusters/applications/runner_spec.rb
spec/models/clusters/applications/runner_spec.rb
+1
-1
No files found.
app/models/ci/runner.rb
View file @
79d2a8b0
...
@@ -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
...
...
app/models/clusters/applications/runner.rb
View file @
79d2a8b0
...
@@ -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
...
...
spec/factories/ci/runner_namespaces.rb
View file @
79d2a8b0
...
@@ -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
spec/factories/ci/runners.rb
View file @
79d2a8b0
...
@@ -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
...
...
spec/models/ci/runner_spec.rb
View file @
79d2a8b0
...
@@ -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'
)
...
...
spec/models/clusters/applications/runner_spec.rb
View file @
79d2a8b0
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment