Commit acbceea7 authored by Tiger's avatar Tiger

Disable clusters controllers if :certificate_based_clusters is disabled

https://gitlab.com/gitlab-org/gitlab/-/issues/351675
parent 8908711a
......@@ -14,6 +14,7 @@ class Clusters::ClustersController < Clusters::BaseController
before_action :authorize_create_cluster!, only: [:new, :authorize_aws_role]
before_action :authorize_update_cluster!, only: [:update]
before_action :update_applications_status, only: [:cluster_status]
before_action :ensure_feature_enabled!, except: :index
helper_method :token_in_session
......@@ -172,7 +173,17 @@ class Clusters::ClustersController < Clusters::BaseController
private
def certificate_based_clusters_enabled?
Feature.enabled?(:certificate_based_clusters, clusterable, default_enabled: :yaml, type: :ops)
end
def ensure_feature_enabled!
render_404 unless certificate_based_clusters_enabled?
end
def cluster_list
return [] unless certificate_based_clusters_enabled?
finder = ClusterAncestorsFinder.new(clusterable.subject, current_user)
clusters = finder.execute
......
......@@ -27,6 +27,10 @@ RSpec.describe Admin::ClustersController do
create(:cluster, :disabled, :provided_by_gcp, :production_environment, :instance)
end
include_examples ':certificate_based_clusters feature flag index responses' do
let(:subject) { get_index }
end
it 'lists available clusters and displays html' do
get_index
......@@ -105,6 +109,10 @@ RSpec.describe Admin::ClustersController do
get :new, params: { provider: provider }
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality for new cluster' do
context 'when omniauth has been configured' do
let(:key) { 'secret-key' }
......@@ -226,6 +234,10 @@ RSpec.describe Admin::ClustersController do
post :create_gcp, params: params
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { post_create_gcp }
end
describe 'functionality' do
context 'when access token is valid' do
before do
......@@ -318,6 +330,10 @@ RSpec.describe Admin::ClustersController do
post :create_aws, params: params
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { post_create_aws }
end
it 'creates a new cluster' do
expect(ClusterProvisionWorker).to receive(:perform_async)
expect { post_create_aws }.to change { Clusters::Cluster.count }
......@@ -375,6 +391,10 @@ RSpec.describe Admin::ClustersController do
post :create_user, params: params
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { post_create_user }
end
describe 'functionality' do
context 'when creates a cluster' do
it 'creates a new cluster' do
......@@ -445,6 +465,10 @@ RSpec.describe Admin::ClustersController do
post :authorize_aws_role, params: params
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
before do
allow(Clusters::Aws::FetchCredentialsService).to receive(:new)
.and_return(double(execute: double))
......@@ -495,6 +519,10 @@ RSpec.describe Admin::ClustersController do
delete :clear_cache, params: { id: cluster }
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it 'deletes the namespaces associated with the cluster' do
expect { go }.to change { Clusters::KubernetesNamespace.count }
......@@ -520,6 +548,10 @@ RSpec.describe Admin::ClustersController do
format: :json
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { get_cluster_status }
end
describe 'functionality' do
it 'responds with matching schema' do
get_cluster_status
......@@ -555,6 +587,10 @@ RSpec.describe Admin::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { get_show }
end
describe 'functionality' do
render_views
......@@ -603,6 +639,10 @@ RSpec.describe Admin::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { put_update }
end
it 'updates and redirects back to show page' do
put_update
......@@ -694,6 +734,10 @@ RSpec.describe Admin::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { delete_destroy }
end
describe 'functionality' do
context 'when cluster is provided by GCP' do
context 'when cluster is created' do
......
......@@ -32,6 +32,10 @@ RSpec.describe Groups::ClustersController do
create(:cluster, :disabled, :provided_by_gcp, :production_environment, cluster_type: :group_type, groups: [group])
end
include_examples ':certificate_based_clusters feature flag index responses' do
let(:subject) { go }
end
it 'lists available clusters and renders html' do
go
......@@ -116,6 +120,10 @@ RSpec.describe Groups::ClustersController do
get :new, params: { group_id: group, provider: provider }
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality for new cluster' do
context 'when omniauth has been configured' do
let(:key) { 'secret-key' }
......@@ -255,6 +263,10 @@ RSpec.describe Groups::ClustersController do
post :create_gcp, params: params.merge(group_id: group)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when access token is valid' do
before do
......@@ -349,6 +361,10 @@ RSpec.describe Groups::ClustersController do
post :create_user, params: params.merge(group_id: group)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when creates a cluster' do
it 'creates a new cluster' do
......@@ -457,6 +473,10 @@ RSpec.describe Groups::ClustersController do
post :create_aws, params: params.merge(group_id: group)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { post_create_aws }
end
it 'creates a new cluster' do
expect(ClusterProvisionWorker).to receive(:perform_async)
expect { post_create_aws }.to change { Clusters::Cluster.count }
......@@ -519,6 +539,10 @@ RSpec.describe Groups::ClustersController do
post :authorize_aws_role, params: params.merge(group_id: group)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
before do
allow(Clusters::Aws::FetchCredentialsService).to receive(:new)
.and_return(double(execute: double))
......@@ -579,6 +603,10 @@ RSpec.describe Groups::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it 'deletes the namespaces associated with the cluster' do
expect { go }.to change { Clusters::KubernetesNamespace.count }
......@@ -611,6 +639,10 @@ RSpec.describe Groups::ClustersController do
format: :json
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
it 'responds with matching schema' do
go
......@@ -651,6 +683,10 @@ RSpec.describe Groups::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
render_views
......@@ -705,6 +741,10 @@ RSpec.describe Groups::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it 'updates and redirects back to show page' do
go
......@@ -802,6 +842,10 @@ RSpec.describe Groups::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when cluster is provided by GCP' do
context 'when cluster is created' do
......
......@@ -26,6 +26,10 @@ RSpec.describe Projects::ClustersController do
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, projects: [project]) }
include_examples ':certificate_based_clusters feature flag index responses' do
let(:subject) { go }
end
it 'lists available clusters and renders html' do
go
......@@ -118,6 +122,10 @@ RSpec.describe Projects::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality for new cluster' do
context 'when omniauth has been configured' do
let(:key) { 'secret-key' }
......@@ -264,6 +272,10 @@ RSpec.describe Projects::ClustersController do
post :create_gcp, params: params.merge(namespace_id: project.namespace, project_id: project)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when access token is valid' do
before do
......@@ -360,6 +372,10 @@ RSpec.describe Projects::ClustersController do
post :create_user, params: params.merge(namespace_id: project.namespace, project_id: project)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when creates a cluster' do
it 'creates a new cluster' do
......@@ -477,6 +493,10 @@ RSpec.describe Projects::ClustersController do
post :create_aws, params: params.merge(namespace_id: project.namespace, project_id: project)
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { post_create_aws }
end
it 'creates a new cluster' do
expect(ClusterProvisionWorker).to receive(:perform_async)
expect { post_create_aws }.to change { Clusters::Cluster.count }
......@@ -548,6 +568,10 @@ RSpec.describe Projects::ClustersController do
.and_return(double(execute: double))
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it 'updates the associated role with the supplied ARN' do
go
......@@ -603,6 +627,10 @@ RSpec.describe Projects::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it 'deletes the namespaces associated with the cluster' do
expect { go }.to change { Clusters::KubernetesNamespace.count }
......@@ -640,6 +668,10 @@ RSpec.describe Projects::ClustersController do
format: :json
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
it "responds with matching schema" do
go
......@@ -685,6 +717,10 @@ RSpec.describe Projects::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
render_views
......@@ -749,6 +785,10 @@ RSpec.describe Projects::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
it "updates and redirects back to show page" do
go
......@@ -842,6 +882,10 @@ RSpec.describe Projects::ClustersController do
}
end
include_examples ':certificate_based_clusters feature flag controller responses' do
let(:subject) { go }
end
describe 'functionality' do
context 'when cluster is provided by GCP' do
context 'when cluster is created' do
......
......@@ -27,3 +27,33 @@ RSpec.shared_examples 'GET new cluster shared examples' do
end
end
end
RSpec.shared_examples ':certificate_based_clusters feature flag index responses' do
context 'feature flag is disabled' do
before do
stub_feature_flags(certificate_based_clusters: false)
end
it 'does not list any clusters' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
expect(assigns(:clusters)).to be_empty
end
end
end
RSpec.shared_examples ':certificate_based_clusters feature flag controller responses' do
context 'feature flag is disabled' do
before do
stub_feature_flags(certificate_based_clusters: false)
end
it 'responds with :not_found' do
subject
expect(response).to have_gitlab_http_status(:not_found)
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