File: deployment_platform.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (43 lines) | stat: -rw-r--r-- 1,292 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module DeploymentPlatform
  # rubocop:disable Gitlab/ModuleWithInstanceVariables
  def deployment_platform(environment: nil)
    return unless self.namespace.certificate_based_clusters_enabled?

    @deployment_platform ||= {}

    @deployment_platform[environment] ||= find_deployment_platform(environment)
  end

  private

  def find_deployment_platform(environment)
    find_platform_kubernetes_with_cte(environment) ||
      find_instance_cluster_platform_kubernetes(environment: environment)
  end

  def find_platform_kubernetes_with_cte(environment)
    if environment
      ::Clusters::ClustersHierarchy.new(self)
        .base_and_ancestors
        .enabled
        .on_environment(environment, relevant_only: true)
        .first&.platform_kubernetes
    else
      Clusters::ClustersHierarchy.new(self).base_and_ancestors
      .enabled.default_environment
      .first&.platform_kubernetes
    end
  end

  def find_instance_cluster_platform_kubernetes(environment: nil)
    if environment
      ::Clusters::Instance.new.clusters.enabled.on_environment(environment, relevant_only: true)
      .first&.platform_kubernetes
    else
      Clusters::Instance.new.clusters.enabled.default_environment
      .first&.platform_kubernetes
    end
  end
end