summaryrefslogtreecommitdiff
path: root/app/services/clusters/create_service.rb
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-19 14:42:30 +1300
committerThong Kuah <tkuah@gitlab.com>2018-11-01 19:36:58 +1300
commit88800abcd8741b07114c2850e00b74fbecfbf90e (patch)
tree06dcb6a6a8036164eb73df0da2cc13150357dda7 /app/services/clusters/create_service.rb
parent5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 (diff)
downloadgitlab-ce-88800abcd8741b07114c2850e00b74fbecfbf90e.tar.gz
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
Diffstat (limited to 'app/services/clusters/create_service.rb')
-rw-r--r--app/services/clusters/create_service.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/app/services/clusters/create_service.rb b/app/services/clusters/create_service.rb
index cd843b8ffa8..270db4a52fd 100644
--- a/app/services/clusters/create_service.rb
+++ b/app/services/clusters/create_service.rb
@@ -8,10 +8,11 @@ module Clusters
@current_user, @params = user, params.dup
end
- def execute(project:, access_token: nil)
- raise ArgumentError, _('Instance does not support multiple Kubernetes clusters') unless can_create_cluster?(project)
+ def execute(access_token: nil)
+ 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|
provider[:access_token] = access_token
end
@@ -27,9 +28,20 @@ module Clusters
Clusters::Cluster.create(cluster_params)
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
- def can_create_cluster?(project)
- project.clusters.empty?
+ def can_create_cluster?
+ clusterable.clusters.empty?
end
end
end