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

修改了TYPES信息

parent 042a4baa
......@@ -7,25 +7,29 @@ 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())
......@@ -34,6 +38,8 @@ function loadRoutes (router) {
// .use('/zookeeper', zookeeperRoute.routes())
.use('/commonService', commonServiceRoute.routes())
.use('/ingress', ingressRoute.routes())
.use('/repository',repositoryRouter.routes())
.use('/tag',tag.routes())
}
exports.start = function () {
......
......@@ -4,17 +4,17 @@ const router = new Router();
module.exports = router
router.get('/', async ctx => {
let data = await ctx.client.namespace_get()
let data = await ctx.cluster.namespace_get()
ctx.body = ctx.ok(data)
})
router.post('/create', async ctx => {
await ctx.client.namespace_create(ctx.request.body.name)
await ctx.client.ingress_create(ctx.request.body.name)
await ctx.cluster.namespace_create(ctx.request.body.name)
await ctx.cluster.ingress_create(ctx.request.body.name)
ctx.body = ctx.ok()
})
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()
})
......@@ -2,24 +2,24 @@ const Router = require('koa-router')
const yaml = require('js-yaml')
const templates = require('../serviceTemplate')
const TYPES = ['ui', 'java', 'nodejs', 'python', 'go']
const TYPES = ['ui', 'java', 'node', 'python', 'go']
const router = new Router()
module.exports = router
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)
})
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.client.service_get(serviceName, namespace)
// let svc = await ctx.cluster.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.client.service_create(params)
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)
})
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('删除成功')
})
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('更新成功')
})
const fs = require('fs')
const ui = fs.readFileSync('serviceTemplate/ui.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 zookeeper = fs.readFileSync('serviceTemplate/zookeeper.template.txt', 'utf8')
const mysql = fs.readFileSync('serviceTemplate/mysql.template.txt', 'utf8')
module.exports = {
ui,
nodejs,
node,
java,
rabbitmq,
zookeeper,
......
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']
......@@ -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',
......
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