Commit 95761937 authored by 智勇's avatar 智勇

异常处理

parent 9f0228cf
...@@ -13,7 +13,7 @@ const { ...@@ -13,7 +13,7 @@ const {
serviceRestart, serviceRestart,
serviceDelete, serviceDelete,
imageUpdate, imageUpdate,
getReplicaSet, // getReplicaSet,
replicaSetDelete, replicaSetDelete,
} = require('../kubeService/service') } = require('../kubeService/service')
...@@ -68,18 +68,20 @@ router.post('/details', async (ctx) => { ...@@ -68,18 +68,20 @@ router.post('/details', async (ctx) => {
router.post('/delete', async (ctx) => { router.post('/delete', async (ctx) => {
const { namespace, serviceName } = ctx.request.body const { namespace, serviceName } = ctx.request.body
await serviceDelete(namespace, serviceName) await serviceDelete(namespace, serviceName)
await replicaSetDelete(namespace, serviceName)
let rsData = await getReplicaSet(namespace) // let rsData = await getReplicaSet(namespace)
rsData = rsData.map(item => item.metadata.name).filter(item => item.indexOf(serviceName) !== -1) // rsData = rsData.map(item => item.metadata.name).filter(item => item.indexOf(serviceName) !== -1)
for (const rs of rsData) { // for (const rs of rsData) {
await replicaSetDelete(namespace, rs) // await replicaSetDelete(namespace, rs)
} // }
if (ctx.request.body.serviceName === 'xyqb-user2') { await ingressDelete(namespace, serviceName)
await ingressDelete(ctx.request.body.namespace, 'xyqb-user2-2') if (serviceName === 'xyqb-user2') {
await ingressDelete(namespace, 'xyqb-user2-2')
} }
await ingressDelete(ctx.request.body.namespace, ctx.request.body.serviceName)
ctx.body = ctx.ok('删除成功') ctx.body = ctx.ok('删除成功')
}) })
...@@ -88,7 +90,6 @@ router.post('/modifyImage', async (ctx) => { ...@@ -88,7 +90,6 @@ router.post('/modifyImage', async (ctx) => {
list = list.body.items.map(item => (item.metadata.labels && item.metadata.labels['qcloud-app']) || item.metadata.name) list = list.body.items.map(item => (item.metadata.labels && item.metadata.labels['qcloud-app']) || item.metadata.name)
if (list.includes(ctx.request.body.serviceName)) { if (list.includes(ctx.request.body.serviceName)) {
logger.info('更新服务', ctx.request.body)
await imageUpdate(ctx.request.body) await imageUpdate(ctx.request.body)
// const data = ctx.request.body // const data = ctx.request.body
......
...@@ -45,7 +45,7 @@ const ingressGet = async (namespace, servicename) => client.apis.extensions.v1be ...@@ -45,7 +45,7 @@ const ingressGet = async (namespace, servicename) => client.apis.extensions.v1be
const ingressCreate = async (namespace, servicename, doamin) => { const ingressCreate = async (namespace, servicename, doamin) => {
const Manifest = getManifest(namespace, servicename, doamin) const Manifest = getManifest(namespace, servicename, doamin)
logger.info('创建ingress', Manifest) logger.info('创建ingress', JSON.stringify(Manifest))
await client.apis.extensions.v1beta1.namespace(namespace).ingresses await client.apis.extensions.v1beta1.namespace(namespace).ingresses
.post({ body: Manifest }) .post({ body: Manifest })
} }
......
...@@ -47,12 +47,12 @@ const serviceCreate = async (data) => { ...@@ -47,12 +47,12 @@ const serviceCreate = async (data) => {
switch (jsonObj.kind) { switch (jsonObj.kind) {
case 'Service': case 'Service':
logger.info('service:', JSON.stringify(jsonObj)) logger.info('创建svc', JSON.stringify(jsonObj))
await client.api.v1.namespaces(namespace).services.post({ body: jsonObj }) await client.api.v1.namespaces(namespace).services.post({ body: jsonObj })
break; break;
case 'Deployment': case 'Deployment':
logger.info('Deployment:', JSON.stringify(jsonObj)) logger.info('创建deploy', JSON.stringify(jsonObj))
await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: jsonObj }) await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: jsonObj })
break; break;
...@@ -75,6 +75,8 @@ const imageUpdate = async (data) => { ...@@ -75,6 +75,8 @@ const imageUpdate = async (data) => {
const { namespace, serviceName } = data const { namespace, serviceName } = data
const image = `ccr.ccs.tencentyun.com/${data.image}` const image = `ccr.ccs.tencentyun.com/${data.image}`
const updateObj = { spec: { template: { spec: { containers: [{ name: serviceName, image }] } } } } const updateObj = { spec: { template: { spec: { containers: [{ name: serviceName, image }] } } } }
logger.info('更新服务', namespace, JSON.stringify(updateObj))
await client.apis.apps.v1beta1.namespaces(namespace).deployments(serviceName).patch({ body: updateObj }) await client.apis.apps.v1beta1.namespaces(namespace).deployments(serviceName).patch({ body: updateObj })
} }
...@@ -221,8 +223,14 @@ const serviceRestart = async (namespace, name) => { ...@@ -221,8 +223,14 @@ const serviceRestart = async (namespace, name) => {
} }
const serviceDelete = async (namespace, name) => { const serviceDelete = async (namespace, name) => {
await client.api.v1.namespaces(namespace).services(name).delete() try {
await client.apis.apps.v1beta1.namespaces(namespace).deployments(name).delete() logger.info('删除deploy', namespace, name)
await client.apis.apps.v1beta1.namespaces(namespace).deployments(name).delete()
logger.info('删除svc', namespace, name)
await client.api.v1.namespaces(namespace).services(name).delete()
} catch (error) {
logger.error(error)
}
} }
const getReplicaSet = async (namespace) => { const getReplicaSet = async (namespace) => {
...@@ -230,8 +238,10 @@ const getReplicaSet = async (namespace) => { ...@@ -230,8 +238,10 @@ const getReplicaSet = async (namespace) => {
return rsData.body.items return rsData.body.items
} }
const replicaSetDelete = async (namespace, rsName) => { const replicaSetDelete = async (namespace, name) => {
await client.apis.apps.v1.namespaces(namespace).replicasets(rsName).delete() logger.info('删除rs', namespace, name)
await client.apis.apps.v1.namespaces(namespace).replicasets.delete({ qs: { labelSelector: `qcloud-app=${name}` } })
// await client.apis.apps.v1.namespaces(namespace).replicasets(rsName).delete()
} }
const getServices = async (namespace) => { const getServices = async (namespace) => {
......
...@@ -101,7 +101,7 @@ projectConfig['gu-bei'] = projectConfig['cash-loan-flow'] = projectConfig['black ...@@ -101,7 +101,7 @@ projectConfig['gu-bei'] = projectConfig['cash-loan-flow'] = projectConfig['black
projectConfig.notify = projectConfig.gyxd = projectConfig['business-flow'] = defaultConfig projectConfig.notify = projectConfig.gyxd = projectConfig['business-flow'] = defaultConfig
// clotho启动比较耗时 // clotho启动比较耗时
projectConfig.clotho = { projectConfig['urge-dispatcher'] = projectConfig.clotho = {
memory: { memory: {
request: 800, request: 800,
limit: 1500, limit: 1500,
...@@ -123,7 +123,7 @@ projectConfig['xyqb-user2'] = projectConfig.xyqb = { ...@@ -123,7 +123,7 @@ projectConfig['xyqb-user2'] = projectConfig.xyqb = {
}, },
} }
projectConfig['urge-dispatcher'] = projectConfig['traffic-webapp'] = _.assign({}, defaultJava, { projectConfig['traffic-webapp'] = _.assign({}, defaultJava, {
memory: { memory: {
request: 100, request: 100,
limit: 200, limit: 200,
......
apiVersion: v1
kind: Service
metadata:
labels:
type: {{label}}
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: {{serviceType}}
ports:
- name: '80'
port: 80
- name: '5005'
port: 5005
selector:
qcloud-app: {{serviceName}}
---
apiVersion: apps/v1beta1 apiVersion: apps/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
...@@ -29,6 +49,8 @@ spec: ...@@ -29,6 +49,8 @@ spec:
env: env:
- name: NAMESPACE - name: NAMESPACE
value: {{namespace}} value: {{namespace}}
- name: SYSTEM_NAME
value: {{serviceName}}
- name: DEBUG - name: DEBUG
value: {{debug}} value: {{debug}}
resources: resources:
...@@ -52,23 +74,3 @@ spec: ...@@ -52,23 +74,3 @@ spec:
imagePullSecrets: imagePullSecrets:
- name: qcloudregistrykey - name: qcloudregistrykey
- name: tencenthubkey - name: tencenthubkey
---
apiVersion: v1
kind: Service
metadata:
labels:
type: {{label}}
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: {{serviceType}}
ports:
- name: '80'
port: 80
- name: '5005'
port: 5005
selector:
qcloud-app: {{serviceName}}
...@@ -66,6 +66,7 @@ spec: ...@@ -66,6 +66,7 @@ spec:
status: {} status: {}
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
......
apiVersion: v1
kind: Service
metadata:
labels:
type: base
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: NodePort
ports:
- port: 3306
selector:
qcloud-app: {{serviceName}}
---
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
apiVersion: v1 apiVersion: v1
metadata: metadata:
...@@ -68,19 +85,3 @@ spec: ...@@ -68,19 +85,3 @@ spec:
restartPolicy: Always restartPolicy: Always
terminationGracePeriodSeconds: 30 terminationGracePeriodSeconds: 30
status: {} status: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
type: base
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: NodePort
ports:
- port: 3306
selector:
qcloud-app: {{serviceName}}
apiVersion: v1
kind: Service
metadata:
labels:
type: {{label}}
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: ClusterIP
ports:
- port: 80
selector:
qcloud-app: {{serviceName}}
---
apiVersion: apps/v1beta1 apiVersion: apps/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
...@@ -29,6 +46,8 @@ spec: ...@@ -29,6 +46,8 @@ spec:
env: env:
- name: NAMESPACE - name: NAMESPACE
value: {{namespace}} value: {{namespace}}
- name: SYSTEM_NAME
value: {{serviceName}}
- name: DEBUG - name: DEBUG
value: {{debug}} value: {{debug}}
- name: NODE_ENV - name: NODE_ENV
...@@ -45,20 +64,3 @@ spec: ...@@ -45,20 +64,3 @@ spec:
imagePullSecrets: imagePullSecrets:
- name: qcloudregistrykey - name: qcloudregistrykey
- name: tencenthubkey - name: tencenthubkey
---
apiVersion: v1
kind: Service
metadata:
labels:
type: {{label}}
qcloud-app: {{serviceName}}
name: {{serviceName}}
namespace: {{namespace}}
spec:
type: ClusterIP
ports:
- port: 80
selector:
qcloud-app: {{serviceName}}
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