diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-07-08 06:03:09 +0000 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-07-08 06:03:09 +0000 |
commit | 3bc76511a066626c06d3d3b76d78e928770c46e0 (patch) | |
tree | b38a3712d31a3b74ce73eaefa71e8fb73d1e5718 /app/models/concerns | |
parent | 299387e311d30c50b060bc62141b4ff6b2cfefe8 (diff) | |
download | gitlab-ce-3bc76511a066626c06d3d3b76d78e928770c46e0.tar.gz |
Create CTE query for clusters hierarchy
- This enables us to use a scope to query all clusters in group
hierarchy order in one query, and also enables us to union to instance
clusters later.
- Handle case where clusters not present at level. In which case the
query should go ahead and return the next level's clusters.
- Swap with new CTE query behind Feature flag. This FF is default
disabled.
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/deployment_platform.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/app/models/concerns/deployment_platform.rb b/app/models/concerns/deployment_platform.rb index 5a358ae2ef6..8f28c897eb6 100644 --- a/app/models/concerns/deployment_platform.rb +++ b/app/models/concerns/deployment_platform.rb @@ -12,11 +12,26 @@ module DeploymentPlatform private def find_deployment_platform(environment) - find_cluster_platform_kubernetes(environment: environment) || - find_group_cluster_platform_kubernetes(environment: environment) || + find_platform_kubernetes(environment) || find_instance_cluster_platform_kubernetes(environment: environment) end + def find_platform_kubernetes(environment) + if Feature.enabled?(:clusters_cte) + find_platform_kubernetes_with_cte(environment) + else + find_cluster_platform_kubernetes(environment: environment) || + find_group_cluster_platform_kubernetes(environment: environment) + end + end + + # EE would override this and utilize environment argument + def find_platform_kubernetes_with_cte(_environment) + Clusters::ClustersHierarchy.new(self).base_and_ancestors + .enabled.default_environment + .first&.platform_kubernetes + end + # EE would override this and utilize environment argument def find_cluster_platform_kubernetes(environment: nil) clusters.enabled.default_environment |