debian-mirror-gitlab/app/models/concerns/deployment_platform.rb

46 lines
1.4 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module DeploymentPlatform
2018-05-01 15:08:00 +05:30
# rubocop:disable Gitlab/ModuleWithInstanceVariables
2018-03-27 19:54:05 +05:30
def deployment_platform(environment: nil)
2018-05-01 15:08:00 +05:30
@deployment_platform ||= {}
@deployment_platform[environment] ||= find_deployment_platform(environment)
2018-03-17 18:26:18 +05:30
end
private
2019-12-21 20:55:43 +05:30
def cluster_management_project_enabled?
2019-12-26 22:10:19 +05:30
Feature.enabled?(:cluster_management_project, self, default_enabled: true)
2019-12-21 20:55:43 +05:30
end
2018-05-01 15:08:00 +05:30
def find_deployment_platform(environment)
2019-09-30 21:07:59 +05:30
find_platform_kubernetes_with_cte(environment) ||
find_instance_cluster_platform_kubernetes(environment: environment)
2018-05-01 15:08:00 +05:30
end
2020-07-28 23:09:34 +05:30
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-09-30 21:07:59 +05:30
.enabled.default_environment
2019-02-15 15:39:39 +05:30
.first&.platform_kubernetes
2020-07-28 23:09:34 +05:30
end
2019-02-15 15:39:39 +05:30
end
2019-07-31 22:56:46 +05:30
def find_instance_cluster_platform_kubernetes(environment: nil)
2020-07-28 23:09:34 +05:30
if environment
::Clusters::Instance.new.clusters.enabled.on_environment(environment, relevant_only: true)
2019-07-31 22:56:46 +05:30
.first&.platform_kubernetes
2020-07-28 23:09:34 +05:30
else
Clusters::Instance.new.clusters.enabled.default_environment
.first&.platform_kubernetes
end
2019-07-31 22:56:46 +05:30
end
2018-03-17 18:26:18 +05:30
end