Commit 157d4746 authored by Thong Kuah's avatar Thong Kuah

EE scoping for cluster management projects

If the license allows, match the environment name to the cluster scope
for cluster management project as well.
parent 41e2e69b
...@@ -17,6 +17,7 @@ module DeploymentPlatform ...@@ -17,6 +17,7 @@ module DeploymentPlatform
find_instance_cluster_platform_kubernetes(environment: environment) find_instance_cluster_platform_kubernetes(environment: environment)
end end
# EE would override this and utilize environment argument
def find_management_cluster(_environment) def find_management_cluster(_environment)
management_clusters.enabled.default_environment.first&.platform_kubernetes management_clusters.enabled.default_environment.first&.platform_kubernetes
end end
......
...@@ -4,6 +4,14 @@ module EE ...@@ -4,6 +4,14 @@ module EE
module DeploymentPlatform module DeploymentPlatform
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :find_management_cluster
def find_management_cluster(environment)
management_clusters
.enabled
.on_environment(environment, relevant_only: true)
.first&.platform_kubernetes
end
override :find_platform_kubernetes_with_cte override :find_platform_kubernetes_with_cte
def find_platform_kubernetes_with_cte(environment) def find_platform_kubernetes_with_cte(environment)
return super unless environment && feature_available?(:multiple_clusters) return super unless environment && feature_available?(:multiple_clusters)
......
...@@ -51,6 +51,24 @@ describe EE::DeploymentPlatform do ...@@ -51,6 +51,24 @@ describe EE::DeploymentPlatform do
end end
end end
context 'multiple clusters use the same management project' do
let(:management_project) { create(:project, group: group) }
let!(:default_cluster) do
create(:cluster_for_group, groups: [group], environment_scope: '*', management_project: management_project)
end
let!(:cluster) do
create(:cluster_for_group, groups: [group], environment_scope: 'review/*', management_project: management_project)
end
let(:environment) { 'review/name' }
subject { management_project.deployment_platform(environment: environment) }
it_behaves_like 'matching environment scope'
end
context 'when project does not have a cluster but has group clusters' do context 'when project does not have a cluster but has group clusters' do
let!(:default_cluster) do let!(:default_cluster) do
create(:cluster, :provided_by_user, create(:cluster, :provided_by_user,
......
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