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

44 lines
1.3 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)
2022-07-16 23:28:13 +05:30
return unless self.namespace.certificate_based_clusters_enabled?
2022-05-07 20:08:51 +05:30
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
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
2021-09-04 01:27:46 +05:30
::Clusters::ClustersHierarchy.new(self)
2020-07-28 23:09:34 +05:30
.base_and_ancestors
.enabled
.on_environment(environment, relevant_only: true)
.first&.platform_kubernetes
else
2021-09-04 01:27:46 +05:30
Clusters::ClustersHierarchy.new(self).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