Commit a836920d authored by 智勇's avatar 智勇

优化删除rs

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