Commit a836920d authored by 智勇's avatar 智勇

优化删除rs

parent cf6608b1
......@@ -4,7 +4,15 @@ const logger = require('koa-log4').getLogger()
const { ingressCreate, ingressDelete } = require('../kubeService/ingress')
const { projectConfig, defaultConfig } = require('../serviceTemplate/resourceLimit')
const {
getPods, serviceCreate, getServices, getServiceDetail, serviceRestart, serviceDelete, imageUpdate,
getPods,
serviceCreate,
getServices,
getServiceDetail,
serviceRestart,
serviceDelete,
imageUpdate,
getReplicaSet,
replicaSetDelete,
} = require('../kubeService/service')
const router = new Router()
......@@ -57,8 +65,16 @@ router.post('/details', async (ctx) => {
})
router.post('/delete', async (ctx) => {
const rsName = ctx.request.body.podName.slice(0, -6)
await serviceDelete(ctx.request.body.namespace, ctx.request.body.serviceName, rsName)
const { namespace, serviceName } = ctx.request.body
await serviceDelete(namespace, serviceName)
// const rsName = ctx.request.body.podName.slice(0, -6)
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')
}
......
......@@ -221,10 +221,18 @@ const serviceRestart = async (namespace, name) => {
await client.api.v1.namespaces(namespace).pods(name).delete()
}
const serviceDelete = async (namespace, name, rsName) => {
const serviceDelete = async (namespace, name) => {
await client.api.v1.namespaces(namespace).services(name).delete()
await client.apis.apps.v1beta1.namespaces(namespace).deployments(name).delete()
}
const getReplicaSet = async (namespace) => {
const rsData = await client.apis.apps.v1beta2.namespaces(namespace).replicasets.get()
return rsData.body.items
}
const replicaSetDelete = async (namespace, rsName) => {
await client.apis.apps.v1.namespaces(namespace).replicasets(rsName).delete()
await client.api.v1.namespaces(namespace).services(name).delete()
}
module.exports = {
......@@ -237,4 +245,6 @@ module.exports = {
serviceRestart,
serviceDelete,
imageUpdate,
getReplicaSet,
replicaSetDelete,
}
......@@ -8,6 +8,7 @@ metadata:
qcloud-app: {{serviceName}}
spec:
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
qcloud-app: {{serviceName}}
......@@ -20,7 +21,6 @@ spec:
type: {{label}}
spec:
terminationGracePeriodSeconds: 0
revisionHistoryLimit: 1
containers:
- name: {{serviceName}}
image: ccr.ccs.tencentyun.com/{{image}}
......
......@@ -7,10 +7,11 @@ metadata:
type: {{label}}
qcloud-app: {{serviceName}}
spec:
replicas: 1
selector:
matchLabels:
qcloud-app: {{serviceName}}
# replicas: 1
revisionHistoryLimit: 1
# selector:
# matchLabels:
# qcloud-app: {{serviceName}}
strategy:
type: Recreate
template:
......@@ -20,7 +21,6 @@ spec:
type: {{label}}
spec:
terminationGracePeriodSeconds: 0
revisionHistoryLimit: 1
containers:
- name: {{serviceName}}
image: ccr.ccs.tencentyun.com/{{image}}
......
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