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
4e90d54c
Commit
4e90d54c
authored
Mar 13, 2019
by
kewei.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除注释代码
parent
57b99a7e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
616 additions
and
703 deletions
+616
-703
service.js
app/service.js
+31
-40
package-lock.json
package-lock.json
+513
-513
tke.clusterService.js
services/tke.clusterService.js
+2
-6
tke.service.js
services/tke.service.js
+70
-144
No files found.
app/service.js
View file @
4e90d54c
...
...
@@ -8,55 +8,46 @@ const router = new Router()
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
ctx
=>
{
let
data
=
await
ctx
.
cluster
.
service_list
(
ctx
.
query
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
data
)
let
data
=
await
ctx
.
cluster
.
service_list
(
ctx
.
query
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
data
)
})
router
.
post
(
'
/create
'
,
async
ctx
=>
{
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.cluster.service_get(serviceName, namespace)
// if (svc) {
// return ctx.body = ctx.fail('服务已经存在')
// }
// } catch (e) {
// }
let
data
=
{
serviceName
,
namespace
,
image
,
system_name
,
lable
}
if
(
!
system_name
)
{
// ui abTest的时候不一样
data
.
system_name
=
serviceName
}
let
template
=
templates
[
type
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
let
{
type
,
serviceName
,
namespace
,
image
,
system_name
,
lable
}
=
ctx
.
request
.
body
if
(
!
TYPES
.
includes
(
type
))
{
return
ctx
.
body
=
ctx
.
fail
(
'
不支持的服务类型
'
)
}
let
data
=
{
serviceName
,
namespace
,
image
,
system_name
,
lable
}
if
(
!
system_name
)
{
// ui abTest的时候不一样
data
.
system_name
=
serviceName
}
return
data
[
arguments
[
1
]]
})
let
params
=
yaml
.
load
(
template
)
await
ctx
.
cluster
.
service_create
(
params
,
type
)
ctx
.
body
=
ctx
.
ok
(
'
创建成功
'
)
let
template
=
templates
[
type
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
}
return
data
[
arguments
[
1
]]
})
let
params
=
yaml
.
load
(
template
)
await
ctx
.
cluster
.
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
)
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
.
cluster
.
service_delete
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
await
ctx
.
cluster
.
service_delete
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
删除成功
'
)
})
router
.
post
(
'
/modifyImage
'
,
async
ctx
=>
{
await
ctx
.
cluster
.
service_modifyImage
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
image
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
更新成功
'
)
await
ctx
.
cluster
.
service_modifyImage
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
image
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
'
更新成功
'
)
})
package-lock.json
View file @
4e90d54c
This diff is collapsed.
Click to expand it.
services/tke.clusterService.js
View file @
4e90d54c
...
...
@@ -27,14 +27,10 @@ class Cluster extends Client {
return
this
.
post
(
'
DescribeClusterServiceInfo
'
,
{
serviceName
,
namespace
,
clusterId
:
this
.
clusterId
})
}
async
service_create
(
params
,
type
)
{
async
service_create
(
params
,
type
)
{
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)
let
updateLabels
=
{
clusterId
:
params
.
clusterId
,
serviceName
:
params
.
serviceName
,
...
...
@@ -50,9 +46,9 @@ class Cluster extends Client {
}
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
})
}
...
...
services/tke.service.js
View file @
4e90d54c
...
...
@@ -2,159 +2,85 @@ const request = require('request')
const
crypto
=
require
(
'
crypto
'
)
const
domainConfig
=
require
(
'
../config
'
)
class
Client
{
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
class
Client
{
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
'
]
}
sign
(
params
,
signMethod
)
{
let
str
=
''
let
keys
=
Object
.
keys
(
params
)
keys
.
sort
()
for
(
let
key
of
keys
)
{
str
+=
'
&
'
+
key
+
'
=
'
+
params
[
key
]
// 禁止操作以下命名空间
this
.
defaultNamespaces
=
[
'
default
'
,
'
kube-system
'
,
'
kube-public
'
]
}
str
=
str
.
slice
(
1
)
let
signStr
=
this
.
method
+
this
.
endpoint
+
this
.
path
+
'
?
'
+
str
let
signMethodMap
=
{
HmacSHA1
:
"
sha1
"
,
HmacSHA256
:
"
sha256
"
}
let
hmac
=
crypto
.
createHmac
(
signMethodMap
[
signMethod
],
this
.
secretKey
)
return
hmac
.
update
(
Buffer
.
from
(
signStr
,
'
utf-8
'
)).
digest
(
'
base64
'
)
}
sign
(
params
,
signMethod
)
{
let
str
=
''
let
keys
=
Object
.
keys
(
params
)
keys
.
sort
()
for
(
let
key
of
keys
)
{
str
+=
'
&
'
+
key
+
'
=
'
+
params
[
key
]
}
str
=
str
.
slice
(
1
)
let
signStr
=
this
.
method
+
this
.
endpoint
+
this
.
path
+
'
?
'
+
str
// 公共参数
// Action: '',
// Region: '',
// Timestamp: null,
// Nonce: null,
// SecretId: '',
// Signature: ''
formatRequestData
(
action
,
params
=
{})
{
params
.
Action
=
action
params
.
Region
=
this
.
region
params
.
Timestamp
=
Math
.
round
(
Date
.
now
()
/
1000
)
params
.
Nonce
=
Math
.
round
(
Math
.
random
()
*
65535
)
params
.
SecretId
=
this
.
secretId
params
.
SignatureMethod
=
params
.
SignatureMethod
||
'
HmacSHA256
'
params
.
Signature
=
this
.
sign
(
params
,
params
.
SignatureMethod
)
}
let
signMethodMap
=
{
HmacSHA1
:
"
sha1
"
,
HmacSHA256
:
"
sha256
"
}
let
hmac
=
crypto
.
createHmac
(
signMethodMap
[
signMethod
],
this
.
secretKey
)
return
hmac
.
update
(
Buffer
.
from
(
signStr
,
'
utf-8
'
)).
digest
(
'
base64
'
)
}
post
(
action
,
params
=
{})
{
if
(
params
.
namespace
&&
this
.
defaultNamespaces
.
includes
(
params
.
namespace
))
{
return
Promise
.
reject
(
new
Error
(
'
未授权的namespace
'
))
// 公共参数
// Action: '',
// Region: '',
// Timestamp: null,
// Nonce: null,
// SecretId: '',
// Signature: ''
formatRequestData
(
action
,
params
=
{})
{
params
.
Action
=
action
params
.
Region
=
this
.
region
params
.
Timestamp
=
Math
.
round
(
Date
.
now
()
/
1000
)
params
.
Nonce
=
Math
.
round
(
Math
.
random
()
*
65535
)
params
.
SecretId
=
this
.
secretId
params
.
SignatureMethod
=
params
.
SignatureMethod
||
'
HmacSHA256
'
params
.
Signature
=
this
.
sign
(
params
,
params
.
SignatureMethod
)
}
this
.
formatRequestData
(
action
,
params
)
let
url
=
this
.
protocal
+
this
.
endpoint
+
this
.
path
let
self
=
this
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
({
method
:
self
.
method
,
url
,
json
:
true
,
form
:
params
},
function
(
err
,
res
,
body
)
{
if
(
err
)
{
console
.
error
(
err
)
reject
(
err
)
}
else
{
if
(
body
.
code
===
0
)
{
resolve
(
body
.
data
)
}
else
{
reject
(
body
)
}
post
(
action
,
params
=
{})
{
if
(
params
.
namespace
&&
this
.
defaultNamespaces
.
includes
(
params
.
namespace
))
{
return
Promise
.
reject
(
new
Error
(
'
未授权的namespace
'
))
}
})
})
}
// 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})
// }
this
.
formatRequestData
(
action
,
params
)
let
url
=
this
.
protocal
+
this
.
endpoint
+
this
.
path
let
self
=
this
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
({
method
:
self
.
method
,
url
,
json
:
true
,
form
:
params
},
function
(
err
,
res
,
body
)
{
if
(
err
)
{
console
.
error
(
err
)
reject
(
err
)
}
else
{
if
(
body
.
code
===
0
)
{
resolve
(
body
.
data
)
}
else
{
reject
(
body
)
}
}
})
})
}
}
module
.
exports
=
Client
// exports.create = function (config) {
// return new Client(config)
// }
// let client = new Client({
// secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac',
// secretKey: 'YBduRnjgVRGzmagZJbss3Vo58wWCyhgc',
// clusterId: 'cls-acfx4pvj',
// region: 'ap-beijing'
// })
// client.post('DescribeClusterNameSpaces', {clusterId: 'cls-acfx4pvj'}).then(res => {
// console.log(5, res)
// })
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