Commit ecae79c3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Implement pipeline size limit class

parent f645ce7a
......@@ -325,6 +325,10 @@ module Ci
@stage_seeds ||= config_processor.stage_seeds(self)
end
def seeds_size
@seeds_size ||= stage_seeds.sum(&:size)
end
def has_kubernetes_active?
project.kubernetes_service&.active?
end
......
module EE
module Gitlab
module Ci
module Pipeline
module Quota
class Size < Ci::Limit
include ActionView::Helpers::TextHelper
def initialize(namespace, pipeline)
@namespace = namespace
@pipeline = pipeline
end
def enabled?
@namespace.max_pipeline_size > 0
end
def exceeded?
return false unless enabled?
excessive_seeds_count > 0
end
def message
return unless exceeded?
'Pipeline size limit exceeded by ' \
"#{pluralize(excessive_seeds_count, 'job')}!"
end
private
def excessive_seeds_count
@excessive ||= @pipeline.seeds_size - @namespace.max_pipeline_size
end
end
end
end
end
end
end
......@@ -3,7 +3,9 @@ module Gitlab
module Stage
class Seed
attr_reader :pipeline
delegate :project, to: :pipeline
delegate :size, to: :@jobs
def initialize(pipeline, stage, jobs)
@pipeline = pipeline
......
require 'spec_helper'
describe EE::Gitlab::Ci::Pipeline::Quota::Size do
set(:namespace) { create(:namespace, plan: EE::Namespace::GOLD_PLAN) }
set(:project) { create(:project, namespace: namespace) }
let(:pipeline) { build_stubbed(:ci_pipeline, project: project) }
let(:limit) { described_class.new(namespace, pipeline) }
shared_context 'pipeline size limit exceeded' do
let(:pipeline) do
config = { rspec: { script: 'rspec' },
spinach: { script: 'spinach' } }
build(:ci_pipeline, project: project, config: config)
end
before do
namespace.plan.update_column(:pipeline_size_limit, 1)
end
end
shared_context 'pipeline size limit not exceeded' do
let(:pipeline) { build(:ci_pipeline_with_one_job, project: project) }
before do
namespace.plan.update_column(:pipeline_size_limit, 2)
end
end
describe '#enabled?' do
context 'when limit is enabled in plan' do
before do
namespace.plan.update_column(:pipeline_size_limit, 10)
end
it 'is enabled' do
expect(limit).to be_enabled
end
end
context 'when limit is not enabled' do
before do
namespace.plan.update_column(:pipeline_size_limit, 0)
end
it 'is not enabled' do
expect(limit).not_to be_enabled
end
end
end
describe '#exceeded?' do
context 'when limit is exceeded' do
include_context 'pipeline size limit exceeded'
it 'is exceeded' do
expect(limit).to be_exceeded
end
end
context 'when limit is not exceeded' do
include_context 'pipeline size limit not exceeded'
it 'is not exceeded' do
expect(limit).not_to be_exceeded
end
end
end
describe '#message' do
context 'when limit is exceeded' do
include_context 'pipeline size limit exceeded'
it 'returns infor about pipeline size limit exceeded' do
expect(limit.message)
.to eq "Pipeline size limit exceeded by 1 job!"
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