Commit 95761937 authored by 智勇's avatar 智勇

异常处理

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