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
d845d80e
Commit
d845d80e
authored
Jul 13, 2021
by
Maxime Orefice
Committed by
Grzegorz Bizon
Jul 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Denormalize shared runners to CI::PendingBuild
parent
7883a37d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
125 additions
and
2 deletions
+125
-2
app/models/ci/pending_build.rb
app/models/ci/pending_build.rb
+38
-1
config/feature_flags/development/ci_pending_builds_maintain_shared_runners_data.yml
...opment/ci_pending_builds_maintain_shared_runners_data.yml
+8
-0
db/migrate/20210705144657_add_instance_runners_enabled_to_ci_pending_build.rb
...44657_add_instance_runners_enabled_to_ci_pending_build.rb
+19
-0
db/schema_migrations/20210705144657
db/schema_migrations/20210705144657
+1
-0
db/structure.sql
db/structure.sql
+2
-1
spec/factories/ci/pending_builds.rb
spec/factories/ci/pending_builds.rb
+1
-0
spec/models/ci/pending_build_spec.rb
spec/models/ci/pending_build_spec.rb
+56
-0
No files found.
app/models/ci/pending_build.rb
View file @
d845d80e
...
@@ -11,11 +11,48 @@ module Ci
...
@@ -11,11 +11,48 @@ module Ci
scope
:queued_before
,
->
(
time
)
{
where
(
arel_table
[
:created_at
].
lt
(
time
))
}
scope
:queued_before
,
->
(
time
)
{
where
(
arel_table
[
:created_at
].
lt
(
time
))
}
def
self
.
upsert_from_build!
(
build
)
def
self
.
upsert_from_build!
(
build
)
entry
=
self
.
new
(
build:
build
,
project:
build
.
project
,
protected:
build
.
protected?
)
entry
=
self
.
new
(
args_from_build
(
build
)
)
entry
.
validate!
entry
.
validate!
self
.
upsert
(
entry
.
attributes
.
compact
,
returning:
%w[build_id]
,
unique_by: :build_id
)
self
.
upsert
(
entry
.
attributes
.
compact
,
returning:
%w[build_id]
,
unique_by: :build_id
)
end
end
def
self
.
args_from_build
(
build
)
args
=
{
build:
build
,
project:
build
.
project
,
protected:
build
.
protected?
}
if
Feature
.
enabled?
(
:ci_pending_builds_maintain_shared_runners_data
,
type: :development
,
default_enabled: :yaml
)
args
.
merge
(
instance_runners_enabled:
shareable?
(
build
))
else
args
end
end
private_class_method
:args_from_build
def
self
.
shareable?
(
build
)
shared_runner_enabled?
(
build
)
&&
builds_access_level?
(
build
)
&&
project_not_removed?
(
build
)
end
private_class_method
:shareable?
def
self
.
shared_runner_enabled?
(
build
)
build
.
project
.
shared_runners
.
exists?
end
private_class_method
:shared_runner_enabled?
def
self
.
project_not_removed?
(
build
)
!
build
.
project
.
pending_delete?
end
private_class_method
:project_not_removed?
def
self
.
builds_access_level?
(
build
)
build
.
project
.
project_feature
.
builds_access_level
.
nil?
||
build
.
project
.
project_feature
.
builds_access_level
>
0
end
private_class_method
:builds_access_level?
end
end
end
end
config/feature_flags/development/ci_pending_builds_maintain_shared_runners_data.yml
0 → 100644
View file @
d845d80e
---
name
:
ci_pending_builds_maintain_shared_runners_data
introduced_by_url
:
rollout_issue_url
:
milestone
:
'
14.1'
type
:
development
group
:
group::pipeline execution
default_enabled
:
false
db/migrate/20210705144657_add_instance_runners_enabled_to_ci_pending_build.rb
0 → 100644
View file @
d845d80e
# frozen_string_literal: true
class
AddInstanceRunnersEnabledToCiPendingBuild
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
def
up
with_lock_retries
do
add_column
:ci_pending_builds
,
:instance_runners_enabled
,
:boolean
,
null:
false
,
default:
false
end
end
def
down
with_lock_retries
do
remove_column
:ci_pending_builds
,
:instance_runners_enabled
end
end
end
db/schema_migrations/20210705144657
0 → 100644
View file @
d845d80e
9ba27b5e2599262846a06736db72fb0d31dc904e2ef4d167c1ee9530feb6367f
\ No newline at end of file
db/structure.sql
View file @
d845d80e
...
@@ -10833,7 +10833,8 @@ CREATE TABLE ci_pending_builds (
...
@@ -10833,7 +10833,8 @@ CREATE TABLE ci_pending_builds (
build_id bigint NOT NULL,
build_id bigint NOT NULL,
project_id bigint NOT NULL,
project_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
protected boolean DEFAULT false NOT NULL
protected boolean DEFAULT false NOT NULL,
instance_runners_enabled boolean DEFAULT false NOT NULL
);
);
CREATE SEQUENCE ci_pending_builds_id_seq
CREATE SEQUENCE ci_pending_builds_id_seq
spec/factories/ci/pending_builds.rb
View file @
d845d80e
...
@@ -5,5 +5,6 @@ FactoryBot.define do
...
@@ -5,5 +5,6 @@ FactoryBot.define do
build
factory: :ci_build
build
factory: :ci_build
project
project
protected
{
build
.
protected
}
protected
{
build
.
protected
}
instance_runners_enabled
{
true
}
end
end
end
end
spec/models/ci/pending_build_spec.rb
View file @
d845d80e
...
@@ -29,5 +29,61 @@ RSpec.describe Ci::PendingBuild do
...
@@ -29,5 +29,61 @@ RSpec.describe Ci::PendingBuild do
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
end
end
end
end
context
'when project does not have shared runner'
do
it
'sets instance_runners_enabled to false'
do
described_class
.
upsert_from_build!
(
build
)
expect
(
described_class
.
last
.
instance_runners_enabled
).
to
be_falsey
end
end
context
'when project has shared runner'
do
let_it_be
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
context
'when ci_pending_builds_maintain_shared_runners_data is enabled'
do
it
'sets instance_runners_enabled to true'
do
described_class
.
upsert_from_build!
(
build
)
expect
(
described_class
.
last
.
instance_runners_enabled
).
to
be_truthy
end
context
'when project is about to be deleted'
do
before
do
build
.
project
.
update!
(
pending_delete:
true
)
end
it
'sets instance_runners_enabled to false'
do
described_class
.
upsert_from_build!
(
build
)
expect
(
described_class
.
last
.
instance_runners_enabled
).
to
be_falsey
end
end
context
'when builds are disabled'
do
before
do
build
.
project
.
project_feature
.
update!
(
builds_access_level:
false
)
end
it
'sets instance_runners_enabled to false'
do
described_class
.
upsert_from_build!
(
build
)
expect
(
described_class
.
last
.
instance_runners_enabled
).
to
be_falsey
end
end
end
context
'when ci_pending_builds_maintain_shared_runners_data is disabled'
do
before
do
stub_feature_flags
(
ci_pending_builds_maintain_shared_runners_data:
false
)
end
it
'sets instance_runners_enabled to false'
do
described_class
.
upsert_from_build!
(
build
)
expect
(
described_class
.
last
.
instance_runners_enabled
).
to
be_falsey
end
end
end
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