Commit ebf87fd9 authored by Thong Kuah's avatar Thong Kuah

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 f85440e6
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
class Groups::ClustersController < Clusters::ClustersController class Groups::ClustersController < Clusters::ClustersController
include ControllerWithCrossProjectAccessCheck include ControllerWithCrossProjectAccessCheck
prepend_before_action :check_group_clusters_feature_flag!
prepend_before_action :group prepend_before_action :group
prepend_before_action :check_group_clusters_feature_flag!
requires_cross_project_access requires_cross_project_access
layout 'group' layout 'group'
...@@ -20,6 +20,10 @@ class Groups::ClustersController < Clusters::ClustersController ...@@ -20,6 +20,10 @@ class Groups::ClustersController < Clusters::ClustersController
end end
def check_group_clusters_feature_flag! 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
end end
...@@ -140,7 +140,7 @@ module GroupsHelper ...@@ -140,7 +140,7 @@ module GroupsHelper
can?(current_user, "read_group_#{resource}".to_sym, @group) can?(current_user, "read_group_#{resource}".to_sym, @group)
end 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 links << :kubernetes
end end
......
...@@ -25,7 +25,7 @@ module DeploymentPlatform ...@@ -25,7 +25,7 @@ module DeploymentPlatform
end end
def find_group_cluster_platform_kubernetes_with_feature_guard(environment: nil) 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) find_group_cluster_platform_kubernetes(environment: environment)
end end
......
...@@ -400,6 +400,10 @@ class Group < Namespace ...@@ -400,6 +400,10 @@ class Group < Namespace
ensure_runners_token! ensure_runners_token!
end end
def group_clusters_enabled?
Feature.enabled?(:group_clusters, root_ancestor, default_enabled: true)
end
private private
def update_two_factor_requirement def update_two_factor_requirement
......
...@@ -243,7 +243,7 @@ class Namespace < ActiveRecord::Base ...@@ -243,7 +243,7 @@ class Namespace < ActiveRecord::Base
end end
def root_ancestor def root_ancestor
ancestors.reorder(nil).find_by(parent_id: nil) self_and_ancestors.reorder(nil).find_by(parent_id: nil)
end end
def subgroup? def subgroup?
......
...@@ -291,6 +291,8 @@ class Project < ActiveRecord::Base ...@@ -291,6 +291,8 @@ class Project < ActiveRecord::Base
delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_role, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_role, to: :team
delegate :add_master, to: :team # @deprecated delegate :add_master, to: :team # @deprecated
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings 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 # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
......
...@@ -69,8 +69,6 @@ describe DeploymentPlatform do ...@@ -69,8 +69,6 @@ describe DeploymentPlatform do
let(:group) { group_cluster.group } let(:group) { group_cluster.group }
before do before do
stub_feature_flags(deploy_group_clusters: true)
project.update!(group: group) project.update!(group: group)
end end
...@@ -118,7 +116,7 @@ describe DeploymentPlatform do ...@@ -118,7 +116,7 @@ describe DeploymentPlatform do
context 'feature flag disabled' do context 'feature flag disabled' do
before do before do
stub_feature_flags(deploy_group_clusters: false) stub_feature_flags(group_clusters: false)
end end
it 'returns nil' do it 'returns nil' do
......
...@@ -745,4 +745,33 @@ describe Group do ...@@ -745,4 +745,33 @@ describe Group do
let(:uploader_class) { AttachmentUploader } let(:uploader_class) { AttachmentUploader }
end end
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 end
...@@ -721,6 +721,7 @@ describe Namespace do ...@@ -721,6 +721,7 @@ describe Namespace do
deep_nested_group = create(:group, parent: nested_group) deep_nested_group = create(:group, parent: nested_group)
very_deep_nested_group = create(:group, parent: deep_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(nested_group.root_ancestor).to eq(root_group)
expect(deep_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) expect(very_deep_nested_group.root_ancestor).to eq(root_group)
......
...@@ -412,6 +412,8 @@ describe Project do ...@@ -412,6 +412,8 @@ describe Project do
it { is_expected.to delegate_method(:members).to(:team).with_prefix(true) } 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(: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 end
describe '#to_reference_with_postfix' do describe '#to_reference_with_postfix' do
...@@ -2129,6 +2131,29 @@ describe Project do ...@@ -2129,6 +2131,29 @@ describe Project do
end end
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 describe '#lfs_enabled?' do
let(:project) { create(:project) } 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