Commit 0892b50a authored by 智勇's avatar 智勇

更新部署

parent 014642b6
......@@ -15,7 +15,7 @@ const {
serviceRestart,
serviceDelete,
imageUpdate,
// getReplicaSet,
deployUpdate,
replicaSetDelete,
pvcDelete,
} = require('../kubeService/service')
......@@ -72,7 +72,6 @@ router.post('/details', async (ctx) => {
router.post('/delete', async (ctx) => {
const { namespace, serviceName, podName } = ctx.request.body
const key = `${namespace}:${podName}#${serviceName}`
console.log(key)
const res = await redis.get(key)
await redis.del(key)
if (res) {
......@@ -101,15 +100,6 @@ router.post('/modifyImage', async (ctx) => {
if (list.includes(ctx.request.body.serviceName)) {
await imageUpdate(ctx.request.body)
// const data = ctx.request.body
// if (!data.label) {
// data.label = data.type
// }
// const resources = makeResouce(data.serviceName, data.label)
// data.resources = resources
// logger.info('更新服务', data)
// await serviceUpdate(data)
} else {
await createService(ctx)
}
......@@ -117,6 +107,18 @@ router.post('/modifyImage', async (ctx) => {
ctx.body = ctx.ok('更新成功')
})
router.post('/modifyDeploy', async (ctx) => {
const data = ctx.request.body
if (!data.label) {
data.label = data.type
}
const resources = makeResouce(data.serviceName, data.label)
data.resources = resources
await deployUpdate(data)
ctx.body = ctx.ok('更新成功')
})
router.post('/redeploy', async (ctx) => {
const key = `${ctx.request.body.namespace}:${ctx.request.body.podName}#${ctx.request.body.serviceName}`
const res = await redis.get(key)
......
......@@ -11,7 +11,7 @@ module.exports = {
path: '/v2/index.php',
domain: '.lkbang.com',
noHealthCheckApp: [
'acs-batch', 'acs-quartz', 'acs-service', 'pcm', 'talos', 'app-server'
]
'acs-batch', 'acs-quartz', 'acs-service', 'pcm', 'vcc-talos', 'app-server',
],
}
......@@ -35,37 +35,35 @@ const makeManifest = (data) => {
return _.get(data, arguments[1])
})
const yamlArray = yamlManifest.split('---')
return yamlArray
const manifestArray = yamlManifest.split('---')
return manifestArray
}
const serviceCreate = async (data) => {
const { namespace, serviceName } = data
const yamlArray = makeManifest(data)
for (const item of yamlArray) {
const jsonObj = yaml.load(item);
const manifestArray = makeManifest(data)
for (const item of manifestArray) {
let manifest = yaml.load(item);
let pvc
let pvcName
switch (jsonObj.kind) {
switch (manifest.kind) {
case 'Service':
if (data.wechat === '"1"') {
jsonObj.spec.type = 'NodePort'
manifest.spec.type = 'NodePort'
}
logger.info('创建svc', JSON.stringify(jsonObj))
await client.api.v1.namespaces(namespace).services.post({ body: jsonObj })
logger.info('创建svc', JSON.stringify(manifest))
await client.api.v1.namespaces(namespace).services.post({ body: manifest })
break;
case 'Deployment':
let obj = jsonObj
if (APP_CONFIG.noHealthCheckApp.includes(serviceName)) {
obj = _.omit(jsonObj, ['spec.template.spec.containers[0].readinessProbe'])
manifest = _.omit(manifest, ['spec.template.spec.containers[0].readinessProbe'])
}
logger.info('创建deploy', serviceName, JSON.stringify(obj))
logger.info('创建deploy', serviceName, JSON.stringify(manifest))
await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: obj })
await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: manifest })
break;
case 'PersistentVolumeClaim':
......@@ -73,8 +71,8 @@ const serviceCreate = async (data) => {
pvc = await client.api.v1.namespaces(namespace).persistentvolumeclaims.get()
pvc = pvc.body.items.filter(item => item.metadata.name === pvcName)
if (!pvc.length) {
logger.info('创建pvc', JSON.stringify(jsonObj))
await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: jsonObj })
logger.info('创建pvc', JSON.stringify(manifest))
await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: manifest })
}
break;
......@@ -93,15 +91,15 @@ const imageUpdate = async (data) => {
await client.apis.apps.v1beta1.namespaces(namespace).deployments(serviceName).patch({ body: updateObj })
}
const serviceUpdate = async (data) => {
const deployUpdate = async (data) => {
const { namespace, serviceName } = data
const yamlArray = makeManifest(data)
const manifestArray = makeManifest(data)
for (const item of yamlArray) {
const jsonObj = yaml.load(item);
if (jsonObj.kind === 'Deployment') {
logger.info('Deployment:', JSON.stringify(jsonObj))
await client.apis.apps.v1beta1.namespaces(namespace).deployments(serviceName).put({ body: jsonObj })
for (const item of manifestArray) {
const manifest = yaml.load(item);
if (manifest.kind === 'Deployment') {
logger.info('更新deploy:', JSON.stringify(manifest))
await client.apis.apps.v1beta1.namespaces(namespace).deployments(serviceName).put({ body: manifest })
}
}
}
......@@ -281,7 +279,7 @@ module.exports = {
getPods,
podGetstatus,
serviceCreate,
serviceUpdate,
deployUpdate,
serviceRestart,
serviceDelete,
imageUpdate,
......
......@@ -115,6 +115,11 @@ const defaultJava = {
cpu: cpuV3,
}
projectConfig.baitiao = {
memory: memoryV3,
cpu: cpuV3,
}
projectConfig['cash-loan-flow'] = projectConfig['gu-bei'] = projectConfig['merchant-backend'] = projectConfig['xyqb-mall'] = projectConfig.xyqb = {
memory: memoryV3,
cpu: cpuV4,
......
......@@ -39,6 +39,7 @@ spec:
labels:
qcloud-app: {{serviceName}}
type: {{label}}
mock: {{mock}}
spec:
terminationGracePeriodSeconds: 0
containers:
......
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