Commit 84b93b67 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'add-cloud-provider-selector-buttons' into 'master'

Add cloud provider selector buttons

See merge request gitlab-org/gitlab-ce!32302
parents 56342d88 90e3a491
...@@ -35,6 +35,12 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -35,6 +35,12 @@ class Clusters::ClustersController < Clusters::BaseController
end end
def new def new
return unless Feature.enabled?(:create_eks_clusters)
@gke_selected = params[:provider] == 'gke'
@eks_selected = params[:provider] == 'eks'
return redirect_to @authorize_url if @gke_selected && @authorize_url && !@valid_gcp_token
end end
# Overridding ActionController::Metal#status is NOT a good idea # Overridding ActionController::Metal#status is NOT a good idea
...@@ -99,7 +105,7 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -99,7 +105,7 @@ class Clusters::ClustersController < Clusters::BaseController
validate_gcp_token validate_gcp_token
user_cluster user_cluster
render :new, locals: { active_tab: 'gcp' } render :new, locals: { active_tab: 'create' }
end end
end end
...@@ -116,7 +122,7 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -116,7 +122,7 @@ class Clusters::ClustersController < Clusters::BaseController
validate_gcp_token validate_gcp_token
gcp_cluster gcp_cluster
render :new, locals: { active_tab: 'user' } render :new, locals: { active_tab: 'add' }
end end
end end
...@@ -189,7 +195,8 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -189,7 +195,8 @@ class Clusters::ClustersController < Clusters::BaseController
end end
def generate_gcp_authorize_url def generate_gcp_authorize_url
state = generate_session_key_redirect(clusterable.new_path.to_s) params = Feature.enabled?(:create_eks_clusters) ? { provider: :gke } : {}
state = generate_session_key_redirect(clusterable.new_path(params).to_s)
@authorize_url = GoogleApi::CloudPlatform::Client.new( @authorize_url = GoogleApi::CloudPlatform::Client.new(
nil, callback_google_api_auth_url, nil, callback_google_api_auth_url,
......
...@@ -25,8 +25,8 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated ...@@ -25,8 +25,8 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated
polymorphic_path([clusterable, :clusters]) polymorphic_path([clusterable, :clusters])
end end
def new_path def new_path(options = {})
new_polymorphic_path([clusterable, :cluster]) new_polymorphic_path([clusterable, :cluster], options)
end end
def create_user_clusters_path def create_user_clusters_path
......
...@@ -18,8 +18,8 @@ class InstanceClusterablePresenter < ClusterablePresenter ...@@ -18,8 +18,8 @@ class InstanceClusterablePresenter < ClusterablePresenter
end end
override :new_path override :new_path
def new_path def new_path(options = {})
new_admin_cluster_path new_admin_cluster_path(options)
end end
override :cluster_status_cluster_path override :cluster_status_cluster_path
......
- provider = local_assigns.fetch(:provider)
- logo_path = local_assigns.fetch(:logo_path)
- label = local_assigns.fetch(:label)
= link_to clusterable.new_path(provider: provider), class: 'btn gl-button btn-outline flex-fill d-inline-flex flex-column mr-3 justify-content-center align-items-center' do
= image_tag logo_path, alt: label, class: 'gl-w-13 gl-h-13'
%span
= label
- gke_label = s_('ClusterIntegration|Google GKE')
- eks_label = s_('ClusterIntegration|Amazon EKS')
- create_cluster_label = s_('ClusterIntegration|Create cluster on')
.d-flex.flex-column
%h5
= create_cluster_label
.d-flex
= render partial: 'clusters/clusters/cloud_providers/cloud_provider_button',
locals: { provider: 'gke', label: gke_label, logo_path: '' }
= render partial: 'clusters/clusters/cloud_providers/cloud_provider_button',
locals: { provider: 'eks', label: eks_label, logo_path: '' }
.js-create-eks-cluster-form-container
- breadcrumb_title _('Kubernetes') - breadcrumb_title _('Kubernetes')
- page_title _('Kubernetes Cluster') - page_title _('Kubernetes Cluster')
- active_tab = local_assigns.fetch(:active_tab, 'gcp') - create_eks_enabled = Feature.enabled?(:create_eks_clusters)
- active_tab = local_assigns.fetch(:active_tab, 'create')
- link_end = '<a/>'.html_safe
= javascript_include_tag 'https://apis.google.com/js/api.js' = javascript_include_tag 'https://apis.google.com/js/api.js'
= render_gcp_signup_offer = render_gcp_signup_offer
...@@ -11,26 +13,36 @@ ...@@ -11,26 +13,36 @@
.col-md-9.js-toggle-container .col-md-9.js-toggle-container
%ul.nav-links.nav-tabs.gitlab-tabs.nav{ role: 'tablist' } %ul.nav-links.nav-tabs.gitlab-tabs.nav{ role: 'tablist' }
%li.nav-item{ role: 'presentation' } %li.nav-item{ role: 'presentation' }
%a.nav-link{ href: '#create-gcp-cluster-pane', id: 'create-gcp-cluster-tab', class: active_when(active_tab == 'gcp'), data: { toggle: 'tab' }, role: 'tab' } %a.nav-link{ href: '#create-cluster-pane', id: 'create-cluster-tab', class: active_when(active_tab == 'create'), data: { toggle: 'tab' }, role: 'tab' }
%span Create new Cluster on GKE %span Create new Cluster on GKE
%li.nav-item{ role: 'presentation' } %li.nav-item{ role: 'presentation' }
%a.nav-link{ href: '#add-user-cluster-pane', id: 'add-user-cluster-tab', class: active_when(active_tab == 'user'), data: { toggle: 'tab' }, role: 'tab' } %a.nav-link{ href: '#add-cluster-pane', id: 'add-cluster-tab', class: active_when(active_tab == 'add'), data: { toggle: 'tab' }, role: 'tab' }
%span Add existing cluster %span Add existing cluster
.tab-content.gitlab-tab-content .tab-content.gitlab-tab-content
.tab-pane{ id: 'create-gcp-cluster-pane', class: active_when(active_tab == 'gcp'), role: 'tabpanel' } - if create_eks_enabled
= render 'clusters/clusters/gcp/header' .tab-pane{ id: 'create-cluster-pane', class: active_when(active_tab == 'create'), role: 'tabpanel' }
- if @valid_gcp_token - if @gke_selected && @valid_gcp_token
= render 'clusters/clusters/gcp/form' = render 'clusters/clusters/gcp/header'
- elsif @authorize_url = render 'clusters/clusters/gcp/form'
.signin-with-google - elsif @eks_selected
= link_to(image_tag('auth_buttons/signin_with_google.png', width: '191px'), @authorize_url) = render 'clusters/clusters/eks/index'
= _('or') - else
= link_to('create a new Google account', 'https://accounts.google.com/SignUpWithoutGmail?service=cloudconsole&continue=https%3A%2F%2Fconsole.cloud.google.com%2Ffreetrial%3Futm_campaign%3D2018_cpanel%26utm_source%3Dgitlab%26utm_medium%3Dreferral', target: '_blank', rel: 'noopener noreferrer') = render 'clusters/clusters/cloud_providers/cloud_provider_selector'
- else - else
- link = link_to(s_('ClusterIntegration|properly configured'), help_page_path("integration/google"), target: '_blank', rel: 'noopener noreferrer') .tab-pane{ id: 'create-cluster-pane', class: active_when(active_tab == 'create'), role: 'tabpanel' }
= s_('Google authentication is not %{link_to_documentation}. Ask your GitLab administrator if you want to use this service.').html_safe % { link_to_documentation: link } = render 'clusters/clusters/gcp/header'
- if @valid_gcp_token
= render 'clusters/clusters/gcp/form'
- elsif @authorize_url
.signin-with-google
- create_account_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: 'https://accounts.google.com/SignUpWithoutGmail?service=cloudconsole&continue=https%3A%2F%2Fconsole.cloud.google.com%2Ffreetrial%3Futm_campaign%3D2018_cpanel%26utm_source%3Dgitlab%26utm_medium%3Dreferral' }
= link_to(image_tag('auth_buttons/signin_with_google.png', width: '191px', alt: _('Sign in with Google')), @authorize_url)
= s_('or %{link_start}create a new Google account%{link_end}').html_safe % { link_start: create_account_link, link_end: link_end }
- else
- documentation_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path("integration/google") }
= s_('Google authentication is not %{link_start}property configured%{link_end}. Ask your GitLab administrator if you want to use this service.').html_safe % { link_start: documentation_link_start, link_end: link_end }
.tab-pane{ id: 'add-user-cluster-pane', class: active_when(active_tab == 'user'), role: 'tabpanel' } .tab-pane{ id: 'add-cluster-pane', class: active_when(active_tab == 'add'), role: 'tabpanel' }
= render 'clusters/clusters/user/header' = render 'clusters/clusters/user/header'
= render 'clusters/clusters/user/form' = render 'clusters/clusters/user/form'
...@@ -2530,6 +2530,9 @@ msgstr "" ...@@ -2530,6 +2530,9 @@ msgstr ""
msgid "ClusterIntegration|Alternatively" msgid "ClusterIntegration|Alternatively"
msgstr "" msgstr ""
msgid "ClusterIntegration|Amazon EKS"
msgstr ""
msgid "ClusterIntegration|An error occurred when trying to contact the Google Cloud API. Please try again later." msgid "ClusterIntegration|An error occurred when trying to contact the Google Cloud API. Please try again later."
msgstr "" msgstr ""
...@@ -2608,6 +2611,9 @@ msgstr "" ...@@ -2608,6 +2611,9 @@ msgstr ""
msgid "ClusterIntegration|Create Kubernetes cluster" msgid "ClusterIntegration|Create Kubernetes cluster"
msgstr "" msgstr ""
msgid "ClusterIntegration|Create cluster on"
msgstr ""
msgid "ClusterIntegration|Did you know?" msgid "ClusterIntegration|Did you know?"
msgstr "" msgstr ""
...@@ -2659,6 +2665,9 @@ msgstr "" ...@@ -2659,6 +2665,9 @@ msgstr ""
msgid "ClusterIntegration|Google Cloud Platform project" msgid "ClusterIntegration|Google Cloud Platform project"
msgstr "" msgstr ""
msgid "ClusterIntegration|Google GKE"
msgstr ""
msgid "ClusterIntegration|Google Kubernetes Engine" msgid "ClusterIntegration|Google Kubernetes Engine"
msgstr "" msgstr ""
...@@ -2989,9 +2998,6 @@ msgstr "" ...@@ -2989,9 +2998,6 @@ msgstr ""
msgid "ClusterIntegration|pricing" msgid "ClusterIntegration|pricing"
msgstr "" msgstr ""
msgid "ClusterIntegration|properly configured"
msgstr ""
msgid "ClusterIntegration|sign up" msgid "ClusterIntegration|sign up"
msgstr "" msgstr ""
...@@ -5518,7 +5524,7 @@ msgstr "" ...@@ -5518,7 +5524,7 @@ msgstr ""
msgid "Google Takeout" msgid "Google Takeout"
msgstr "" msgstr ""
msgid "Google authentication is not %{link_to_documentation}. Ask your GitLab administrator if you want to use this service." msgid "Google authentication is not %{link_start}property configured%{link_end}. Ask your GitLab administrator if you want to use this service."
msgstr "" msgstr ""
msgid "Got it" msgid "Got it"
...@@ -10565,6 +10571,9 @@ msgstr "" ...@@ -10565,6 +10571,9 @@ msgstr ""
msgid "Sign in via 2FA code" msgid "Sign in via 2FA code"
msgstr "" msgstr ""
msgid "Sign in with Google"
msgstr ""
msgid "Sign out" msgid "Sign out"
msgstr "" msgstr ""
...@@ -14180,7 +14189,7 @@ msgstr "" ...@@ -14180,7 +14189,7 @@ msgstr ""
msgid "nounSeries|%{item}, and %{lastItem}" msgid "nounSeries|%{item}, and %{lastItem}"
msgstr "" msgstr ""
msgid "or" msgid "or %{link_start}create a new Google account%{link_end}"
msgstr "" msgstr ""
msgid "out of %d total test" msgid "out of %d total test"
......
...@@ -73,8 +73,8 @@ describe Admin::ClustersController do ...@@ -73,8 +73,8 @@ describe Admin::ClustersController do
end end
describe 'GET #new' do describe 'GET #new' do
def get_new def get_new(provider: 'gke')
get :new get :new, params: { provider: provider }
end end
describe 'functionality for new cluster' do describe 'functionality for new cluster' do
...@@ -85,6 +85,7 @@ describe Admin::ClustersController do ...@@ -85,6 +85,7 @@ describe Admin::ClustersController do
end end
before do before do
stub_feature_flags(create_eks_clusters: false)
allow(SecureRandom).to receive(:hex).and_return(key) allow(SecureRandom).to receive(:hex).and_return(key)
end end
...@@ -94,6 +95,20 @@ describe Admin::ClustersController do ...@@ -94,6 +95,20 @@ describe Admin::ClustersController do
expect(assigns(:authorize_url)).to include(key) expect(assigns(:authorize_url)).to include(key)
expect(session[session_key_for_redirect_uri]).to eq(new_admin_cluster_path) expect(session[session_key_for_redirect_uri]).to eq(new_admin_cluster_path)
end end
context 'when create_eks_clusters feature flag is enabled' do
before do
stub_feature_flags(create_eks_clusters: true)
end
context 'when selected provider is gke and no valid gcp token exists' do
it 'redirects to gcp authorize_url' do
get_new
expect(response).to redirect_to(assigns(:authorize_url))
end
end
end
end end
context 'when omniauth has not configured' do context 'when omniauth has not configured' do
......
...@@ -85,8 +85,8 @@ describe Groups::ClustersController do ...@@ -85,8 +85,8 @@ describe Groups::ClustersController do
end end
describe 'GET new' do describe 'GET new' do
def go def go(provider: 'gke')
get :new, params: { group_id: group } get :new, params: { group_id: group, provider: provider }
end end
describe 'functionality for new cluster' do describe 'functionality for new cluster' do
...@@ -97,6 +97,7 @@ describe Groups::ClustersController do ...@@ -97,6 +97,7 @@ describe Groups::ClustersController do
end end
before do before do
stub_feature_flags(create_eks_clusters: false)
allow(SecureRandom).to receive(:hex).and_return(key) allow(SecureRandom).to receive(:hex).and_return(key)
end end
...@@ -106,6 +107,20 @@ describe Groups::ClustersController do ...@@ -106,6 +107,20 @@ describe Groups::ClustersController do
expect(assigns(:authorize_url)).to include(key) expect(assigns(:authorize_url)).to include(key)
expect(session[session_key_for_redirect_uri]).to eq(new_group_cluster_path(group)) expect(session[session_key_for_redirect_uri]).to eq(new_group_cluster_path(group))
end end
context 'when create_eks_clusters feature flag is enabled' do
before do
stub_feature_flags(create_eks_clusters: true)
end
context 'when selected provider is gke and no valid gcp token exists' do
it 'redirects to gcp authorize_url' do
go
expect(response).to redirect_to(assigns(:authorize_url))
end
end
end
end end
context 'when omniauth has not configured' do context 'when omniauth has not configured' do
......
...@@ -79,8 +79,12 @@ describe Projects::ClustersController do ...@@ -79,8 +79,12 @@ describe Projects::ClustersController do
end end
describe 'GET new' do describe 'GET new' do
def go def go(provider: 'gke')
get :new, params: { namespace_id: project.namespace, project_id: project } get :new, params: {
namespace_id: project.namespace,
project_id: project,
provider: provider
}
end end
describe 'functionality for new cluster' do describe 'functionality for new cluster' do
...@@ -91,6 +95,7 @@ describe Projects::ClustersController do ...@@ -91,6 +95,7 @@ describe Projects::ClustersController do
end end
before do before do
stub_feature_flags(create_eks_clusters: false)
allow(SecureRandom).to receive(:hex).and_return(key) allow(SecureRandom).to receive(:hex).and_return(key)
end end
...@@ -100,6 +105,20 @@ describe Projects::ClustersController do ...@@ -100,6 +105,20 @@ describe Projects::ClustersController do
expect(assigns(:authorize_url)).to include(key) expect(assigns(:authorize_url)).to include(key)
expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project)) expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project))
end end
context 'when create_eks_clusters feature flag is enabled' do
before do
stub_feature_flags(create_eks_clusters: true)
end
context 'when selected provider is gke and no valid gcp token exists' do
it 'redirects to gcp authorize_url' do
go
expect(response).to redirect_to(assigns(:authorize_url))
end
end
end
end end
context 'when omniauth has not configured' do context 'when omniauth has not configured' do
......
...@@ -18,6 +18,8 @@ describe 'Gcp Cluster', :js do ...@@ -18,6 +18,8 @@ describe 'Gcp Cluster', :js do
let(:project_id) { 'test-project-1234' } let(:project_id) { 'test-project-1234' }
before do before do
stub_feature_flags(create_eks_clusters: false)
allow_any_instance_of(Projects::ClustersController) allow_any_instance_of(Projects::ClustersController)
.to receive(:token_in_session).and_return('token') .to receive(:token_in_session).and_return('token')
allow_any_instance_of(Projects::ClustersController) allow_any_instance_of(Projects::ClustersController)
...@@ -147,6 +149,7 @@ describe 'Gcp Cluster', :js do ...@@ -147,6 +149,7 @@ describe 'Gcp Cluster', :js do
context 'when user has not signed with Google' do context 'when user has not signed with Google' do
before do before do
stub_feature_flags(create_eks_clusters: false)
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add Kubernetes cluster' click_link 'Add Kubernetes cluster'
......
...@@ -51,6 +51,7 @@ describe 'Clusters', :js do ...@@ -51,6 +51,7 @@ describe 'Clusters', :js do
context 'when user has not signed in Google' do context 'when user has not signed in Google' do
before do before do
stub_feature_flags(create_eks_clusters: false)
visit project_clusters_path(project) visit project_clusters_path(project)
click_link 'Add Kubernetes cluster' click_link 'Add Kubernetes cluster'
...@@ -62,4 +63,27 @@ describe 'Clusters', :js do ...@@ -62,4 +63,27 @@ describe 'Clusters', :js do
expect(page).to have_link('Google account') expect(page).to have_link('Google account')
end end
end end
context 'when create_eks_clusters feature flag is enabled' do
before do
stub_feature_flags(create_eks_clusters: true)
end
context 'when user access create cluster page' do
before do
visit project_clusters_path(project)
click_link 'Add Kubernetes cluster'
click_link 'Create new Cluster on GKE'
end
it 'user sees a link to create a GKE cluster' do
expect(page).to have_link('Google GKE')
end
it 'user sees a link to create an EKS cluster' do
expect(page).to have_link('Amazon EKS')
end
end
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