Commit 55ac72e5 authored by Shinya Maeda's avatar Shinya Maeda

Create cluster

parent 3823707a
...@@ -37,10 +37,11 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -37,10 +37,11 @@ class Projects::ClustersController < Projects::ApplicationController
if params['creation_type'] == 'on_gke' if params['creation_type'] == 'on_gke'
# Create a cluster on GKE # Create a cluster on GKE
results = api_client.projects_zones_clusters_create( results = api_client.projects_zones_clusters_create(
params['gcp_project_id'], project_id: params['gcp_project_id'],
params['cluster_zone'], zone: params['cluster_zone'],
params['cluster_name'], cluster_name: params['cluster_name'],
params['cluster_size'] cluster_size: params['cluster_size'],
machine_type: params['machine_type']
) )
# Update service # Update service
...@@ -90,7 +91,15 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -90,7 +91,15 @@ class Projects::ClustersController < Projects::ApplicationController
def edit def edit
unless session[GoogleApi::CloudPlatform::Client.token_in_session] unless session[GoogleApi::CloudPlatform::Client.token_in_session]
@authorize_url = api_client.authorize_url @authorize_url = api_client.authorize_url
render :edit
end end
# Get cluster information
api_client.projects_zones_clusters_get(
project_id: cluster.gcp_project_id,
zone: cluster.cluster_zone,
cluster_id: cluster.cluster_name
)
end end
def update def update
......
Create a new cluster
%br
Avaiable GCP project lists
%br
Avaiable zones
%br
= link_to "Create on Google Container Engine", namespace_project_clusters_path(@project.namespace, @project, creation_type: 'on_gke', cluster_name: 'gke-test-creation', gcp_project_id: 'gitlab-internal-153318', cluster_zone: 'us-central1-a', cluster_size: '1', project_namespace: 'aaa', machine_type: '???'), method: :post
%br
= link_to "Use existing kubernets cluster", namespace_project_clusters_path(@project.namespace, @project, creation_type: 'manual', end_point: 'xxx.xxx.xxx.xxx', ca_cert: 'xxx...xxx', token: 'xxx', project_namespace: 'aaa'), method: :post
Login
%p= link_to("authenticate from here", @authorize_url)
edit/show cluster edit/show cluster
= @cluster.inspect
- if @authorize_url
= render "login"
- else
= @cluster.inspect
\ No newline at end of file
Create a new cluster
%br
- if @authorize_url - if @authorize_url
I have not authenticated yet. I can authenticate from = render "login"
= link_to("authenticate from here", @authorize_url)
- else - else
I have already authenticated. = render "form"
%br
Avaiable GCP project lists
%br
Avaiable zones
%br
= link_to "Create on Google Container Engine", namespace_project_clusters_path(@project.namespace, @project, creation_type: 'on_gke', cluster_name: 'new-cluster-shinya', gcp_project_id: 'gitlab-internal', cluster_zone: 'gitlab-internal', cluster_size: 'gitlab-internal', project_namespace: 'aaa'), method: :post
%br
= link_to "Use existing kubernets cluster", namespace_project_clusters_path(@project.namespace, @project, creation_type: 'manual', end_point: 'xxx.xxx.xxx.xxx', ca_cert: 'xxx...xxx', token: 'xxx', project_namespace: 'aaa'), method: :post
require 'google/apis/container_v1'
module GoogleApi module GoogleApi
module CloudPlatform module CloudPlatform
class Client < GoogleApi::Authentication class Client < GoogleApi::Authentication
# Google::Apis::ContainerV1::ContainerService.new
class << self class << self
def token_in_session def token_in_session
:cloud_platform_access_token :cloud_platform_access_token
...@@ -13,26 +13,37 @@ module GoogleApi ...@@ -13,26 +13,37 @@ module GoogleApi
'https://www.googleapis.com/auth/cloud-platform' 'https://www.googleapis.com/auth/cloud-platform'
end end
def projects_zones_clusters_get def projects_zones_clusters_get(project_id:, zone:, cluster_id:)
# TODO: service = Google::Apis::ContainerV1::ContainerService.new
# service = Google::Apis::ContainerV1::ContainerService.new service.authorization = access_token
# service.authorization = access_token
# project_id = params['project_id'] response = service.get_zone_cluster(project_id, zone, cluster_id)
# ... response.to_json
# response = service.list_zone_clusters(project_id, zone)
response
end end
def projects_zones_clusters_create(gcp_project_id, cluster_zone, cluster_name, cluster_size) # Responce exmaple
# TODO: Google::Apis::ContainerV1::ContainerService.new # {"name":"operation-1506424047439-0293f57c","operationType":"CREATE_CLUSTER","selfLink":"https://container.googleapis.com/v1/projects/696404988091/zones/us-central1-a/operations/operation-1506424047439-0293f57c","startTime":"2017-09-26T11:07:27.439033158Z","status":"RUNNING","targetLink":"https://container.googleapis.com/v1/projects/696404988091/zones/us-central1-a/clusters/gke-test-creation","zone":"us-central1-a"}
def projects_zones_clusters_create(project_id:, zone:, cluster_name:, cluster_size:, machine_type:)
service = Google::Apis::ContainerV1::ContainerService.new
service.authorization = access_token
request_body = Google::Apis::ContainerV1::CreateClusterRequest.new(
{
"cluster": {
"name": cluster_name,
"initial_node_count": cluster_size
}
}
)
# TODO: machine_type : Defailt 3.75 GB
response = service.create_cluster(project_id, zone, request_body)
puts response.to_json
response.to_json
end
# TODO: Debug def get_status(project_id:, zone:, cluster_name:, cluster_size:, machine_type:)
{ # Observe
'end_point' => 'https://111.111.111.111',
'ca_cert' => 'XXXXXXXXXXXXXXXXXX',
'username' => 'AAA',
'password' => 'BBB'
}
end 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