Commit 2de90321 authored by Thong Kuah's avatar Thong Kuah
Browse files

Unify into :group_clusters feature flag

With this MR, group clusters is now functional, so default to enabled.

Have a single setting on the root ancestor group to enabled or disable
group clusters feature as a whole
parent 25aaac800b56
......@@ -3,8 +3,8 @@
class Groups::ClustersController < Clusters::ClustersController
include ControllerWithCrossProjectAccessCheck
prepend_before_action :check_group_clusters_feature_flag!
prepend_before_action :group
prepend_before_action :check_group_clusters_feature_flag!
requires_cross_project_access
layout 'group'
......@@ -20,6 +20,10 @@ def group
end
def check_group_clusters_feature_flag!
render_404 unless Feature.enabled?(:group_clusters)
render_404 unless group_clusters_enabled?
end
def group_clusters_enabled?
group.group_clusters_enabled?
end
end
......@@ -140,7 +140,7 @@ def get_group_sidebar_links
can?(current_user, "read_group_#{resource}".to_sym, @group)
end
if can?(current_user, :read_cluster, @group) && Feature.enabled?(:group_clusters)
if can?(current_user, :read_cluster, @group) && @group.group_clusters_enabled?
links << :kubernetes
end
......
......@@ -25,7 +25,7 @@ def find_cluster_platform_kubernetes(environment: nil)
end
def find_group_cluster_platform_kubernetes_with_feature_guard(environment: nil)
return unless Feature.enabled?(:deploy_group_clusters, default_enabled: true)
return unless group_clusters_enabled?
find_group_cluster_platform_kubernetes(environment: environment)
end
......
......@@ -400,6 +400,10 @@ def runners_token
ensure_runners_token!
end
def group_clusters_enabled?
Feature.enabled?(:group_clusters, root_ancestor, default_enabled: true)
end
private
def update_two_factor_requirement
......
......@@ -243,7 +243,7 @@ def has_parent?
end
def root_ancestor
ancestors.reorder(nil).find_by(parent_id: nil)
self_and_ancestors.reorder(nil).find_by(parent_id: nil)
end
def subgroup?
......
......@@ -291,6 +291,8 @@ class Project < ActiveRecord::Base
delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_role, to: :team
delegate :add_master, to: :team # @deprecated
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings
delegate :group_clusters_enabled?, to: :group, allow_nil: true
delegate :root_ancestor, to: :namespace, allow_nil: true
# Validations
validates :creator, presence: true, on: :create
......
......@@ -69,8 +69,6 @@
let(:group) { group_cluster.group }
before do
stub_feature_flags(deploy_group_clusters: true)
project.update!(group: group)
end
......@@ -118,7 +116,7 @@
context 'feature flag disabled' do
before do
stub_feature_flags(deploy_group_clusters: false)
stub_feature_flags(group_clusters: false)
end
it 'returns nil' do
......
......@@ -745,4 +745,33 @@ def setup_group_members(group)
let(:uploader_class) { AttachmentUploader }
end
end
describe '#group_clusters_enabled?' do
before do
# Override global stub in spec/spec_helper.rb
expect(Feature).to receive(:enabled?).and_call_original
end
subject { group.group_clusters_enabled? }
it { is_expected.to be_truthy }
context 'explicitly disabled for root ancestor' do
before do
feature = Feature.get(:group_clusters)
feature.disable(group.root_ancestor)
end
it { is_expected.to be_falsey }
end
context 'explicitly disabled for root ancestor' do
before do
feature = Feature.get(:group_clusters)
feature.enable(group.root_ancestor)
end
it { is_expected.to be_truthy }
end
end
end
......@@ -721,6 +721,7 @@ def project_rugged(project)
deep_nested_group = create(:group, parent: nested_group)
very_deep_nested_group = create(:group, parent: deep_nested_group)
expect(root_group.root_ancestor).to eq(root_group)
expect(nested_group.root_ancestor).to eq(root_group)
expect(deep_nested_group.root_ancestor).to eq(root_group)
expect(very_deep_nested_group.root_ancestor).to eq(root_group)
......
......@@ -412,6 +412,8 @@
it { is_expected.to delegate_method(:members).to(:team).with_prefix(true) }
it { is_expected.to delegate_method(:name).to(:owner).with_prefix(true).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:group_clusters_enabled?).to(:group).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:root_ancestor).to(:namespace).with_arguments(allow_nil: true) }
end
describe '#to_reference_with_postfix' do
......@@ -2129,6 +2131,29 @@ def create_build(new_pipeline = pipeline, name = 'test')
end
end
describe '#root_ancestor' do
let(:project) { create(:project) }
subject { project.root_ancestor }
it { is_expected.to eq(project.namespace) }
context 'in a group' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
it { is_expected.to eq(group) }
end
context 'in a nested group', :nested_groups do
let(:root) { create(:group) }
let(:child) { create(:group, parent: root) }
let(:project) { create(:project, group: child) }
it { is_expected.to eq(root) }
end
end
describe '#lfs_enabled?' do
let(:project) { create(:project) }
......
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