2018-08-03 17:22:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-04 22:35:41 +00:00
|
|
|
module DeploymentPlatform
|
2018-03-26 22:14:23 +00:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2018-03-07 10:14:25 +00:00
|
|
|
def deployment_platform(environment: nil)
|
2018-03-26 22:14:23 +00:00
|
|
|
@deployment_platform ||= {}
|
|
|
|
|
|
|
|
@deployment_platform[environment] ||= find_deployment_platform(environment)
|
2018-01-04 22:35:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-10-14 12:06:14 +00:00
|
|
|
def cluster_management_project_enabled?
|
2019-11-18 06:06:20 +00:00
|
|
|
Feature.enabled?(:cluster_management_project, self, default_enabled: true)
|
2019-10-14 12:06:14 +00:00
|
|
|
end
|
|
|
|
|
2018-03-26 22:14:23 +00:00
|
|
|
def find_deployment_platform(environment)
|
2019-07-16 23:37:34 +00:00
|
|
|
find_platform_kubernetes_with_cte(environment) ||
|
2019-06-27 12:29:19 +00:00
|
|
|
find_instance_cluster_platform_kubernetes(environment: environment)
|
2018-03-26 22:14:23 +00:00
|
|
|
end
|
|
|
|
|
2020-07-08 12:09:33 +00:00
|
|
|
def find_platform_kubernetes_with_cte(environment)
|
|
|
|
if environment
|
|
|
|
::Clusters::ClustersHierarchy.new(self, include_management_project: cluster_management_project_enabled?)
|
|
|
|
.base_and_ancestors
|
|
|
|
.enabled
|
|
|
|
.on_environment(environment, relevant_only: true)
|
|
|
|
.first&.platform_kubernetes
|
|
|
|
else
|
|
|
|
Clusters::ClustersHierarchy.new(self, include_management_project: cluster_management_project_enabled?).base_and_ancestors
|
2019-07-08 06:03:09 +00:00
|
|
|
.enabled.default_environment
|
|
|
|
.first&.platform_kubernetes
|
2020-07-08 12:09:33 +00:00
|
|
|
end
|
2019-07-08 06:03:09 +00:00
|
|
|
end
|
|
|
|
|
2019-04-18 02:45:31 +00:00
|
|
|
def find_instance_cluster_platform_kubernetes(environment: nil)
|
2020-07-08 12:09:33 +00:00
|
|
|
if environment
|
|
|
|
::Clusters::Instance.new.clusters.enabled.on_environment(environment, relevant_only: true)
|
2019-04-18 02:45:31 +00:00
|
|
|
.first&.platform_kubernetes
|
2020-07-08 12:09:33 +00:00
|
|
|
else
|
|
|
|
Clusters::Instance.new.clusters.enabled.default_environment
|
|
|
|
.first&.platform_kubernetes
|
|
|
|
end
|
2019-04-18 02:45:31 +00:00
|
|
|
end
|
2018-01-04 22:35:41 +00:00
|
|
|
end
|