Commit c2f9d67a authored by Thong Kuah's avatar Thong Kuah

Add cluster_management_project feature flag

This should be safe to enable by default.

We also have a kwarg to includee the management project or not in
Clusters::ClustersHierarchy.
parent 61cd54b5
......@@ -4,8 +4,9 @@ module Clusters
class ClustersHierarchy
DEPTH_COLUMN = :depth
def initialize(clusterable)
def initialize(clusterable, include_management_project: true)
@clusterable = clusterable
@include_management_project = include_management_project
end
# Returns clusters in order from deepest to highest group
......@@ -24,7 +25,7 @@ module Clusters
private
attr_reader :clusterable
attr_reader :clusterable, :include_management_project
def recursive_cte
cte = Gitlab::SQL::RecursiveCTE.new(:clusters_cte)
......@@ -38,7 +39,7 @@ module Clusters
raise ArgumentError, "unknown type for #{clusterable}"
end
if clusterable.is_a?(::Project)
if clusterable.is_a?(::Project) && include_management_project
cte << management_clusters_query
end
......
......@@ -11,6 +11,10 @@ module DeploymentPlatform
private
def cluster_management_project_enabled?
Feature.enabled?(:cluster_management_project, default_enabled: true)
end
def find_deployment_platform(environment)
find_platform_kubernetes_with_cte(environment) ||
find_instance_cluster_platform_kubernetes(environment: environment)
......@@ -18,7 +22,7 @@ module DeploymentPlatform
# EE would override this and utilize environment argument
def find_platform_kubernetes_with_cte(_environment)
Clusters::ClustersHierarchy.new(self).base_and_ancestors
Clusters::ClustersHierarchy.new(self, include_management_project: cluster_management_project_enabled?).base_and_ancestors
.enabled.default_environment
.first&.platform_kubernetes
end
......
......@@ -8,7 +8,8 @@ module EE
def find_platform_kubernetes_with_cte(environment)
return super unless environment && feature_available?(:multiple_clusters)
::Clusters::ClustersHierarchy.new(self).base_and_ancestors
::Clusters::ClustersHierarchy.new(self, include_management_project: cluster_management_project_enabled?)
.base_and_ancestors
.enabled
.on_environment(environment, relevant_only: true)
.first&.platform_kubernetes
......
......@@ -4,8 +4,8 @@ require 'spec_helper'
describe Clusters::ClustersHierarchy do
describe '#base_and_ancestors' do
def base_and_ancestors(clusterable)
described_class.new(clusterable).base_and_ancestors
def base_and_ancestors(clusterable, include_management_project: true)
described_class.new(clusterable, include_management_project: include_management_project).base_and_ancestors
end
context 'project in nested group with clusters at every level' do
......@@ -56,6 +56,10 @@ describe Clusters::ClustersHierarchy do
expect(base_and_ancestors(management_project)).to eq([group_cluster])
end
it 'returns nothing if include_management_project is false' do
expect(base_and_ancestors(management_project, include_management_project: false)).to be_empty
end
it 'returns clusters for project' do
expect(base_and_ancestors(project)).to eq([project_cluster, group_cluster])
end
......
......@@ -15,8 +15,20 @@ describe DeploymentPlatform do
context 'when project is the cluster\'s management project ' do
let!(:cluster_with_management_project) { create(:cluster, :provided_by_user, management_project: project) }
it 'returns the managed cluster' do
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
context 'cluster_management_project feature is enabled' do
it 'returns the cluster with management project' do
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
end
end
context 'cluster_management_project feature is disabled' do
before do
stub_feature_flags(cluster_management_project: false)
end
it 'returns nothing' do
is_expected.to be_nil
end
end
end
......@@ -56,8 +68,20 @@ describe DeploymentPlatform do
context 'when project is the cluster\'s management project ' do
let!(:cluster_with_management_project) { create(:cluster, :provided_by_user, management_project: project) }
it 'returns the managed cluster' do
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
context 'cluster_management_project feature is enabled' do
it 'returns the cluster with management project' do
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
end
end
context 'cluster_management_project feature is disabled' do
before do
stub_feature_flags(cluster_management_project: false)
end
it 'returns the group cluster' do
is_expected.to eq(group_cluster.platform_kubernetes)
end
end
end
......
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