Commit b390316b authored by Pedro Pombeiro's avatar Pedro Pombeiro

Introduce ci_runner_limits_override feature flag

This will allow overriding the `ci_runner_limits` feature flag in case
of need
parent d9d4ac4a
...@@ -9,6 +9,7 @@ module Ci ...@@ -9,6 +9,7 @@ module Ci
self.limit_scope = :group self.limit_scope = :group
self.limit_relation = :recent_runners self.limit_relation = :recent_runners
self.limit_feature_flag = :ci_runner_limits self.limit_feature_flag = :ci_runner_limits
self.limit_feature_flag_for_override = :ci_runner_limits_override
belongs_to :runner, inverse_of: :runner_namespaces belongs_to :runner, inverse_of: :runner_namespaces
belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace' belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace'
......
...@@ -9,6 +9,7 @@ module Ci ...@@ -9,6 +9,7 @@ module Ci
self.limit_scope = :project self.limit_scope = :project
self.limit_relation = :recent_runners self.limit_relation = :recent_runners
self.limit_feature_flag = :ci_runner_limits self.limit_feature_flag = :ci_runner_limits
self.limit_feature_flag_for_override = :ci_runner_limits_override
belongs_to :runner, inverse_of: :runner_projects belongs_to :runner, inverse_of: :runner_projects
belongs_to :project, inverse_of: :runner_projects belongs_to :project, inverse_of: :runner_projects
......
---
name: ci_runner_limits_override
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67152
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/337224
milestone: '14.2'
type: development
group: group::runner
default_enabled: false
...@@ -4,6 +4,12 @@ require 'spec_helper' ...@@ -4,6 +4,12 @@ require 'spec_helper'
RSpec.describe Ci::RunnerNamespace do RSpec.describe Ci::RunnerNamespace do
it_behaves_like 'includes Limitable concern' do it_behaves_like 'includes Limitable concern' do
before do
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: false)
end
subject { build(:ci_runner_namespace, group: create(:group, :nested), runner: create(:ci_runner, :group)) } subject { build(:ci_runner_namespace, group: create(:group, :nested), runner: create(:ci_runner, :group)) }
end end
end end
...@@ -4,6 +4,12 @@ require 'spec_helper' ...@@ -4,6 +4,12 @@ require 'spec_helper'
RSpec.describe Ci::RunnerProject do RSpec.describe Ci::RunnerProject do
it_behaves_like 'includes Limitable concern' do it_behaves_like 'includes Limitable concern' do
before do
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: false)
end
subject { build(:ci_runner_project, project: create(:project), runner: create(:ci_runner, :project)) } subject { build(:ci_runner_project, project: create(:project), runner: create(:ci_runner, :project)) }
end end
end end
...@@ -98,14 +98,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -98,14 +98,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
before do before do
create(:ci_runner, runner_type: :project_type, projects: [project], contacted_at: 1.second.ago) create(:ci_runner, runner_type: :project_type, projects: [project], contacted_at: 1.second.ago)
create(:plan_limits, :default_plan, ci_registered_project_runners: 1) create(:plan_limits, :default_plan, ci_registered_project_runners: 1)
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: ci_runner_limits_override)
end end
it 'does not create runner' do context 'with ci_runner_limits_override FF disabled' do
request let(:ci_runner_limits_override) { false }
it 'does not create runner' do
request
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('runner_projects.base' => ['Maximum number of ci registered project runners (1) exceeded']) expect(json_response['message']).to include('runner_projects.base' => ['Maximum number of ci registered project runners (1) exceeded'])
expect(project.runners.reload.size).to eq(1) expect(project.runners.reload.size).to eq(1)
end
end
context 'with ci_runner_limits_override FF enabled' do
let(:ci_runner_limits_override) { true }
it 'creates runner' do
request
expect(response).to have_gitlab_http_status(:created)
expect(json_response['message']).to be_nil
expect(project.runners.reload.size).to eq(2)
end
end end
end end
...@@ -113,6 +132,9 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -113,6 +132,9 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
before do before do
create(:ci_runner, runner_type: :project_type, projects: [project], created_at: 14.months.ago, contacted_at: 13.months.ago) create(:ci_runner, runner_type: :project_type, projects: [project], created_at: 14.months.ago, contacted_at: 13.months.ago)
create(:plan_limits, :default_plan, ci_registered_project_runners: 1) create(:plan_limits, :default_plan, ci_registered_project_runners: 1)
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: false)
end end
it 'creates runner' do it 'creates runner' do
...@@ -182,14 +204,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -182,14 +204,33 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
before do before do
create(:ci_runner, runner_type: :group_type, groups: [group], contacted_at: nil, created_at: 1.month.ago) create(:ci_runner, runner_type: :group_type, groups: [group], contacted_at: nil, created_at: 1.month.ago)
create(:plan_limits, :default_plan, ci_registered_group_runners: 1) create(:plan_limits, :default_plan, ci_registered_group_runners: 1)
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: ci_runner_limits_override)
end end
it 'does not create runner' do context 'with ci_runner_limits_override FF disabled' do
request let(:ci_runner_limits_override) { false }
it 'does not create runner' do
request
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('runner_namespaces.base' => ['Maximum number of ci registered group runners (1) exceeded']) expect(json_response['message']).to include('runner_namespaces.base' => ['Maximum number of ci registered group runners (1) exceeded'])
expect(group.runners.reload.size).to eq(1) expect(group.runners.reload.size).to eq(1)
end
end
context 'with ci_runner_limits_override FF enabled' do
let(:ci_runner_limits_override) { true }
it 'creates runner' do
request
expect(response).to have_gitlab_http_status(:created)
expect(json_response['message']).to be_nil
expect(group.runners.reload.size).to eq(2)
end
end end
end end
...@@ -198,6 +239,9 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -198,6 +239,9 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
create(:ci_runner, runner_type: :group_type, groups: [group], created_at: 4.months.ago, contacted_at: 3.months.ago) create(:ci_runner, runner_type: :group_type, groups: [group], created_at: 4.months.ago, contacted_at: 3.months.ago)
create(:ci_runner, runner_type: :group_type, groups: [group], contacted_at: nil, created_at: 4.months.ago) create(:ci_runner, runner_type: :group_type, groups: [group], contacted_at: nil, created_at: 4.months.ago)
create(:plan_limits, :default_plan, ci_registered_group_runners: 1) create(:plan_limits, :default_plan, ci_registered_group_runners: 1)
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: false)
end end
it 'creates runner' do it 'creates runner' do
......
...@@ -1003,13 +1003,31 @@ RSpec.describe API::Ci::Runners do ...@@ -1003,13 +1003,31 @@ RSpec.describe API::Ci::Runners do
context 'when it exceeds the application limits' do context 'when it exceeds the application limits' do
before do before do
create(:plan_limits, :default_plan, ci_registered_project_runners: 1) create(:plan_limits, :default_plan, ci_registered_project_runners: 1)
skip_default_enabled_yaml_check
stub_feature_flags(ci_runner_limits_override: ci_runner_limits_override)
end end
it 'does not enable specific runner' do context 'with ci_runner_limits_override FF disabled' do
expect do let(:ci_runner_limits_override) { false }
post api("/projects/#{project.id}/runners", admin), params: { runner_id: new_project_runner.id }
end.not_to change { project.runners.count } it 'does not enable specific runner' do
expect(response).to have_gitlab_http_status(:bad_request) expect do
post api("/projects/#{project.id}/runners", admin), params: { runner_id: new_project_runner.id }
end.not_to change { project.runners.count }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
context 'with ci_runner_limits_override FF enabled' do
let(:ci_runner_limits_override) { true }
it 'enables specific runner' do
expect do
post api("/projects/#{project.id}/runners", admin), params: { runner_id: new_project_runner.id }
end.to change { project.runners.count }
expect(response).to have_gitlab_http_status(:created)
end
end end
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