Commit 33651e72 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by ayufanpl

Account shared runner minutes to top-level namespace

parent 497a2070
...@@ -500,6 +500,10 @@ class Project < ActiveRecord::Base ...@@ -500,6 +500,10 @@ class Project < ActiveRecord::Base
.base_and_ancestors(upto: top) .base_and_ancestors(upto: top)
end end
def top_level_ancestor
@top_level_ancestor ||= ancestors_upto.last
end
def lfs_enabled? def lfs_enabled?
return namespace.lfs_enabled? if self[:lfs_enabled].nil? return namespace.lfs_enabled? if self[:lfs_enabled].nil?
......
- if project.namespace.shared_runners_minutes_used? - if project.shared_runners_limit_namespace.shared_runners_minutes_used?
- quota_used = project.namespace.shared_runners_minutes - quota_used = project.shared_runners_limit_namespace.shared_runners_minutes
- quota_limit = project.namespace.actual_shared_runners_minutes_limit - quota_limit = project.shared_runners_limit_namespace.actual_shared_runners_minutes_limit
.bs-callout.bs-callout-warning .bs-callout.bs-callout-warning
%p %p
You have used all your shared Runners pipeline minutes. You have used all your shared Runners pipeline minutes.
......
- project = local_assigns.fetch(:project, nil) - project = local_assigns.fetch(:project, nil)
- namespace = local_assigns.fetch(:namespace, project && project.namespace) - namespace = local_assigns.fetch(:namespace, project && project.shared_runners_limit_namespace)
- scope = (project || namespace).full_path - scope = (project || namespace).full_path
- has_limit = (project || namespace).shared_runners_minutes_limit_enabled? - has_limit = (project || namespace).shared_runners_minutes_limit_enabled?
- can_see_status = project.nil? || can?(current_user, :create_pipeline, project) - can_see_status = project.nil? || can?(current_user, :create_pipeline, project)
......
---
title: Account shared runner minutes to top-level namespace
merge_request:
author:
type: fixed
...@@ -4,6 +4,16 @@ class Groups::PipelineQuotaController < Groups::ApplicationController ...@@ -4,6 +4,16 @@ class Groups::PipelineQuotaController < Groups::ApplicationController
layout 'group_settings' layout 'group_settings'
def index def index
@projects = @group.projects.with_shared_runners_limit_enabled.page(params[:page]) @projects = all_projects.with_shared_runners_limit_enabled.page(params[:page])
end
private
def all_projects
if Feature.enabled?(:account_on_namespace)
@group.all_projects
else
@group.projects
end
end end
end end
...@@ -54,7 +54,7 @@ module EE ...@@ -54,7 +54,7 @@ module EE
to: :statistics, allow_nil: true to: :statistics, allow_nil: true
delegate :actual_shared_runners_minutes_limit, delegate :actual_shared_runners_minutes_limit,
:shared_runners_minutes_used?, to: :namespace :shared_runners_minutes_used?, to: :shared_runners_limit_namespace
validates :repository_size_limit, validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true } numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
...@@ -82,6 +82,14 @@ module EE ...@@ -82,6 +82,14 @@ module EE
end end
end end
def shared_runners_limit_namespace
if Feature.enabled?(:account_on_namespace)
top_level_ancestor
else
namespace
end
end
def mirror def mirror
super && feature_available?(:repository_mirrors) super && feature_available?(:repository_mirrors)
end end
...@@ -190,11 +198,12 @@ module EE ...@@ -190,11 +198,12 @@ module EE
end end
def shared_runners_available? def shared_runners_available?
super && !namespace.shared_runners_minutes_used? super && !shared_runners_limit_namespace.shared_runners_minutes_used?
end end
def shared_runners_minutes_limit_enabled? def shared_runners_minutes_limit_enabled?
!public? && shared_runners_enabled? && namespace.shared_runners_minutes_limit_enabled? !public? && shared_runners_enabled? &&
shared_runners_limit_namespace.shared_runners_minutes_limit_enabled?
end end
def feature_available?(feature, user = nil) def feature_available?(feature, user = nil)
......
...@@ -17,8 +17,7 @@ module EE ...@@ -17,8 +17,7 @@ module EE
end end
def builds_check_limit def builds_check_limit
::Namespace.reorder(nil) all_namespaces
.where('namespaces.id = projects.namespace_id')
.joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id') .joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id')
.where('COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR ' \ .where('COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR ' \
'COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60', 'COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60',
...@@ -26,6 +25,16 @@ module EE ...@@ -26,6 +25,16 @@ module EE
.select('1') .select('1')
end end
def all_namespaces
if Feature.enabled?(:account_on_namespace)
::Gitlab::GroupHierarchy.new(::Namespace.where('namespaces.id = projects.namespace_id'))
.roots
else
::Namespace.reorder(nil)
.where('namespaces.id = projects.namespace_id')
end
end
def application_shared_runners_minutes def application_shared_runners_minutes
current_application_settings.shared_runners_minutes current_application_settings.shared_runners_minutes
end end
......
...@@ -22,6 +22,10 @@ class UpdateBuildMinutesService < BaseService ...@@ -22,6 +22,10 @@ class UpdateBuildMinutesService < BaseService
end end
def namespace def namespace
project.namespace if Feature.enabled(:account_on_top_level)
project.namespace.top_level_parent
else
project.namespace
end
end end
end end
...@@ -33,6 +33,10 @@ module Gitlab ...@@ -33,6 +33,10 @@ module Gitlab
base_and_ancestors(upto: upto).where.not(id: ancestors_base.select(:id)) base_and_ancestors(upto: upto).where.not(id: ancestors_base.select(:id))
end end
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# Returns a relation that includes the ancestors_base set of groups # Returns a relation that includes the ancestors_base set of groups
# and all their ancestors (recursively). # and all their ancestors (recursively).
# #
......
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