Commit 45201f79 authored by Mayra Cabrera's avatar Mayra Cabrera

Rearrange DeploymentPlatform methods

- Change cluster factory to use default_environment
- Add a constant on cluster to declare default environment
- Change find_cluster_platform_kubernetes to search for a specific
  environment on EE, and ignore environment argument on CE
- Override find_cluster_platform_kubernetes and deployment_platform
  methods
- Remove memoization frmo deployment_platform on EE, otherwise when
  searching for a another platform, once the first one is assigned,
environment parameter is completely ignored
parent 3613fed3
......@@ -11,6 +11,7 @@ module Clusters
Applications::Prometheus.application_name => Applications::Prometheus,
Applications::Runner.application_name => Applications::Runner
}.freeze
DEFAULT_ENVIRONMENT = '*'.freeze
belongs_to :user
......@@ -52,6 +53,7 @@ module Clusters
scope :enabled, -> { where(enabled: true) }
scope :disabled, -> { where(enabled: false) }
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
def status_name
if provider
......
module DeploymentPlatform
# EE would override this and utilize the extra argument
# EE would override this and utilize environment argument
def deployment_platform(environment: nil)
@deployment_platform ||=
find_cluster_platform_kubernetes ||
find_cluster_platform_kubernetes(environment: environment) ||
find_kubernetes_service_integration ||
build_cluster_and_deployment_platform
end
private
def find_cluster_platform_kubernetes
clusters.find_by(enabled: true)&.platform_kubernetes
# EE would override this and utilize environment argument
def find_cluster_platform_kubernetes(environment: nil)
clusters.enabled.default_environment
.last&.platform_kubernetes
end
def find_kubernetes_service_integration
......
......@@ -4,13 +4,19 @@ module EE
override :deployment_platform
def deployment_platform(environment: nil)
find_cluster_platform_kubernetes(environment: environment) ||
find_kubernetes_service_integration ||
build_cluster_and_deployment_platform
end
private
override :find_cluster_platform_kubernetes
def find_cluster_platform_kubernetes(environment: nil)
return super unless environment && feature_available?(:multiple_clusters)
@deployment_platform = # rubocop:disable Gitlab/ModuleWithInstanceVariables
clusters.enabled.on_environment(environment.name)
.last&.platform_kubernetes
super # Wildcard or KubernetesService
end
end
end
......@@ -2,7 +2,7 @@ FactoryBot.define do
factory :cluster, class: Clusters::Cluster do
user
name 'test-cluster'
sequence(:environment_scope) { |n| "production#{n}/*" }
environment_scope Clusters::Cluster::DEFAULT_ENVIRONMENT
trait :project do
before(:create) do |cluster, evaluator|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment