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
aa136207
Commit
aa136207
authored
Mar 30, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
f4b07b0a
6a96e3a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
51 deletions
+100
-51
app/workers/container_expiration_policy_worker.rb
app/workers/container_expiration_policy_worker.rb
+13
-7
config/feature_flags/development/container_registry_expiration_policies_loopless.yml
...pment/container_registry_expiration_policies_loopless.yml
+8
-0
spec/workers/container_expiration_policy_worker_spec.rb
spec/workers/container_expiration_policy_worker_spec.rb
+79
-44
No files found.
app/workers/container_expiration_policy_worker.rb
View file @
aa136207
...
...
@@ -29,13 +29,15 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo
def
perform_throttled
try_obtain_lease
do
with_runnable_policy
do
|
policy
|
ContainerExpirationPolicy
.
transaction
do
policy
.
schedule_next_run!
ContainerRepository
.
for_project_id
(
policy
.
id
)
.
each_batch
do
|
relation
|
relation
.
update_all
(
expiration_policy_cleanup_status: :cleanup_scheduled
)
end
unless
loopless_enabled?
with_runnable_policy
do
|
policy
|
ContainerExpirationPolicy
.
transaction
do
policy
.
schedule_next_run!
ContainerRepository
.
for_project_id
(
policy
.
id
)
.
each_batch
do
|
relation
|
relation
.
update_all
(
expiration_policy_cleanup_status: :cleanup_scheduled
)
end
end
end
end
...
...
@@ -75,6 +77,10 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo
Feature
.
enabled?
(
:container_registry_expiration_policies_throttling
)
end
def
loopless_enabled?
Feature
.
enabled?
(
:container_registry_expiration_policies_loopless
)
end
def
lease_timeout
5
.
hours
end
...
...
config/feature_flags/development/container_registry_expiration_policies_loopless.yml
0 → 100644
View file @
aa136207
---
name
:
container_registry_expiration_policies_loopless
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56962
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/325273
milestone
:
'
13.11'
type
:
development
group
:
group::package
default_enabled
:
false
spec/workers/container_expiration_policy_worker_spec.rb
View file @
aa136207
...
...
@@ -11,7 +11,7 @@ RSpec.describe ContainerExpirationPolicyWorker do
describe
'#perform'
do
subject
{
worker
.
perform
}
RSpec
.
shared_examples
'not executing any policy'
do
shared_examples
'not executing any policy'
do
it
'does not run any policy'
do
expect
(
ContainerExpirationPolicyService
).
not_to
receive
(
:new
)
...
...
@@ -19,6 +19,21 @@ RSpec.describe ContainerExpirationPolicyWorker do
end
end
shared_examples
'handling a taken exclusive lease'
do
context
'with exclusive lease taken'
do
before
do
stub_exclusive_lease_taken
(
worker
.
lease_key
,
timeout:
5
.
hours
)
end
it
'does not do anything'
do
expect
(
ContainerExpirationPolicies
::
CleanupContainerRepositoryWorker
).
not_to
receive
(
:perform_with_capacity
)
expect
(
worker
).
not_to
receive
(
:runnable_policies
)
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
cleanup_scheduled
.
count
}
end
end
end
context
'With no container expiration policies'
do
it
'does not execute any policies'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
...
...
@@ -27,66 +42,86 @@ RSpec.describe ContainerExpirationPolicyWorker do
end
end
context
'with container expiration policies'
do
let_it_be
(
:container_expiration_policy
)
{
create
(
:container_expiration_policy
,
:runnable
)
}
let_it_be
(
:container_repository
)
{
create
(
:container_repository
,
project:
container_expiration_policy
.
project
)
}
context
'with throttling enabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_throttling:
true
)
end
context
'with
a valid container expiration policy
'
do
it
'schedules the next run'
do
expect
{
subject
}.
to
change
{
container_expiration_policy
.
reload
.
next_run_at
}
context
'with
loopless disabled
'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
false
)
end
it
'marks the container repository as scheduled for cleanup'
do
expect
{
subject
}.
to
change
{
container_repository
.
reload
.
cleanup_scheduled?
}.
from
(
false
).
to
(
true
)
expect
(
ContainerRepository
.
cleanup_scheduled
.
count
).
to
eq
(
1
)
end
context
'with container expiration policies'
do
let_it_be
(
:container_expiration_policy
)
{
create
(
:container_expiration_policy
,
:runnable
)
}
let_it_be
(
:container_repository
)
{
create
(
:container_repository
,
project:
container_expiration_policy
.
project
)
}
it
'calls the limited capacity worker'
do
expect
(
ContainerExpirationPolicies
::
CleanupContainerRepositoryWorker
).
to
receive
(
:perform_with_capacity
)
before
do
expect
(
worker
).
to
receive
(
:with_runnable_policy
).
and_call_original
end
subject
end
end
context
'with a valid container expiration policy'
do
it
'schedules the next run'
do
expect
{
subject
}.
to
change
{
container_expiration_policy
.
reload
.
next_run_at
}
end
context
'with a disabled container expiration policy
'
do
before
do
container_expiration_policy
.
disable!
end
it
'marks the container repository as scheduled for cleanup
'
do
expect
{
subject
}.
to
change
{
container_repository
.
reload
.
cleanup_scheduled?
}.
from
(
false
).
to
(
true
)
expect
(
ContainerRepository
.
cleanup_scheduled
.
count
).
to
eq
(
1
)
end
it
'does not run the policy
'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
it
'calls the limited capacity worker
'
do
expect
(
ContainerExpirationPolicies
::
CleanupContainerRepositoryWorker
).
to
receive
(
:perform_with_capacity
)
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
cleanup_scheduled
.
count
}
end
end
subject
end
end
context
'with an invalid container expiration policy'
do
let
(
:user
)
{
container_expiration_policy
.
project
.
owner
}
context
'with a disabled container expiration policy'
do
before
do
container_expiration_policy
.
disable!
end
before
do
container_expiration_policy
.
update_column
(
:name_regex
,
'*production'
)
end
it
'does not run the policy'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
it
'disables the policy and tracks an error'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
e
xpect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:log_exception
).
with
(
instance_of
(
described_class
::
InvalidPolicyError
),
container_expiration_policy_id:
container_expiration_policy
.
id
)
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
cleanup_scheduled
.
count
}
end
e
nd
expect
{
subject
}.
to
change
{
container_expiration_policy
.
reload
.
enabled
}.
from
(
true
).
to
(
false
)
expect
(
ContainerRepository
.
cleanup_scheduled
).
to
be_empty
context
'with an invalid container expiration policy'
do
let
(
:user
)
{
container_expiration_policy
.
project
.
owner
}
before
do
container_expiration_policy
.
update_column
(
:name_regex
,
'*production'
)
end
it
'disables the policy and tracks an error'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:log_exception
).
with
(
instance_of
(
described_class
::
InvalidPolicyError
),
container_expiration_policy_id:
container_expiration_policy
.
id
)
expect
{
subject
}.
to
change
{
container_expiration_policy
.
reload
.
enabled
}.
from
(
true
).
to
(
false
)
expect
(
ContainerRepository
.
cleanup_scheduled
).
to
be_empty
end
end
end
end
end
context
'with exclusive lease taken'
do
before
do
stub_exclusive_lease_taken
(
worker
.
lease_key
,
timeout:
5
.
hours
)
it_behaves_like
'handling a taken exclusive lease'
end
it
'does not execute any policy'
do
expect
(
ContainerExpirationPolicies
::
CleanupContainerRepositoryWorker
).
not_to
receive
(
:perform_with_capacity
)
expect
(
worker
).
not_to
receive
(
:runnable_policies
)
context
'with loopless enabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
true
)
expect
(
worker
).
not_to
receive
(
:with_runnable_policy
)
end
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
cleanup_scheduled
.
count
}
it
'calls the limited capacity worker'
do
expect
(
ContainerExpirationPolicies
::
CleanupContainerRepositoryWorker
).
to
receive
(
:perform_with_capacity
)
subject
end
it_behaves_like
'handling a taken exclusive lease'
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