Commit d65cd0a6 authored by Shinya Maeda's avatar Shinya Maeda

Tie KubernetesService

parent bdc618c2
...@@ -32,8 +32,10 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -32,8 +32,10 @@ class Projects::ClustersController < Projects::ApplicationController
# - If create on GKE, Use Google::Apis::ContainerV1::ContainerService # - If create on GKE, Use Google::Apis::ContainerV1::ContainerService
# - If create manually, save in db (Prob, Project > Setting) # - If create manually, save in db (Prob, Project > Setting)
# - Dry up with Service # - Dry up with Service
# - Transaction
def create def create
if params['creation_type'] == 'on_gke' if params['creation_type'] == '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'], params['gcp_project_id'],
params['cluster_zone'], params['cluster_zone'],
...@@ -41,22 +43,24 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -41,22 +43,24 @@ class Projects::ClustersController < Projects::ApplicationController
params['cluster_size'] params['cluster_size']
) )
# TODO: How to create # Update service
project.kubernetes_service.save( kubernetes_service.attributes = service_params(
end_point: results['end_point'], active: true,
ca_cert: results['ca_cert'], api_url: results['end_point'],
token: nil, ca_pem: results['ca_cert'], # TODO: Decode Base64
username: results['username'], namespace: params['project_namespace'],
password: results['password'], token: 'aaa' # TODO: username/password
project_namespace: params['project_namespace'] )
)
kubernetes_service.save!
# Save info
project.clusters.create( project.clusters.create(
creation_type: params['creation_type'], creation_type: params['creation_type'],
gcp_project_id: params['gcp_project_id'], gcp_project_id: params['gcp_project_id'],
cluster_zone: params['cluster_zone'], cluster_zone: params['cluster_zone'],
cluster_name: params['cluster_name'], cluster_name: params['cluster_name'],
kubernetes_service: project.kubernetes_service service: kubernetes_service
) )
elsif params['creation_type'] == 'manual' elsif params['creation_type'] == 'manual'
# TODO: Transaction # TODO: Transaction
...@@ -121,7 +125,7 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -121,7 +125,7 @@ class Projects::ClustersController < Projects::ApplicationController
def cluster def cluster
# Each project has only one cluster, for now. In the future iteraiton, we'll support multiple clusters # Each project has only one cluster, for now. In the future iteraiton, we'll support multiple clusters
@cluster ||= project.clusters.first @cluster ||= project.clusters.last
end end
# def cluster_params # def cluster_params
...@@ -136,4 +140,18 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -136,4 +140,18 @@ class Projects::ClustersController < Projects::ApplicationController
state: namespace_project_clusters_url.to_s state: namespace_project_clusters_url.to_s
) )
end end
def kubernetes_service
@kubernetes_service ||= project.find_or_initialize_service('kubernetes')
end
def service_params(active:, api_url:, ca_pem:, namespace:, token:)
{
active: active,
api_url: api_url,
ca_pem: ca_pem,
namespace: namespace,
token: token
}
end
end end
...@@ -4,6 +4,7 @@ module Ci ...@@ -4,6 +4,7 @@ module Ci
belongs_to :project belongs_to :project
belongs_to :owner, class_name: 'User' belongs_to :owner, class_name: 'User'
belongs_to :service
enum creation_type: { enum creation_type: {
unknown: nil, unknown: nil,
......
...@@ -183,10 +183,11 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -183,10 +183,11 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
resources :clusters, except: [:show, :destroy] do resources :clusters, except: [:edit, :show, :destroy] do
collection do collection do
get :gcp_projects # TODO: This doesn't belong here. Grape or under user. Hint. Serilizer get :gcp_projects # TODO: This doesn't belong here. Grape or under user. Hint. Serilizer
get :gke_zones get :gke_zones
get :edit
end end
end end
......
...@@ -28,7 +28,7 @@ module GoogleApi ...@@ -28,7 +28,7 @@ module GoogleApi
# TODO: Debug # TODO: Debug
{ {
'end_point' => '111.111.111.111', 'end_point' => 'https://111.111.111.111',
'ca_cert' => 'XXXXXXXXXXXXXXXXXX', 'ca_cert' => 'XXXXXXXXXXXXXXXXXX',
'username' => 'AAA', 'username' => 'AAA',
'password' => 'BBB' 'password' => 'BBB'
......
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