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 ...@@ -11,6 +11,7 @@ module Clusters
Applications::Prometheus.application_name => Applications::Prometheus, Applications::Prometheus.application_name => Applications::Prometheus,
Applications::Runner.application_name => Applications::Runner Applications::Runner.application_name => Applications::Runner
}.freeze }.freeze
DEFAULT_ENVIRONMENT = '*'.freeze
belongs_to :user belongs_to :user
...@@ -52,6 +53,7 @@ module Clusters ...@@ -52,6 +53,7 @@ module Clusters
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :disabled, -> { where(enabled: false) } scope :disabled, -> { where(enabled: false) }
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
def status_name def status_name
if provider if provider
......
module DeploymentPlatform module DeploymentPlatform
# EE would override this and utilize the extra argument # EE would override this and utilize environment argument
def deployment_platform(environment: nil) def deployment_platform(environment: nil)
@deployment_platform ||= @deployment_platform ||=
find_cluster_platform_kubernetes || find_cluster_platform_kubernetes(environment: environment) ||
find_kubernetes_service_integration || find_kubernetes_service_integration ||
build_cluster_and_deployment_platform build_cluster_and_deployment_platform
end end
private private
def find_cluster_platform_kubernetes # EE would override this and utilize environment argument
clusters.find_by(enabled: true)&.platform_kubernetes def find_cluster_platform_kubernetes(environment: nil)
clusters.enabled.default_environment
.last&.platform_kubernetes
end end
def find_kubernetes_service_integration def find_kubernetes_service_integration
......
...@@ -4,13 +4,19 @@ module EE ...@@ -4,13 +4,19 @@ module EE
override :deployment_platform override :deployment_platform
def deployment_platform(environment: nil) def deployment_platform(environment: nil)
return super unless environment && feature_available?(:multiple_clusters) find_cluster_platform_kubernetes(environment: environment) ||
find_kubernetes_service_integration ||
build_cluster_and_deployment_platform
end
@deployment_platform = # rubocop:disable Gitlab/ModuleWithInstanceVariables private
clusters.enabled.on_environment(environment.name)
.last&.platform_kubernetes override :find_cluster_platform_kubernetes
def find_cluster_platform_kubernetes(environment: nil)
return super unless environment && feature_available?(:multiple_clusters)
super # Wildcard or KubernetesService clusters.enabled.on_environment(environment.name)
.last&.platform_kubernetes
end end
end end
end end
...@@ -2,7 +2,7 @@ FactoryBot.define do ...@@ -2,7 +2,7 @@ FactoryBot.define do
factory :cluster, class: Clusters::Cluster do factory :cluster, class: Clusters::Cluster do
user user
name 'test-cluster' name 'test-cluster'
sequence(:environment_scope) { |n| "production#{n}/*" } environment_scope Clusters::Cluster::DEFAULT_ENVIRONMENT
trait :project do trait :project do
before(:create) do |cluster, evaluator| 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