gitlab-org--gitlab-foss/app/models/concerns/deployment_platform.rb
Thong Kuah 3bc76511a0 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.
2019-07-08 06:03:09 +00:00

52 lines
1.7 KiB
Ruby

# frozen_string_literal: true
module DeploymentPlatform
# EE would override this and utilize environment argument
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def deployment_platform(environment: nil)
@deployment_platform ||= {}
@deployment_platform[environment] ||= find_deployment_platform(environment)
end
private
def find_deployment_platform(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
.last&.platform_kubernetes
end
# EE would override this and utilize environment argument
def find_group_cluster_platform_kubernetes(environment: nil)
Clusters::Cluster.enabled.default_environment.ancestor_clusters_for_clusterable(self)
.first&.platform_kubernetes
end
# EE would override this and utilize environment argument
def find_instance_cluster_platform_kubernetes(environment: nil)
Clusters::Instance.new.clusters.enabled.default_environment
.first&.platform_kubernetes
end
end