Commit 292d2208 authored by Thong Kuah's avatar Thong Kuah

Add FE option for users to choose to create a fully RBAC-enabled cluster or not.

This is similar to the option in the Add Existing cluster form
parent a02e3530
...@@ -141,7 +141,8 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -141,7 +141,8 @@ class Projects::ClustersController < Projects::ApplicationController
:gcp_project_id, :gcp_project_id,
:zone, :zone,
:num_nodes, :num_nodes,
:machine_type :machine_type,
:legacy_abac
]).merge( ]).merge(
provider_type: :gcp, provider_type: :gcp,
platform_type: :kubernetes platform_type: :kubernetes
......
...@@ -25,16 +25,11 @@ module Clusters ...@@ -25,16 +25,11 @@ module Clusters
params[:provider_gcp_attributes].try do |provider| params[:provider_gcp_attributes].try do |provider|
provider[:access_token] = access_token provider[:access_token] = access_token
provider[:legacy_abac] = legacy_abac_value
end end
@cluster_params = params.merge(user: current_user, projects: [project]) @cluster_params = params.merge(user: current_user, projects: [project])
end end
def legacy_abac_value
!Feature.enabled?(:rbac_clusters)
end
def can_create_cluster? def can_create_cluster?
project.clusters.empty? project.clusters.empty?
end end
......
...@@ -61,5 +61,15 @@ ...@@ -61,5 +61,15 @@
%p.form-text.text-muted %p.form-text.text-muted
= s_('ClusterIntegration|Learn more about %{help_link_start_machine_type}machine types%{help_link_end} and %{help_link_start_pricing}pricing%{help_link_end}.').html_safe % { help_link_start_machine_type: help_link_start % { url: machine_type_link_url }, help_link_start_pricing: help_link_start % { url: pricing_link_url }, help_link_end: help_link_end } = s_('ClusterIntegration|Learn more about %{help_link_start_machine_type}machine types%{help_link_end} and %{help_link_start_pricing}pricing%{help_link_end}.').html_safe % { help_link_start_machine_type: help_link_start % { url: machine_type_link_url }, help_link_start_pricing: help_link_start % { url: pricing_link_url }, help_link_end: help_link_end }
- if rbac_clusters_feature_enabled?
.form-group
.form-check
= provider_gcp_field.check_box :legacy_abac, { class: 'form-check-input' }, false, true
= provider_gcp_field.label :legacy_abac, s_('ClusterIntegration|RBAC-enabled cluster (experimental)'), class: 'form-check-label label-bold'
.form-text.text-muted
= s_('ClusterIntegration|Enable this setting if using role-based access control (RBAC).')
= s_('ClusterIntegration|This option will allow you to install applications on RBAC clusters.')
= link_to _('More information'), help_page_path('user/project/clusters/index.md', anchor: 'role-based-access-control-rbac-experimental-support'), target: '_blank'
.form-group .form-group
= field.submit s_('ClusterIntegration|Create Kubernetes cluster'), class: 'js-gke-cluster-creation-submit btn btn-success', disabled: true = field.submit s_('ClusterIntegration|Create Kubernetes cluster'), class: 'js-gke-cluster-creation-submit btn btn-success', disabled: true
...@@ -37,5 +37,14 @@ ...@@ -37,5 +37,14 @@
= platform_kubernetes_field.label :namespace, s_('ClusterIntegration|Project namespace (optional, unique)') = platform_kubernetes_field.label :namespace, s_('ClusterIntegration|Project namespace (optional, unique)')
= platform_kubernetes_field.text_field :namespace, class: 'form-control', placeholder: s_('ClusterIntegration|Project namespace') = platform_kubernetes_field.text_field :namespace, class: 'form-control', placeholder: s_('ClusterIntegration|Project namespace')
- if rbac_clusters_feature_enabled?
.form-group
.form-check
= platform_kubernetes_field.check_box :authorization_type, { class: 'form-check-input', disabled: true }, 'rbac', 'abac'
= platform_kubernetes_field.label :authorization_type, s_('ClusterIntegration|RBAC-enabled cluster (experimental)'), class: 'form-check-label label-bold'
.form-text.text-muted
= s_('ClusterIntegration|Enable this setting if using role-based access control (RBAC).')
= s_('ClusterIntegration|This option will allow you to install applications on RBAC clusters.')
.form-group .form-group
= field.submit s_('ClusterIntegration|Save changes'), class: 'btn btn-success' = field.submit s_('ClusterIntegration|Save changes'), class: 'btn btn-success'
...@@ -170,12 +170,14 @@ describe Projects::ClustersController do ...@@ -170,12 +170,14 @@ describe Projects::ClustersController do
end end
describe 'POST create for new cluster' do describe 'POST create for new cluster' do
let(:legacy_abac_param) { 'true' }
let(:params) do let(:params) do
{ {
cluster: { cluster: {
name: 'new-cluster', name: 'new-cluster',
provider_gcp_attributes: { provider_gcp_attributes: {
gcp_project_id: 'gcp-project-12345' gcp_project_id: 'gcp-project-12345',
legacy_abac: legacy_abac_param
} }
} }
} }
...@@ -201,6 +203,18 @@ describe Projects::ClustersController do ...@@ -201,6 +203,18 @@ describe Projects::ClustersController do
expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) expect(response).to redirect_to(project_cluster_path(project, project.clusters.first))
expect(project.clusters.first).to be_gcp expect(project.clusters.first).to be_gcp
expect(project.clusters.first).to be_kubernetes expect(project.clusters.first).to be_kubernetes
expect(project.clusters.first.provider_gcp).to be_legacy_abac
end
context 'when legacy_abac param is false' do
let(:legacy_abac_param) { 'false' }
it 'creates a new cluster with legacy_abac_disabled' do
expect(ClusterProvisionWorker).to receive(:perform_async)
expect { go }.to change { Clusters::Cluster.count }
.and change { Clusters::Providers::Gcp.count }
expect(project.clusters.first.provider_gcp).not_to be_legacy_abac
end
end end
end end
......
...@@ -7,7 +7,8 @@ shared_context 'valid cluster create params' do ...@@ -7,7 +7,8 @@ shared_context 'valid cluster create params' do
gcp_project_id: 'gcp-project', gcp_project_id: 'gcp-project',
zone: 'us-central1-a', zone: 'us-central1-a',
num_nodes: 1, num_nodes: 1,
machine_type: 'machine_type-a' machine_type: 'machine_type-a',
legacy_abac: 'true'
} }
} }
end end
...@@ -50,16 +51,6 @@ shared_examples 'create cluster service success' do ...@@ -50,16 +51,6 @@ shared_examples 'create cluster service success' do
expect(subject.provider).to be_legacy_abac expect(subject.provider).to be_legacy_abac
expect(subject.platform).to be_nil expect(subject.platform).to be_nil
end end
context 'rbac_clusters feature is enabled' do
before do
stub_feature_flags(rbac_clusters: true)
end
it 'has legacy_abac false' do
expect(subject.provider).not_to be_legacy_abac
end
end
end end
shared_examples 'create cluster service error' do shared_examples 'create cluster service error' do
......
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