Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
55ac72e5
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
55ac72e5
编写于
9月 26, 2017
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create cluster
上级
3823707a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
61 addition
and
39 deletion
+61
-39
app/controllers/projects/clusters_controller.rb
app/controllers/projects/clusters_controller.rb
+13
-4
app/views/projects/clusters/_form.html.haml
app/views/projects/clusters/_form.html.haml
+9
-0
app/views/projects/clusters/_login.html.haml
app/views/projects/clusters/_login.html.haml
+2
-0
app/views/projects/clusters/edit.html.haml
app/views/projects/clusters/edit.html.haml
+5
-1
app/views/projects/clusters/new.html.haml
app/views/projects/clusters/new.html.haml
+2
-15
lib/google_api/cloud_platform/client.rb
lib/google_api/cloud_platform/client.rb
+30
-19
未找到文件。
app/controllers/projects/clusters_controller.rb
浏览文件 @
55ac72e5
...
...
@@ -37,10 +37,11 @@ class Projects::ClustersController < Projects::ApplicationController
if
params
[
'creation_type'
]
==
'on_gke'
# Create a cluster on GKE
results
=
api_client
.
projects_zones_clusters_create
(
params
[
'gcp_project_id'
],
params
[
'cluster_zone'
],
params
[
'cluster_name'
],
params
[
'cluster_size'
]
project_id:
params
[
'gcp_project_id'
],
zone:
params
[
'cluster_zone'
],
cluster_name:
params
[
'cluster_name'
],
cluster_size:
params
[
'cluster_size'
],
machine_type:
params
[
'machine_type'
]
)
# Update service
...
...
@@ -90,7 +91,15 @@ class Projects::ClustersController < Projects::ApplicationController
def
edit
unless
session
[
GoogleApi
::
CloudPlatform
::
Client
.
token_in_session
]
@authorize_url
=
api_client
.
authorize_url
render
:edit
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
def
update
...
...
app/views/projects/clusters/_form.html.haml
0 → 100644
浏览文件 @
55ac72e5
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
app/views/projects/clusters/_login.html.haml
0 → 100644
浏览文件 @
55ac72e5
Login
%p
=
link_to
(
"authenticate from here"
,
@authorize_url
)
app/views/projects/clusters/edit.html.haml
浏览文件 @
55ac72e5
edit/show cluster
=
@cluster
.
inspect
-
if
@authorize_url
=
render
"login"
-
else
=
@cluster
.
inspect
\ No newline at end of file
app/views/projects/clusters/new.html.haml
浏览文件 @
55ac72e5
Create a new cluster
%br
-
if
@authorize_url
I have not authenticated yet. I can authenticate from
=
link_to
(
"authenticate from here"
,
@authorize_url
)
=
render
"login"
-
else
I have already authenticated.
%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
=
render
"form"
lib/google_api/cloud_platform/client.rb
浏览文件 @
55ac72e5
require
'google/apis/container_v1'
module
GoogleApi
module
CloudPlatform
class
Client
<
GoogleApi
::
Authentication
# Google::Apis::ContainerV1::ContainerService.new
class
<<
self
def
token_in_session
:cloud_platform_access_token
...
...
@@ -13,26 +13,37 @@ module GoogleApi
'https://www.googleapis.com/auth/cloud-platform'
end
def
projects_zones_clusters_get
# TODO:
# service = Google::Apis::ContainerV1::ContainerService.new
# service.authorization = access_token
# project_id = params['project_id']
# ...
# response = service.list_zone_clusters(project_id, zone)
response
def
projects_zones_clusters_get
(
project_id
:,
zone
:,
cluster_id
:)
service
=
Google
::
Apis
::
ContainerV1
::
ContainerService
.
new
service
.
authorization
=
access_token
response
=
service
.
get_zone_cluster
(
project_id
,
zone
,
cluster_id
)
response
.
to_json
end
def
projects_zones_clusters_create
(
gcp_project_id
,
cluster_zone
,
cluster_name
,
cluster_size
)
# TODO: Google::Apis::ContainerV1::ContainerService.new
# Responce exmaple
# {"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
{
'end_point'
=>
'https://111.111.111.111'
,
'ca_cert'
=>
'XXXXXXXXXXXXXXXXXX'
,
'username'
=>
'AAA'
,
'password'
=>
'BBB'
}
def
get_status
(
project_id
:,
zone
:,
cluster_name
:,
cluster_size
:,
machine_type
:)
# Observe
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录