Commit 3f8a5339 authored by kewei.jia's avatar kewei.jia

修改了TYPES信息

parent 042a4baa
...@@ -7,33 +7,39 @@ const result = require('../middleware/result') ...@@ -7,33 +7,39 @@ const result = require('../middleware/result')
const namespaceRoute = require('./namespace') const namespaceRoute = require('./namespace')
const serviceRoute = require('./service') const serviceRoute = require('./service')
const repositoryRouter = require('./repository')
const tag = require('./tag')
// const rabbitmqRoute = require('./rabbitmq') // const rabbitmqRoute = require('./rabbitmq')
// const zookeeperRoute = require('./zookeeper') // const zookeeperRoute = require('./zookeeper')
const commonServiceRoute = require('./commonService') const commonServiceRoute = require('./commonService')
const ingressRoute = require('./ingress') const ingressRoute = require('./ingress')
const client = require('../services/tke.service').create({ // const client = require('../services/tke.service').create({
secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac', // secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac',
secretKey: 'YBduRnjgVRGzmagZJbss3Vo58wWCyhgc', // secretKey: 'YBduRnjgVRGzmagZJbss3Vo58wWCyhgc',
clusterId: 'cls-acfx4pvj', // clusterId: 'cls-acfx4pvj',
region: 'ap-beijing' // region: 'ap-beijing'
}) // })
const cluster = require('../services/tke.clusterService').create()
const container = require('../services/tke.containerService').create()
function loadRoutes (router) { function loadRoutes (router) {
router router
.use(error()) .use(error())
.use(result()) .use(result())
.use(async (ctx, next) => { .use(async (ctx, next) => {
// 腾讯云 // 腾讯云
ctx.client = client ctx.container = container
ctx.cluster = cluster
await next() await next()
}, bodyParser()) }, bodyParser())
.use('/namespace', namespaceRoute.routes()) .use('/namespace', namespaceRoute.routes())
.use('/service', serviceRoute.routes()) .use('/service', serviceRoute.routes())
// .use('/rabbitmq', rabbitmqRoute.routes()) // .use('/rabbitmq', rabbitmqRoute.routes())
// .use('/zookeeper', zookeeperRoute.routes()) // .use('/zookeeper', zookeeperRoute.routes())
.use('/commonService', commonServiceRoute.routes()) .use('/commonService', commonServiceRoute.routes())
.use('/ingress', ingressRoute.routes()) .use('/ingress', ingressRoute.routes())
.use('/repository',repositoryRouter.routes())
.use('/tag',tag.routes())
} }
exports.start = function () { exports.start = function () {
......
...@@ -4,17 +4,17 @@ const router = new Router(); ...@@ -4,17 +4,17 @@ const router = new Router();
module.exports = router module.exports = router
router.get('/', async ctx => { router.get('/', async ctx => {
let data = await ctx.client.namespace_get() let data = await ctx.cluster.namespace_get()
ctx.body = ctx.ok(data) ctx.body = ctx.ok(data)
}) })
router.post('/create', async ctx => { router.post('/create', async ctx => {
await ctx.client.namespace_create(ctx.request.body.name) await ctx.cluster.namespace_create(ctx.request.body.name)
await ctx.client.ingress_create(ctx.request.body.name) await ctx.cluster.ingress_create(ctx.request.body.name)
ctx.body = ctx.ok() ctx.body = ctx.ok()
}) })
router.post('/delete', async ctx => { router.post('/delete', async ctx => {
await ctx.client.namespace_delete(ctx.request.body.name) await ctx.cluster.namespace_delete(ctx.request.body.name)
ctx.body = ctx.ok() ctx.body = ctx.ok()
}) })
...@@ -2,24 +2,24 @@ const Router = require('koa-router') ...@@ -2,24 +2,24 @@ const Router = require('koa-router')
const yaml = require('js-yaml') const yaml = require('js-yaml')
const templates = require('../serviceTemplate') const templates = require('../serviceTemplate')
const TYPES = ['ui', 'java', 'nodejs', 'python', 'go'] const TYPES = ['ui', 'java', 'node', 'python', 'go']
const router = new Router() const router = new Router()
module.exports = router module.exports = router
router.get('/', async ctx => { router.get('/', async ctx => {
let data = await ctx.client.service_list(ctx.query.namespace) let data = await ctx.cluster.service_list(ctx.query.namespace)
ctx.body = ctx.ok(data) ctx.body = ctx.ok(data)
}) })
router.post('/create', async ctx => { 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)) { if (!TYPES.includes(type)) {
return ctx.body = ctx.fail('不支持的服务类型') return ctx.body = ctx.fail('不支持的服务类型')
} }
// try { // try {
// let svc = await ctx.client.service_get(serviceName, namespace) // let svc = await ctx.cluster.service_get(serviceName, namespace)
// if (svc) { // if (svc) {
// return ctx.body = ctx.fail('服务已经存在') // return ctx.body = ctx.fail('服务已经存在')
// } // }
...@@ -30,7 +30,8 @@ router.post('/create', async ctx => { ...@@ -30,7 +30,8 @@ router.post('/create', async ctx => {
serviceName, serviceName,
namespace, namespace,
image, image,
system_name system_name,
lable
} }
if (!system_name) { if (!system_name) {
// ui abTest的时候不一样 // ui abTest的时候不一样
...@@ -43,16 +44,19 @@ router.post('/create', async ctx => { ...@@ -43,16 +44,19 @@ router.post('/create', async ctx => {
return data[arguments[1]] return data[arguments[1]]
}) })
let params = yaml.load(template) let params = yaml.load(template)
await ctx.client.service_create(params) await ctx.cluster.service_create(params,type)
ctx.body = ctx.ok('创建成功') 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 => { router.post('/delete', async ctx => {
await ctx.client.service_delete(ctx.request.body.serviceName, ctx.request.body.namespace) await ctx.cluster.service_delete(ctx.request.body.serviceName, ctx.request.body.namespace)
ctx.body = ctx.ok('删除成功') ctx.body = ctx.ok('删除成功')
}) })
router.post('/modifyImage', async ctx => { router.post('/modifyImage', async ctx => {
await ctx.client.service_modifyImage(ctx.request.body.serviceName, ctx.request.body.image, ctx.request.body.namespace) await ctx.cluster.service_modifyImage(ctx.request.body.serviceName, ctx.request.body.image, ctx.request.body.namespace)
ctx.body = ctx.ok('更新成功') ctx.body = ctx.ok('更新成功')
}) })
const fs = require('fs') const fs = require('fs')
const ui = fs.readFileSync('serviceTemplate/ui.template.txt', 'utf8') const ui = fs.readFileSync('serviceTemplate/ui.template.txt', 'utf8')
const java = fs.readFileSync('serviceTemplate/java.template.txt', 'utf8') const java = fs.readFileSync('serviceTemplate/java.template.txt', 'utf8')
const nodejs = 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 rabbitmq = fs.readFileSync('serviceTemplate/rabbitmq.template.txt', 'utf8')
const zookeeper = fs.readFileSync('serviceTemplate/zookeeper.template.txt', 'utf8') const zookeeper = fs.readFileSync('serviceTemplate/zookeeper.template.txt', 'utf8')
const mysql = fs.readFileSync('serviceTemplate/mysql.template.txt', 'utf8') const mysql = fs.readFileSync('serviceTemplate/mysql.template.txt', 'utf8')
module.exports = { module.exports = {
ui, ui,
nodejs, node,
java, java,
rabbitmq, rabbitmq,
zookeeper, zookeeper,
......
const request = require('request') const request = require('request')
const crypto = require('crypto') const crypto = require('crypto')
const domainConfig = require('../config')
class Client { class Client {
constructor ({secretId, secretKey, region, clusterId}) { constructor () {
this.secretId = secretId this.secretId = domainConfig.secretId
this.secretKey = secretKey this.secretKey = domainConfig.secretKey
this.region = region this.region = domainConfig.region
this.clusterId = clusterId this.clusterId = domainConfig.clusterId
this.method = 'POST' this.method = domainConfig.method
this.protocal = 'https://' this.protocal = domainConfig.protocal
this.endpoint = 'ccs.api.qcloud.com' this.endpoint = ''
this.path = '/v2/index.php' this.path = domainConfig.path
this.domain = ".lkbang.com" this.domain = domainConfig.domain
// 禁止操作以下命名空间 // 禁止操作以下命名空间
this.defaultNamespaces = ['default', 'kube-system', 'kube-public'] this.defaultNamespaces = ['default', 'kube-system', 'kube-public']
...@@ -63,7 +64,7 @@ class Client { ...@@ -63,7 +64,7 @@ class Client {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
request({ request({
method: self.method, method: self.method,
url, url,
json: true, json: true,
form: params form: params
}, function (err, res, body) { }, function (err, res, body) {
...@@ -81,66 +82,71 @@ class Client { ...@@ -81,66 +82,71 @@ class Client {
}) })
} }
namespace_get () { // namespace_get () {
return this.post('DescribeClusterNameSpaces', {clusterId: this.clusterId}) // return this.post('DescribeClusterNameSpaces', {clusterId: this.clusterId})
} // }
//
namespace_create (name) { // namespace_create (name) {
return this.post('CreateClusterNamespace', {name, description: '', clusterId: this.clusterId}) // return this.post('CreateClusterNamespace', {name, description: '', clusterId: this.clusterId})
} // }
//
namespace_delete (name) { // namespace_delete (name) {
return this.post('DeleteClusterNamespace', {"names.0": name, clusterId: this.clusterId}) // return this.post('DeleteClusterNamespace', {"names.0": name, clusterId: this.clusterId})
} // }
service_list (namespace) { // service_list (namespace) {
return this.post('DescribeClusterService', {namespace, clusterId: this.clusterId, allnamespace: 0}) // return this.post('DescribeClusterService', {namespace, clusterId: this.clusterId, allnamespace: 0})
} // }
//
service_get (serviceName, namespace) { // service_get (serviceName, namespace) {
return this.post('DescribeClusterServiceInfo', {serviceName, namespace, clusterId: this.clusterId}) // return this.post('DescribeClusterServiceInfo', {serviceName, namespace, clusterId: this.clusterId})
} // }
//
async service_create (params) { // async service_create (params) {
params.clusterId = this.clusterId // params.clusterId = this.clusterId
let str = JSON.stringify(params) // let str = JSON.stringify(params)
await this.post('CreateClusterService', params) // await this.post('CreateClusterService', params)
// 腾讯云api暂只能通过修改服务来改成Recreate策略 // // 腾讯云api暂只能通过修改服务来改成Recreate策略
let modifyParams = JSON.parse(str) // let modifyParams = JSON.parse(str)
modifyParams.strategy = 'Recreate' // modifyParams.strategy = 'Recreate'
return this.post('ModifyClusterService', modifyParams) // return this.post('ModifyClusterService', modifyParams)
} // }
//
service_delete (serviceName, namespace) { // service_delete (serviceName, namespace) {
return this.post('DeleteClusterService', {serviceName, namespace, clusterId: this.clusterId}) // return this.post('DeleteClusterService', {serviceName, namespace, clusterId: this.clusterId})
} // }
//
service_modifyImage (serviceName, image, namespace) { // service_modifyImage (serviceName, image, namespace) {
// 修改示例的第一个容器 // // 修改示例的第一个容器
return this.post('ModifyClusterServiceImage', {serviceName, namespace, image, clusterId: this.clusterId}) // return this.post('ModifyClusterServiceImage', {serviceName, namespace, image, clusterId: this.clusterId})
} // }
//
ingress_get (namespace) { // ingress_get (namespace) {
return this.post('DescribeIngress', {namespace, clusterId: this.clusterId}) // return this.post('DescribeIngress', {namespace, clusterId: this.clusterId})
} // }
//
ingress_create (namespace) { // ingress_create (namespace) {
return this.post('CreateIngress', {ingressName: `qa-${namespace}`, ingressDesc: '', namespace, clusterId: this.clusterId}) // return this.post('CreateIngress', {ingressName: `qa-${namespace}`, ingressDesc: '', namespace, clusterId: this.clusterId})
} // }
//
ingress_delete (ingressName, namespace) { // ingress_delete (ingressName, namespace) {
return this.post('DeleteIngress', {ingressName, namespace, clusterId: this.clusterId}) // return this.post('DeleteIngress', {ingressName, namespace, clusterId: this.clusterId})
} // }
//
ingress_modify (ingressName, namespace, rules) { // ingress_modify (ingressName, namespace, rules) {
return this.post('MosifyIngress', {ingressName, namespace, ...rules, clusterId: this.clusterId}) // return this.post('MosifyIngress', {ingressName, namespace, ...rules, clusterId: this.clusterId})
} // }
//腾讯仓库列表
// repository_get(namespace1, reponame1) {
// return this.post('SearchUserRepository', {reponame})
// }
} }
exports.create = function (config) { module.exports = Client
return new Client(config) // exports.create = function (config) {
} // return new Client(config)
// }
// let client = new Client({ // let client = new Client({
// secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac', // secretId: 'AKID4rY7wwNphsUcaFsy1pRtKhQvDj4CA3Ac',
...@@ -151,4 +157,4 @@ exports.create = function (config) { ...@@ -151,4 +157,4 @@ exports.create = function (config) {
// client.post('DescribeClusterNameSpaces', {clusterId: 'cls-acfx4pvj'}).then(res => { // client.post('DescribeClusterNameSpaces', {clusterId: 'cls-acfx4pvj'}).then(res => {
// console.log(5, res) // console.log(5, res)
// }) // })
\ No newline at end of file
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