Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tke-eos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
tke-eos
Commits
3f8a5339
Commit
3f8a5339
authored
Mar 12, 2019
by
kewei.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了TYPES信息
parent
042a4baa
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
98 deletions
+114
-98
index.js
app/index.js
+20
-14
namespace.js
app/namespace.js
+4
-4
service.js
app/service.js
+13
-9
index.js
serviceTemplate/index.js
+2
-2
tke.service.js
services/tke.service.js
+75
-69
No files found.
app/index.js
View file @
3f8a5339
...
...
@@ -7,33 +7,39 @@ const result = require('../middleware/result')
const
namespaceRoute
=
require
(
'
./namespace
'
)
const
serviceRoute
=
require
(
'
./service
'
)
const
repositoryRouter
=
require
(
'
./repository
'
)
const
tag
=
require
(
'
./tag
'
)
// const rabbitmqRoute = require('./rabbitmq')
// const zookeeperRoute = require('./zookeeper')
const
commonServiceRoute
=
require
(
'
./commonService
'
)
const
ingressRoute
=
require
(
'
./ingress
'
)
const
client
=
require
(
'
../services/tke.service
'
).
create
({
secretId
:
'
AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac
'
,
secretKey
:
'
YBduRnjgVRGzmagZJbss3Vo58wWCyhgc
'
,
clusterId
:
'
cls-acfx4pvj
'
,
region
:
'
ap-beijing
'
})
// const client = require('../services/tke.service').create({
// secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac',
// secretKey: 'YBduRnjgVRGzmagZJbss3Vo58wWCyhgc',
// clusterId: 'cls-acfx4pvj',
// region: 'ap-beijing'
// })
const
cluster
=
require
(
'
../services/tke.clusterService
'
).
create
()
const
container
=
require
(
'
../services/tke.containerService
'
).
create
()
function
loadRoutes
(
router
)
{
router
.
use
(
error
())
.
use
(
result
())
.
use
(
async
(
ctx
,
next
)
=>
{
// 腾讯云
ctx
.
client
=
client
ctx
.
container
=
container
ctx
.
cluster
=
cluster
await
next
()
},
bodyParser
())
.
use
(
'
/namespace
'
,
namespaceRoute
.
routes
())
.
use
(
'
/service
'
,
serviceRoute
.
routes
())
// .use('/rabbitmq', rabbitmqRoute.routes())
// .use('/zookeeper', zookeeperRoute.routes())
.
use
(
'
/commonService
'
,
commonServiceRoute
.
routes
())
.
use
(
'
/ingress
'
,
ingressRoute
.
routes
())
.
use
(
'
/namespace
'
,
namespaceRoute
.
routes
())
.
use
(
'
/service
'
,
serviceRoute
.
routes
())
// .use('/rabbitmq', rabbitmqRoute.routes())
// .use('/zookeeper', zookeeperRoute.routes())
.
use
(
'
/commonService
'
,
commonServiceRoute
.
routes
())
.
use
(
'
/ingress
'
,
ingressRoute
.
routes
())
.
use
(
'
/repository
'
,
repositoryRouter
.
routes
())
.
use
(
'
/tag
'
,
tag
.
routes
())
}
exports
.
start
=
function
()
{
...
...
app/namespace.js
View file @
3f8a5339
...
...
@@ -4,17 +4,17 @@ const router = new Router();
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
ctx
=>
{
let
data
=
await
ctx
.
cl
ient
.
namespace_get
()
let
data
=
await
ctx
.
cl
uster
.
namespace_get
()
ctx
.
body
=
ctx
.
ok
(
data
)
})
router
.
post
(
'
/create
'
,
async
ctx
=>
{
await
ctx
.
cl
ient
.
namespace_create
(
ctx
.
request
.
body
.
name
)
await
ctx
.
cl
ient
.
ingress_create
(
ctx
.
request
.
body
.
name
)
await
ctx
.
cl
uster
.
namespace_create
(
ctx
.
request
.
body
.
name
)
await
ctx
.
cl
uster
.
ingress_create
(
ctx
.
request
.
body
.
name
)
ctx
.
body
=
ctx
.
ok
()
})
router
.
post
(
'
/delete
'
,
async
ctx
=>
{
await
ctx
.
cl
ient
.
namespace_delete
(
ctx
.
request
.
body
.
name
)
await
ctx
.
cl
uster
.
namespace_delete
(
ctx
.
request
.
body
.
name
)
ctx
.
body
=
ctx
.
ok
()
})
app/service.js
View file @
3f8a5339
...
...
@@ -2,24 +2,24 @@ const Router = require('koa-router')
const
yaml
=
require
(
'
js-yaml
'
)
const
templates
=
require
(
'
../serviceTemplate
'
)
const
TYPES
=
[
'
ui
'
,
'
java
'
,
'
node
js
'
,
'
python
'
,
'
go
'
]
const
TYPES
=
[
'
ui
'
,
'
java
'
,
'
node
'
,
'
python
'
,
'
go
'
]
const
router
=
new
Router
()
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
ctx
=>
{
let
data
=
await
ctx
.
cl
ient
.
service_list
(
ctx
.
query
.
namespace
)
let
data
=
await
ctx
.
cl
uster
.
service_list
(
ctx
.
query
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
data
)
})
router
.
post
(
'
/create
'
,
async
ctx
=>
{
let
{
type
,
serviceName
,
namespace
,
image
,
system_name
}
=
ctx
.
request
.
body
let
{
type
,
serviceName
,
namespace
,
image
,
system_name
,
lable
}
=
ctx
.
request
.
body
if
(
!
TYPES
.
includes
(
type
))
{
return
ctx
.
body
=
ctx
.
fail
(
'
不支持的服务类型
'
)
}
// try {
// let svc = await ctx.cl
ient
.service_get(serviceName, namespace)
// let svc = await ctx.cl
uster
.service_get(serviceName, namespace)
// if (svc) {
// return ctx.body = ctx.fail('服务已经存在')
// }
...
...
@@ -30,7 +30,8 @@ router.post('/create', async ctx => {
serviceName
,
namespace
,
image
,
system_name
system_name
,
lable
}
if
(
!
system_name
)
{
// ui abTest的时候不一样
...
...
@@ -43,16 +44,19 @@ router.post('/create', async ctx => {
return
data
[
arguments
[
1
]]
})
let
params
=
yaml
.
load
(
template
)
await
ctx
.
cl
ient
.
service_create
(
params
)
await
ctx
.
cl
uster
.
service_create
(
params
,
type
)
ctx
.
body
=
ctx
.
ok
(
'
创建成功
'
)
})
router
.
post
(
'
/details
'
,
async
ctx
=>
{
let
data
=
await
ctx
.
cluster
.
service_get
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
data
)
})
router
.
post
(
'
/delete
'
,
async
ctx
=>
{
await
ctx
.
cl
ient
.
service_delete
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
await
ctx
.
cl
uster
.
service_delete
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
})
router
.
post
(
'
/modifyImage
'
,
async
ctx
=>
{
await
ctx
.
cl
ient
.
service_modifyImage
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
image
,
ctx
.
request
.
body
.
namespace
)
await
ctx
.
cl
uster
.
service_modifyImage
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
image
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
更新成功
'
)
})
serviceTemplate/index.js
View file @
3f8a5339
const
fs
=
require
(
'
fs
'
)
const
ui
=
fs
.
readFileSync
(
'
serviceTemplate/ui.template.txt
'
,
'
utf8
'
)
const
java
=
fs
.
readFileSync
(
'
serviceTemplate/java.template.txt
'
,
'
utf8
'
)
const
node
js
=
fs
.
readFileSync
(
'
serviceTemplate/nodejs
.template.txt
'
,
'
utf8
'
)
const
node
=
fs
.
readFileSync
(
'
serviceTemplate/node
.template.txt
'
,
'
utf8
'
)
const
rabbitmq
=
fs
.
readFileSync
(
'
serviceTemplate/rabbitmq.template.txt
'
,
'
utf8
'
)
const
zookeeper
=
fs
.
readFileSync
(
'
serviceTemplate/zookeeper.template.txt
'
,
'
utf8
'
)
const
mysql
=
fs
.
readFileSync
(
'
serviceTemplate/mysql.template.txt
'
,
'
utf8
'
)
module
.
exports
=
{
ui
,
node
js
,
node
,
java
,
rabbitmq
,
zookeeper
,
...
...
services/tke.service.js
View file @
3f8a5339
const
request
=
require
(
'
request
'
)
const
crypto
=
require
(
'
crypto
'
)
const
domainConfig
=
require
(
'
../config
'
)
class
Client
{
constructor
(
{
secretId
,
secretKey
,
region
,
clusterId
}
)
{
this
.
secretId
=
secretId
this
.
secretKey
=
secretKey
this
.
region
=
region
this
.
clusterId
=
clusterId
this
.
method
=
'
POST
'
this
.
protocal
=
'
https://
'
this
.
endpoint
=
'
ccs.api.qcloud.com
'
this
.
path
=
'
/v2/index.php
'
this
.
domain
=
"
.lkbang.com
"
constructor
()
{
this
.
secretId
=
domainConfig
.
secretId
this
.
secretKey
=
domainConfig
.
secretKey
this
.
region
=
domainConfig
.
region
this
.
clusterId
=
domainConfig
.
clusterId
this
.
method
=
domainConfig
.
method
this
.
protocal
=
domainConfig
.
protocal
this
.
endpoint
=
''
this
.
path
=
domainConfig
.
path
this
.
domain
=
domainConfig
.
domain
// 禁止操作以下命名空间
this
.
defaultNamespaces
=
[
'
default
'
,
'
kube-system
'
,
'
kube-public
'
]
...
...
@@ -63,7 +64,7 @@ class Client {
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
({
method
:
self
.
method
,
url
,
url
,
json
:
true
,
form
:
params
},
function
(
err
,
res
,
body
)
{
...
...
@@ -81,66 +82,71 @@ class Client {
})
}
namespace_get
()
{
return
this
.
post
(
'
DescribeClusterNameSpaces
'
,
{
clusterId
:
this
.
clusterId
})
}
namespace_create
(
name
)
{
return
this
.
post
(
'
CreateClusterNamespace
'
,
{
name
,
description
:
''
,
clusterId
:
this
.
clusterId
})
}
namespace_delete
(
name
)
{
return
this
.
post
(
'
DeleteClusterNamespace
'
,
{
"
names.0
"
:
name
,
clusterId
:
this
.
clusterId
})
}
service_list
(
namespace
)
{
return
this
.
post
(
'
DescribeClusterService
'
,
{
namespace
,
clusterId
:
this
.
clusterId
,
allnamespace
:
0
})
}
service_get
(
serviceName
,
namespace
)
{
return
this
.
post
(
'
DescribeClusterServiceInfo
'
,
{
serviceName
,
namespace
,
clusterId
:
this
.
clusterId
})
}
async
service_create
(
params
)
{
params
.
clusterId
=
this
.
clusterId
let
str
=
JSON
.
stringify
(
params
)
await
this
.
post
(
'
CreateClusterService
'
,
params
)
// 腾讯云api暂只能通过修改服务来改成Recreate策略
let
modifyParams
=
JSON
.
parse
(
str
)
modifyParams
.
strategy
=
'
Recreate
'
return
this
.
post
(
'
ModifyClusterService
'
,
modifyParams
)
}
service_delete
(
serviceName
,
namespace
)
{
return
this
.
post
(
'
DeleteClusterService
'
,
{
serviceName
,
namespace
,
clusterId
:
this
.
clusterId
})
}
service_modifyImage
(
serviceName
,
image
,
namespace
)
{
// 修改示例的第一个容器
return
this
.
post
(
'
ModifyClusterServiceImage
'
,
{
serviceName
,
namespace
,
image
,
clusterId
:
this
.
clusterId
})
}
ingress_get
(
namespace
)
{
return
this
.
post
(
'
DescribeIngress
'
,
{
namespace
,
clusterId
:
this
.
clusterId
})
}
ingress_create
(
namespace
)
{
return
this
.
post
(
'
CreateIngress
'
,
{
ingressName
:
`qa-
${
namespace
}
`
,
ingressDesc
:
''
,
namespace
,
clusterId
:
this
.
clusterId
})
}
ingress_delete
(
ingressName
,
namespace
)
{
return
this
.
post
(
'
DeleteIngress
'
,
{
ingressName
,
namespace
,
clusterId
:
this
.
clusterId
})
}
ingress_modify
(
ingressName
,
namespace
,
rules
)
{
return
this
.
post
(
'
MosifyIngress
'
,
{
ingressName
,
namespace
,
...
rules
,
clusterId
:
this
.
clusterId
})
}
// namespace_get () {
// return this.post('DescribeClusterNameSpaces', {clusterId: this.clusterId})
// }
//
// namespace_create (name) {
// return this.post('CreateClusterNamespace', {name, description: '', clusterId: this.clusterId})
// }
//
// namespace_delete (name) {
// return this.post('DeleteClusterNamespace', {"names.0": name, clusterId: this.clusterId})
// }
// service_list (namespace) {
// return this.post('DescribeClusterService', {namespace, clusterId: this.clusterId, allnamespace: 0})
// }
//
// service_get (serviceName, namespace) {
// return this.post('DescribeClusterServiceInfo', {serviceName, namespace, clusterId: this.clusterId})
// }
//
// async service_create (params) {
// params.clusterId = this.clusterId
// let str = JSON.stringify(params)
// await this.post('CreateClusterService', params)
// // 腾讯云api暂只能通过修改服务来改成Recreate策略
// let modifyParams = JSON.parse(str)
// modifyParams.strategy = 'Recreate'
// return this.post('ModifyClusterService', modifyParams)
// }
//
// service_delete (serviceName, namespace) {
// return this.post('DeleteClusterService', {serviceName, namespace, clusterId: this.clusterId})
// }
//
// service_modifyImage (serviceName, image, namespace) {
// // 修改示例的第一个容器
// return this.post('ModifyClusterServiceImage', {serviceName, namespace, image, clusterId: this.clusterId})
// }
//
// ingress_get (namespace) {
// return this.post('DescribeIngress', {namespace, clusterId: this.clusterId})
// }
//
// ingress_create (namespace) {
// return this.post('CreateIngress', {ingressName: `qa-${namespace}`, ingressDesc: '', namespace, clusterId: this.clusterId})
// }
//
// ingress_delete (ingressName, namespace) {
// return this.post('DeleteIngress', {ingressName, namespace, clusterId: this.clusterId})
// }
//
// ingress_modify (ingressName, namespace, rules) {
// return this.post('MosifyIngress', {ingressName, namespace, ...rules, clusterId: this.clusterId})
// }
//腾讯仓库列表
// repository_get(namespace1, reponame1) {
// return this.post('SearchUserRepository', {reponame})
// }
}
exports
.
create
=
function
(
config
)
{
return
new
Client
(
config
)
}
module
.
exports
=
Client
// exports.create = function (config) {
// return new Client(config)
// }
// let client = new Client({
// secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac',
...
...
@@ -151,4 +157,4 @@ exports.create = function (config) {
// client.post('DescribeClusterNameSpaces', {clusterId: 'cls-acfx4pvj'}).then(res => {
// console.log(5, res)
// })
\ No newline at end of file
// })
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment