Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-28 12:11:17 +0300
committerShinya Maeda <shinya@gitlab.com>2017-09-28 12:11:17 +0300
commitfabc359e77c39aea86f0eaa9f19b17b2a609dd99 (patch)
treee252491c27bd2ac6a2606cb7f89ac33ab1fa0254 /app/services/ci
parent058e595788118fb129d3003989a3728de9ae7e39 (diff)
Multithreading cluster creation is done with `reactive_cache`
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/create_cluster_service.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/services/ci/create_cluster_service.rb b/app/services/ci/create_cluster_service.rb
new file mode 100644
index 00000000000..bbf42ab2c8d
--- /dev/null
+++ b/app/services/ci/create_cluster_service.rb
@@ -0,0 +1,29 @@
+module Ci
+ class CreateClusterService < BaseService
+ UnexpectedOperationError = Class.new(StandardError)
+
+ def create_cluster_on_gke(api_client)
+ # Create a cluster on GKE
+ operation = api_client.projects_zones_clusters_create(
+ params['gcp_project_id'], params['cluster_zone'], params['cluster_name'],
+ cluster_size: params['cluster_size'], machine_type: params['machine_type']
+ )
+
+ if operation&.status != ('RUNNING' || 'PENDING')
+ raise UnexpectedOperationError
+ end
+
+ api_client.parse_self_link(operation.self_link).tap do |project_id, zone, operation_id|
+ project.clusters.create(owner: current_user,
+ gcp_project_id: params['gcp_project_id'],
+ cluster_zone: params['cluster_zone'],
+ cluster_name: params['cluster_name'],
+ project_namespace: params['project_namespace'],
+ gcp_operation_id: operation_id).tap do |cluster|
+ # Start status polling. When the operation finish, create KubernetesService.
+ cluster.creation_status(api_client.access_token)
+ end
+ end
+ end
+ end
+end