Commit 80975aa9 authored by Stan Hu's avatar Stan Hu

Merge branch 'unlimited-zero-minutes-fix-2' into 'master'

Respect namespaces with unlimited minutes

See merge request gitlab-org/gitlab!68599
parents aa5450e4 7eb5fc0b
...@@ -274,6 +274,11 @@ class Namespace < ApplicationRecord ...@@ -274,6 +274,11 @@ class Namespace < ApplicationRecord
projects.with_shared_runners.any? projects.with_shared_runners.any?
end end
# Internal Gitlab owned namespaces only (example: gitlab-org)
def unlimited_minutes?
shared_runners_minutes_limit == 0
end
def user_ids_for_project_authorizations def user_ids_for_project_authorizations
[owner_id] [owner_id]
end end
......
...@@ -77,6 +77,8 @@ module Ci ...@@ -77,6 +77,8 @@ module Ci
ServiceResponse.error(message: 'Feature not enabled') ServiceResponse.error(message: 'Feature not enabled')
elsif !build.running? elsif !build.running?
ServiceResponse.error(message: 'Build is not running') ServiceResponse.error(message: 'Build is not running')
elsif root_namespace.unlimited_minutes?
ServiceResponse.error(message: 'Namespace has unlimited minutes')
elsif !build.cost_factor_enabled? elsif !build.cost_factor_enabled?
ServiceResponse.error(message: 'Cost factor not enabled for build') ServiceResponse.error(message: 'Cost factor not enabled for build')
else else
......
...@@ -80,6 +80,14 @@ RSpec.describe Ci::Minutes::TrackLiveConsumptionService do ...@@ -80,6 +80,14 @@ RSpec.describe Ci::Minutes::TrackLiveConsumptionService do
it_behaves_like 'returns early', 'Cost factor not enabled for build' it_behaves_like 'returns early', 'Cost factor not enabled for build'
end end
context 'when namespace has unlimited minutes' do
before do
namespace.update!(shared_runners_minutes_limit: 0)
end
it_behaves_like 'returns early', 'Namespace has unlimited minutes'
end
context 'when build has not been tracked recently' do context 'when build has not been tracked recently' do
it 'considers the current consumption as zero' do it 'considers the current consumption as zero' do
response = subject response = subject
......
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