summaryrefslogtreecommitdiff
path: root/app/models/clusters/cluster.rb
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-29 15:28:36 +1300
committerThong Kuah <tkuah@gitlab.com>2018-12-05 10:16:44 +1300
commit5bb2814ae6eb45463bb1fa4c5ed5fdd376afa2ca (patch)
treeb8442b8ecaabd9db1e32dfe8fdcebd8ea93c8025 /app/models/clusters/cluster.rb
parentd3866fb48cdf640cd16d48b9825dba2c261a78f3 (diff)
downloadgitlab-ce-5bb2814ae6eb45463bb1fa4c5ed5fdd376afa2ca.tar.gz
Deploy to clusters for a project's groups
Look for matching clusters starting from the closest ancestor, then go up the ancestor tree. Then use Ruby to get clusters for each group in order. Not that efficient, considering we will doing up to `NUMBER_OF_ANCESTORS_ALLOWED` number of queries, but it's a finite number Explicitly order query by depth This allows us to control ordering explicitly and also to reverse the order which is useful to allow us to be consistent with Clusters::Cluster.on_environment (EE) which does reverse ordering. Puts querying group clusters behind Feature Flag. Just in case we have issues with performance, we can easily disable this
Diffstat (limited to 'app/models/clusters/cluster.rb')
-rw-r--r--app/models/clusters/cluster.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 13906c903b9..a3d26d62a22 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -86,6 +86,16 @@ module Clusters
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
+ # Returns an ordered list of group clusters order from clusters of closest
+ # group up to furthest ancestor group
+ def self.ordered_group_clusters_for_project(project_id)
+ project_groups = ::Group.joins(:projects).where(projects: { id: project_id })
+ hierarchy_groups = Gitlab::GroupHierarchy.new(project_groups)
+ .base_and_ancestors(depth: :desc)
+
+ hierarchy_groups.flat_map(&:clusters)
+ end
+
def status_name
if provider
provider.status_name