Commit 88800abc authored by Thong Kuah's avatar Thong Kuah

Abstract out project out of ClustersController

To the extent possible swap out `project` with `clusterable`

- Abstract paths for showing cluster or clusters. This will allow us to
swap in alternative paths for group level cluster

- Push :project_id and :namespace_id params from the URL to the POST
body.

- Create a nice helper for to generate links for the destroy
action

For some reason, spec :project_id and :namespace_id param are not going
through `to_param` for a JSON format. Manually call `to_param` to fix
specs.

- Move :layout to BaseController
parent 5b3c096c
...@@ -19,7 +19,7 @@ class Clusters::ApplicationsController < Clusters::BaseController ...@@ -19,7 +19,7 @@ class Clusters::ApplicationsController < Clusters::BaseController
private private
def cluster def cluster
@cluster ||= project.clusters.find(params[:id]) || render_404 @cluster ||= clusterable.clusters.find(params[:id]) || render_404
end end
def create_cluster_application_params def create_cluster_application_params
......
...@@ -9,6 +9,10 @@ class Clusters::BaseController < ApplicationController ...@@ -9,6 +9,10 @@ class Clusters::BaseController < ApplicationController
before_action :repository, if: :project_type? before_action :repository, if: :project_type?
before_action :authorize_read_cluster! before_action :authorize_read_cluster!
layout :determine_layout
helper_method :clusters_page_path, :cluster_page_path, :new_cluster_page_path
private private
# We can extend to `#group_type?` in the future # We can extend to `#group_type?` in the future
...@@ -32,8 +36,34 @@ class Clusters::BaseController < ApplicationController ...@@ -32,8 +36,34 @@ class Clusters::BaseController < ApplicationController
access_denied! unless can?(current_user, :create_cluster, clusterable) access_denied! unless can?(current_user, :create_cluster, clusterable)
end end
def determine_layout
if project_type?
'project'
end
end
def clusterable def clusterable
project if project_type? if project_type?
project
end
end
def cluster_page_path(cluster)
if project_type?
project_cluster_path(project, cluster)
end
end
def clusters_page_path
if project_type?
project_clusters_path(project)
end
end
def new_cluster_page_path
if project_type?
new_project_cluster_path(project)
end
end end
def project_type? def project_type?
......
...@@ -11,14 +11,12 @@ class ClustersController < Clusters::BaseController ...@@ -11,14 +11,12 @@ class ClustersController < Clusters::BaseController
before_action :authorize_admin_cluster!, only: [:destroy] before_action :authorize_admin_cluster!, only: [:destroy]
before_action :update_applications_status, only: [:status] before_action :update_applications_status, only: [:status]
layout :determine_layout
helper_method :token_in_session helper_method :token_in_session
STATUS_POLLING_INTERVAL = 10_000 STATUS_POLLING_INTERVAL = 10_000
def index def index
clusters = ClustersFinder.new(project, current_user, :all).execute clusters = ClustersFinder.new(clusterable, current_user, :all).execute
@clusters = clusters.page(params[:page]).per(20) @clusters = clusters.page(params[:page]).per(20)
end end
...@@ -31,7 +29,7 @@ class ClustersController < Clusters::BaseController ...@@ -31,7 +29,7 @@ class ClustersController < Clusters::BaseController
Gitlab::PollingInterval.set_header(response, interval: STATUS_POLLING_INTERVAL) Gitlab::PollingInterval.set_header(response, interval: STATUS_POLLING_INTERVAL)
render json: ClusterSerializer render json: ClusterSerializer
.new(project: project, current_user: @current_user) .new(current_user: @current_user)
.represent_status(@cluster) .represent_status(@cluster)
end end
end end
...@@ -52,7 +50,7 @@ class ClustersController < Clusters::BaseController ...@@ -52,7 +50,7 @@ class ClustersController < Clusters::BaseController
end end
format.html do format.html do
flash[:notice] = _('Kubernetes cluster was successfully updated.') flash[:notice] = _('Kubernetes cluster was successfully updated.')
redirect_to project_cluster_path(project, cluster) redirect_to cluster_page_path(cluster)
end end
end end
else else
...@@ -66,7 +64,7 @@ class ClustersController < Clusters::BaseController ...@@ -66,7 +64,7 @@ class ClustersController < Clusters::BaseController
def destroy def destroy
if cluster.destroy if cluster.destroy
flash[:notice] = _('Kubernetes cluster integration was successfully removed.') flash[:notice] = _('Kubernetes cluster integration was successfully removed.')
redirect_to project_clusters_path(project), status: :found redirect_to clusters_page_path, status: :found
else else
flash[:notice] = _('Kubernetes cluster integration was not removed.') flash[:notice] = _('Kubernetes cluster integration was not removed.')
render :show render :show
...@@ -76,10 +74,10 @@ class ClustersController < Clusters::BaseController ...@@ -76,10 +74,10 @@ class ClustersController < Clusters::BaseController
def create_gcp def create_gcp
@gcp_cluster = ::Clusters::CreateService @gcp_cluster = ::Clusters::CreateService
.new(current_user, create_gcp_cluster_params) .new(current_user, create_gcp_cluster_params)
.execute(project: project, access_token: token_in_session) .execute(access_token: token_in_session)
if @gcp_cluster.persisted? if @gcp_cluster.persisted?
redirect_to project_cluster_path(project, @gcp_cluster) redirect_to cluster_page_path(@gcp_cluster)
else else
generate_gcp_authorize_url generate_gcp_authorize_url
validate_gcp_token validate_gcp_token
...@@ -92,10 +90,10 @@ class ClustersController < Clusters::BaseController ...@@ -92,10 +90,10 @@ class ClustersController < Clusters::BaseController
def create_user def create_user
@user_cluster = ::Clusters::CreateService @user_cluster = ::Clusters::CreateService
.new(current_user, create_user_cluster_params) .new(current_user, create_user_cluster_params)
.execute(project: project, access_token: token_in_session) .execute(access_token: token_in_session)
if @user_cluster.persisted? if @user_cluster.persisted?
redirect_to project_cluster_path(project, @user_cluster) redirect_to cluster_page_path(@user_cluster)
else else
generate_gcp_authorize_url generate_gcp_authorize_url
validate_gcp_token validate_gcp_token
...@@ -107,14 +105,8 @@ class ClustersController < Clusters::BaseController ...@@ -107,14 +105,8 @@ class ClustersController < Clusters::BaseController
private private
def determine_layout
if project_type?
'project'
end
end
def cluster def cluster
@cluster ||= project.clusters.find(params[:id]) @cluster ||= clusterable.clusters.find(params[:id])
.present(current_user: current_user) .present(current_user: current_user)
end end
...@@ -155,7 +147,8 @@ class ClustersController < Clusters::BaseController ...@@ -155,7 +147,8 @@ class ClustersController < Clusters::BaseController
:legacy_abac :legacy_abac
]).merge( ]).merge(
provider_type: :gcp, provider_type: :gcp,
platform_type: :kubernetes platform_type: :kubernetes,
clusterable: clusterable
) )
end end
...@@ -172,12 +165,13 @@ class ClustersController < Clusters::BaseController ...@@ -172,12 +165,13 @@ class ClustersController < Clusters::BaseController
:authorization_type :authorization_type
]).merge( ]).merge(
provider_type: :user, provider_type: :user,
platform_type: :kubernetes platform_type: :kubernetes,
clusterable: clusterable
) )
end end
def generate_gcp_authorize_url def generate_gcp_authorize_url
state = generate_session_key_redirect(new_project_cluster_path(project).to_s) state = generate_session_key_redirect(new_cluster_page_path.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,
......
# frozen_string_literal: true # frozen_string_literal: true
class ClustersFinder class ClustersFinder
def initialize(project, user, scope) def initialize(clusterable, user, scope)
@project = project @clusterable = clusterable
@user = user @user = user
@scope = scope || :active @scope = scope || :active
end end
def execute def execute
clusters = project.clusters clusters = clusterable.clusters
filter_by_scope(clusters) filter_by_scope(clusters)
end end
private private
attr_reader :project, :user, :scope attr_reader :clusterable, :user, :scope
def filter_by_scope(clusters) def filter_by_scope(clusters)
case scope.to_sym case scope.to_sym
......
# frozen_string_literal: true # frozen_string_literal: true
module ClustersHelper module ClustersHelper
def has_multiple_clusters?(project) # EE overrides this
def has_multiple_clusters?
false false
end end
def clusterable
@project
end
def can_create_cluster?
can?(current_user, :create_cluster, clusterable)
end
def render_gcp_signup_offer def render_gcp_signup_offer
return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers? return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers?
return unless show_gcp_signup_offer? return unless show_gcp_signup_offer?
...@@ -13,4 +22,19 @@ module ClustersHelper ...@@ -13,4 +22,19 @@ module ClustersHelper
render 'clusters/gcp_signup_offer_banner' render 'clusters/gcp_signup_offer_banner'
end end
end end
def hidden_clusterable_fields
clusterable_params.map do |key, value|
hidden_field_tag(key, value)
end.reduce(&:safe_concat)
end
def clusterable_params
case clusterable
when Project
{ project_id: clusterable.to_param, namespace_id: clusterable.namespace.to_param }
else
{}
end
end
end end
...@@ -8,10 +8,11 @@ module Clusters ...@@ -8,10 +8,11 @@ module Clusters
@current_user, @params = user, params.dup @current_user, @params = user, params.dup
end end
def execute(project:, access_token: nil) def execute(access_token: nil)
raise ArgumentError, _('Instance does not support multiple Kubernetes clusters') unless can_create_cluster?(project) raise ArgumentError, 'Unknown clusterable provided' unless clusterable
raise ArgumentError, _('Instance does not support multiple Kubernetes clusters') unless can_create_cluster?
cluster_params = params.merge(user: current_user, cluster_type: :project_type, projects: [project]) cluster_params = params.merge(user: current_user).merge(clusterable_params)
cluster_params[:provider_gcp_attributes].try do |provider| cluster_params[:provider_gcp_attributes].try do |provider|
provider[:access_token] = access_token provider[:access_token] = access_token
end end
...@@ -27,9 +28,20 @@ module Clusters ...@@ -27,9 +28,20 @@ module Clusters
Clusters::Cluster.create(cluster_params) Clusters::Cluster.create(cluster_params)
end end
def clusterable
@clusterable ||= params.delete(:clusterable)
end
def clusterable_params
case clusterable
when ::Project
{ cluster_type: :project_type, projects: [clusterable] }
end
end
# EE would override this method # EE would override this method
def can_create_cluster?(project) def can_create_cluster?
project.clusters.empty? clusterable.clusters.empty?
end end
end end
end end
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
= s_('ClusterIntegration|Remove Kubernetes cluster integration') = s_('ClusterIntegration|Remove Kubernetes cluster integration')
%p %p
= s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.") = s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.")
= link_to(s_('ClusterIntegration|Remove integration'), namespace_project_cluster_path(@project.namespace, @project, @cluster.id), method: :delete, class: 'btn btn-danger', data: { confirm: s_("ClusterIntegration|Are you sure you want to remove this Kubernetes cluster's integration? This will not delete your actual Kubernetes cluster.")}) = link_to(s_('ClusterIntegration|Remove integration'), cluster_path(@cluster, clusterable_params), method: :delete, class: 'btn btn-danger', data: { confirm: s_("ClusterIntegration|Are you sure you want to remove this Kubernetes cluster's integration? This will not delete your actual Kubernetes cluster.")})
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.table-section.section-30 .table-section.section-30
.table-mobile-header{ role: "rowheader" }= s_("ClusterIntegration|Kubernetes cluster") .table-mobile-header{ role: "rowheader" }= s_("ClusterIntegration|Kubernetes cluster")
.table-mobile-content .table-mobile-content
= link_to cluster.name, namespace_project_cluster_path(@project.namespace, @project, cluster) = link_to cluster.name, cluster_page_path(cluster)
.table-section.section-30 .table-section.section-30
.table-mobile-header{ role: "rowheader" }= s_("ClusterIntegration|Environment scope") .table-mobile-header{ role: "rowheader" }= s_("ClusterIntegration|Environment scope")
.table-mobile-content= cluster.environment_scope .table-mobile-content= cluster.environment_scope
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
class: "#{'is-checked' if cluster.enabled?} #{'is-disabled' if !cluster.can_toggle_cluster?}", class: "#{'is-checked' if cluster.enabled?} #{'is-disabled' if !cluster.can_toggle_cluster?}",
"aria-label": s_("ClusterIntegration|Toggle Kubernetes Cluster"), "aria-label": s_("ClusterIntegration|Toggle Kubernetes Cluster"),
disabled: !cluster.can_toggle_cluster?, disabled: !cluster.can_toggle_cluster?,
data: { endpoint: namespace_project_cluster_path(@project.namespace, @project, cluster, format: :json) } } data: { endpoint: cluster_path(cluster, clusterable_params.merge(format: :json)) } }
%input.js-project-feature-toggle-input{ type: "hidden", value: cluster.enabled? } %input.js-project-feature-toggle-input{ type: "hidden", value: cluster.enabled? }
= icon("spinner spin", class: "loading-icon") = icon("spinner spin", class: "loading-icon")
%span.toggle-icon %span.toggle-icon
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
- link_to_help_page = link_to(_('Learn more about Kubernetes'), help_page_path('user/project/clusters/index'), target: '_blank', rel: 'noopener noreferrer') - link_to_help_page = link_to(_('Learn more about Kubernetes'), help_page_path('user/project/clusters/index'), target: '_blank', rel: 'noopener noreferrer')
%p= s_('ClusterIntegration|Kubernetes clusters allow you to use review apps, deploy your applications, run your pipelines, and much more in an easy way. %{link_to_help_page}').html_safe % { link_to_help_page: link_to_help_page} %p= s_('ClusterIntegration|Kubernetes clusters allow you to use review apps, deploy your applications, run your pipelines, and much more in an easy way. %{link_to_help_page}').html_safe % { link_to_help_page: link_to_help_page}
- if can?(current_user, :create_cluster, @project) - if can_create_cluster?
.text-center .text-center
= link_to s_('ClusterIntegration|Add Kubernetes cluster'), new_project_cluster_path(@project), class: 'btn btn-success' = link_to s_('ClusterIntegration|Add Kubernetes cluster'), new_cluster_page_path, class: 'btn btn-success'
= form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| = form_for @cluster, url: cluster_path(@cluster), as: :cluster do |field|
= form_errors(@cluster) = form_errors(@cluster)
= hidden_clusterable_fields
.form-group .form-group
%h5= s_('ClusterIntegration|Integration status') %h5= s_('ClusterIntegration|Integration status')
%label.append-bottom-0.js-cluster-enable-toggle-area %label.append-bottom-0.js-cluster-enable-toggle-area
...@@ -13,7 +14,7 @@ ...@@ -13,7 +14,7 @@
= sprite_icon('status_failed_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-unchecked') = sprite_icon('status_failed_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-unchecked')
.form-text.text-muted= s_('ClusterIntegration|Enable or disable GitLab\'s connection to your Kubernetes cluster.') .form-text.text-muted= s_('ClusterIntegration|Enable or disable GitLab\'s connection to your Kubernetes cluster.')
- if has_multiple_clusters?(@project) - if has_multiple_clusters?
.form-group .form-group
%h5= s_('ClusterIntegration|Environment scope') %h5= s_('ClusterIntegration|Environment scope')
= field.text_field :environment_scope, class: 'col-md-6 form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'col-md-6 form-control js-select-on-focus', placeholder: s_('ClusterIntegration|Environment scope')
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
.form-group .form-group
= field.submit _('Save changes'), class: 'btn btn-success' = field.submit _('Save changes'), class: 'btn btn-success'
- unless has_multiple_clusters?(@project) - unless has_multiple_clusters?
%h5= s_('ClusterIntegration|Environment scope') %h5= s_('ClusterIntegration|Environment scope')
%p %p
%code * %code *
......
...@@ -12,14 +12,15 @@ ...@@ -12,14 +12,15 @@
%p= link_to('Select a different Google account', @authorize_url) %p= link_to('Select a different Google account', @authorize_url)
= form_for @gcp_cluster, html: { class: 'js-gke-cluster-creation prepend-top-20', data: { token: token_in_session } }, url: create_gcp_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| = form_for @gcp_cluster, html: { class: 'js-gke-cluster-creation prepend-top-20', data: { token: token_in_session } }, url: create_gcp_clusters_path, as: :cluster do |field|
= form_errors(@gcp_cluster) = form_errors(@gcp_cluster)
= hidden_clusterable_fields
.form-group .form-group
= field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold' = field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold'
= field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name') = field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name')
.form-group .form-group
= field.label :environment_scope, s_('ClusterIntegration|Environment scope'), class: 'label-bold' = field.label :environment_scope, s_('ClusterIntegration|Environment scope'), class: 'label-bold'
= field.text_field :environment_scope, class: 'form-control', readonly: !has_multiple_clusters?(@project), placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', readonly: !has_multiple_clusters?, placeholder: s_('ClusterIntegration|Environment scope')
= field.fields_for :provider_gcp, @gcp_cluster.provider_gcp do |provider_gcp_field| = field.fields_for :provider_gcp, @gcp_cluster.provider_gcp do |provider_gcp_field|
.form-group .form-group
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
%span.input-group-append %span.input-group-append
= clipboard_button(text: @cluster.name, title: s_('ClusterIntegration|Copy Kubernetes cluster name'), class: 'input-group-text btn-default') = clipboard_button(text: @cluster.name, title: s_('ClusterIntegration|Copy Kubernetes cluster name'), class: 'input-group-text btn-default')
= form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| = form_for @cluster, url: cluster_path(@cluster), as: :cluster do |field|
= form_errors(@cluster) = form_errors(@cluster)
= hidden_clusterable_fields
= field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field| = field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field|
.form-group .form-group
......
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
- add_to_breadcrumbs "Kubernetes Clusters", project_clusters_path(@project) - add_to_breadcrumbs "Kubernetes Clusters", clusters_page_path
- breadcrumb_title @cluster.name - breadcrumb_title @cluster.name
- page_title _("Kubernetes Cluster") - page_title _("Kubernetes Cluster")
- manage_prometheus_path = edit_project_service_path(@cluster.project, 'prometheus') if @project
- expanded = Rails.env.test? - expanded = Rails.env.test?
- status_path = status_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster.id, format: :json) if can?(current_user, :admin_cluster, @cluster) - status_path = status_cluster_path(@cluster.id, clusterable_params.merge(format: :json)) if can?(current_user, :admin_cluster, @cluster)
.edit-cluster-form.js-edit-cluster-form{ data: { status_path: status_path, .edit-cluster-form.js-edit-cluster-form{ data: { status_path: status_path,
install_helm_path: install_applications_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster, :helm), install_helm_path: install_applications_cluster_path(@cluster, :helm, clusterable_params),
install_ingress_path: install_applications_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster, :ingress), install_ingress_path: install_applications_cluster_path(@cluster, :ingress, clusterable_params),
install_prometheus_path: install_applications_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster, :prometheus), install_prometheus_path: install_applications_cluster_path(@cluster, :prometheus, clusterable_params),
install_runner_path: install_applications_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster, :runner), install_runner_path: install_applications_cluster_path(@cluster, :runner, clusterable_params),
install_jupyter_path: install_applications_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster, :jupyter), install_jupyter_path: install_applications_cluster_path(@cluster, :jupyter, clusterable_params),
toggle_status: @cluster.enabled? ? 'true': 'false', toggle_status: @cluster.enabled? ? 'true': 'false',
cluster_status: @cluster.status_name, cluster_status: @cluster.status_name,
cluster_status_reason: @cluster.status_reason, cluster_status_reason: @cluster.status_reason,
help_path: help_page_path('user/project/clusters/index.md', anchor: 'installing-applications'), help_path: help_page_path('user/project/clusters/index.md', anchor: 'installing-applications'),
ingress_help_path: help_page_path('user/project/clusters/index.md', anchor: 'getting-the-external-ip-address'), ingress_help_path: help_page_path('user/project/clusters/index.md', anchor: 'getting-the-external-ip-address'),
ingress_dns_help_path: help_page_path('topics/autodevops/quick_start_guide.md', anchor: 'point-dns-at-cluster-ip'), ingress_dns_help_path: help_page_path('topics/autodevops/quick_start_guide.md', anchor: 'point-dns-at-cluster-ip'),
manage_prometheus_path: edit_project_service_path(@cluster.project, 'prometheus') } } manage_prometheus_path: manage_prometheus_path } }
.js-cluster-application-notice .js-cluster-application-notice
.flash-container .flash-container
......
= form_for @user_cluster, url: create_user_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field| = form_for @user_cluster, url: create_user_clusters_path, as: :cluster do |field|
= form_errors(@user_cluster) = form_errors(@user_cluster)
= hidden_clusterable_fields
.form-group .form-group
= field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold' = field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold'
= field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name') = field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name')
- if has_multiple_clusters?(@project) - if has_multiple_clusters?
.form-group .form-group
= field.label :environment_scope, s_('ClusterIntegration|Environment scope'), class: 'label-bold' = field.label :environment_scope, s_('ClusterIntegration|Environment scope'), class: 'label-bold'
= field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope') = field.text_field :environment_scope, class: 'form-control', placeholder: s_('ClusterIntegration|Environment scope')
......
= form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| = form_for @cluster, url: cluster_path(@cluster), as: :cluster do |field|
= form_errors(@cluster) = form_errors(@cluster)
= hidden_clusterable_fields
.form-group .form-group
= field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold' = field.label :name, s_('ClusterIntegration|Kubernetes cluster name'), class: 'label-bold'
= field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name') = field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Kubernetes cluster name')
......
...@@ -74,6 +74,21 @@ Rails.application.routes.draw do ...@@ -74,6 +74,21 @@ Rails.application.routes.draw do
resources :issues, module: :boards, only: [:index, :update] resources :issues, module: :boards, only: [:index, :update]
end end
resources :clusters, only: [:update, :destroy] do
collection do
post :create_user
post :create_gcp
end
member do
scope :applications do
post '/:application', to: 'clusters/applications#create', as: :install_applications
end
get :status, format: :json
end
end
# UserCallouts # UserCallouts
resources :user_callouts, only: [:create] resources :user_callouts, only: [:create]
...@@ -85,20 +100,7 @@ Rails.application.routes.draw do ...@@ -85,20 +100,7 @@ Rails.application.routes.draw do
end end
concern :clusterable do concern :clusterable do
resources :clusters, except: [:edit, :create], controller: '/clusters' do resources :clusters, only: [:index, :new, :show], controller: '/clusters'
collection do
post :create_gcp
post :create_user
end
member do
get :status, format: :json
scope :applications do
post '/:application', to: '/clusters/applications#create', as: :install_applications
end
end
end
end end
draw :api draw :api
......
...@@ -325,8 +325,8 @@ describe ClustersController do ...@@ -325,8 +325,8 @@ describe ClustersController do
def go def go
get :status, get :status,
namespace_id: project.namespace, namespace_id: project.namespace.to_param,
project_id: project, project_id: project.to_param,
id: cluster, id: cluster,
format: :json format: :json
end end
...@@ -405,8 +405,8 @@ describe ClustersController do ...@@ -405,8 +405,8 @@ describe ClustersController do
end end
def go(format: :html) def go(format: :html)
put :update, params.merge(namespace_id: project.namespace, put :update, params.merge(namespace_id: project.namespace.to_param,
project_id: project, project_id: project.to_param,
id: cluster, id: cluster,
format: format format: format
) )
......
...@@ -5,18 +5,43 @@ describe Clusters::CreateService do ...@@ -5,18 +5,43 @@ describe Clusters::CreateService do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
subject { described_class.new(user, params).execute(project: project, access_token: access_token) } subject { described_class.new(user, params).execute(access_token: access_token) }
context 'when provider is gcp' do context 'when provider is gcp' do
context 'when project has no clusters' do context 'when project has no clusters' do
context 'when correct params' do context 'when correct params' do
include_context 'valid cluster create params' let(:params) do
{
name: 'test-cluster',
provider_type: :gcp,
provider_gcp_attributes: {
gcp_project_id: 'gcp-project',
zone: 'us-central1-a',
num_nodes: 1,
machine_type: 'machine_type-a',
legacy_abac: 'true'
},
clusterable: project
}
end
include_examples 'create cluster service success' include_examples 'create cluster service success'
end end
context 'when invalid params' do context 'when invalid params' do
include_context 'invalid cluster create params' let(:params) do
{
name: 'test-cluster',
provider_type: :gcp,
provider_gcp_attributes: {
gcp_project_id: '!!!!!!!',
zone: 'us-central1-a',
num_nodes: 1,
machine_type: 'machine_type-a'
},
clusterable: project
}
end
include_examples 'create cluster service error' include_examples 'create cluster service error'
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