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

更新部署

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