Commit 97e12db9 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '244050-feature-flag-to-allow-old-projects-to-have-a-cleanup-policy' into 'master'

Add feature flag for a a phased rollout of cleanup policies

See merge request gitlab-org/gitlab!44444
parents 9d6f0a58 dd57d868
......@@ -24,4 +24,9 @@ module ContainerExpirationPoliciesHelper
end
end
end
def container_expiration_policies_historic_entry_enabled?(project)
Gitlab::CurrentSettings.container_expiration_policies_enable_historic_entries ||
Feature.enabled?(:container_expiration_policies_historic_entry, project)
end
end
......@@ -5,4 +5,4 @@
older_than_options: older_than_options.to_json,
is_admin: current_user&.admin.to_s,
admin_settings_path: ci_cd_admin_application_settings_path(anchor: 'js-registry-settings'),
enable_historic_entries: Gitlab::CurrentSettings.try(:container_expiration_policies_enable_historic_entries).to_s} }
enable_historic_entries: container_expiration_policies_historic_entry_enabled?(@project).to_s} }
---
title: Add feature flag for a phased rollout of cleanup policies
merge_request: 44444
author:
type: added
---
name: container_expiration_policies_historic_entry
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44444
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/262639
type: development
group: group::package
default_enabled: false
......@@ -469,6 +469,20 @@ Cleanup policies can be run on all projects, with these exceptions:
There are performance risks with enabling it for all projects, especially if you
are using an [external registry](./index.md#use-with-external-container-registries).
- For self-managed GitLab instances, you can enable or disable the cleanup policy for a specific
project.
To enable it:
```ruby
Feature.enable(:container_expiration_policies_historic_entry, Project.find(<project id>))
```
To disable it:
```ruby
Feature.disable(:container_expiration_policies_historic_entry, Project.find(<project id>))
```
### How the cleanup policy works
......
......@@ -3,27 +3,35 @@
require 'spec_helper'
RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration policy', :js do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace, container_registry_enabled: container_registry_enabled) }
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, namespace: user.namespace) }
let(:container_registry_enabled) { true }
let(:container_registry_enabled_on_project) { true }
subject { visit project_settings_ci_cd_path(project) }
before do
project.update!(container_registry_enabled: container_registry_enabled_on_project)
sign_in(user)
stub_container_registry_config(enabled: true)
stub_container_registry_config(enabled: container_registry_enabled)
stub_feature_flags(new_variables_ui: false)
end
context 'as owner' do
before do
visit project_settings_ci_cd_path(project)
end
it 'shows available section' do
subject
settings_block = find('#js-registry-policies')
expect(settings_block).to have_text 'Cleanup policy for tags'
end
it 'saves cleanup policy submit the form' do
subject
within '#js-registry-policies' do
within '.card-body' do
select('7 days until tags are automatically removed', from: 'Expiration interval:')
......@@ -40,6 +48,8 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
end
it 'does not save cleanup policy submit form with invalid regex' do
subject
within '#js-registry-policies' do
within '.card-body' do
fill_in('Tags with names matching this regex pattern will expire:', with: '*-production')
......@@ -53,25 +63,53 @@ RSpec.describe 'Project > Settings > CI/CD > Container registry tag expiration p
end
end
context 'when registry is disabled' do
context 'with a project without expiration policy' do
where(:application_setting, :feature_flag, :result) do
true | true | :available_section
true | false | :available_section
false | true | :available_section
false | false | :disabled_message
end
with_them do
before do
stub_container_registry_config(enabled: false)
visit project_settings_ci_cd_path(project)
project.container_expiration_policy.destroy!
stub_feature_flags(container_expiration_policies_historic_entry: false)
stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
end
it 'does not exists' do
expect(page).not_to have_selector('#js-registry-policies')
it 'displays the expected result' do
subject
within '#js-registry-policies' do
case result
when :available_section
expect(find('.card-header')).to have_content('Tag expiration policy')
when :disabled_message
expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled')
end
end
end
end
end
context 'when container registry is disabled on project' do
context 'when registry is disabled' do
let(:container_registry_enabled) { false }
before do
visit project_settings_ci_cd_path(project)
it 'does not exists' do
subject
expect(page).not_to have_selector('#js-registry-policies')
end
end
context 'when container registry is disabled on project' do
let(:container_registry_enabled_on_project) { false }
it 'does not exists' do
subject
expect(page).not_to have_selector('#js-registry-policies')
end
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe ContainerExpirationPoliciesHelper do
using RSpec::Parameterized::TableSyntax
describe '#keep_n_options' do
it 'returns keep_n options formatted for dropdown usage' do
expected_result = [
......@@ -44,4 +46,27 @@ RSpec.describe ContainerExpirationPoliciesHelper do
expect(helper.older_than_options).to eq(expected_result)
end
end
describe '#container_expiration_policies_historic_entry_enabled?' do
let_it_be(:project) { build_stubbed(:project) }
subject { helper.container_expiration_policies_historic_entry_enabled?(project) }
where(:application_setting, :feature_flag, :expected_result) do
true | true | true
true | false | true
false | true | true
false | false | false
end
with_them do
before do
stub_feature_flags(container_expiration_policies_historic_entry: false)
stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting)
stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag
end
it { is_expected.to eq(expected_result) }
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