Commit d202b0b5 authored by 智勇's avatar 智勇

闲置服务检查

parent c20894cb
......@@ -66,7 +66,7 @@ const syncDB = async (cluster) => {
module.exports = () => {
// schedule.scheduleJob('*/2 * * * *', async () => {
schedule.scheduleJob('0 23 * * *', async () => {
schedule.scheduleJob('50 7 * * *', async () => {
try {
await syncDB('qa')
} catch (e) {
......
const schedule = require('node-schedule')
const logger = require('koa-log4').getLogger('deleteTestSvc')
const {
getServicesFormat, getAllNamespace,
} = require('../kubeService/service')
const getClient = require('../resource/getClient')
const dingTalk = require('../utils/dingTalk')
const APP_CONFIG = require('../config')
const deploy = async (cluster) => {
logger.info('deleteTestSvc job start')
const client = await getClient(cluster)
const ns = await getAllNamespace(client.clientInfo)
const summary = {}
for (const namespace of ns.namespaces) {
if (namespace.description === 'test') {
logger.info('开始检查ns:', namespace.name)
summary[namespace.name] = []
const svcs = await getServicesFormat(client.clientInfo, namespace.name)
for (const svc of svcs) {
if (svc.labels.type !== 'base' && !~svc.image.indexOf('latest') && !~svc.image.search(':master-') && ~svc.createdAt.search('month')) {
summary[namespace.name].push(svc.image.split('/')[2])
}
}
logger.info('ns:', namespace.name, '检查完毕')
}
}
let text = '早。以下测试分支已经一个月没有更新啦,请确认该服务是否还在使用,如无回复将会被删除\n\n'
for (const i in summary) {
if (Object.prototype.hasOwnProperty.call(summary, i)) {
if (summary[i].length) {
text = `${text}${i} : \n\n${summary[i].join('\n\n')}\n\n`
}
}
}
dingTalk('daily 闲置服务检查', text, APP_CONFIG.deleteTestSvcRobot)
logger.info('deleteTestSvc job end')
}
module.exports = () => {
// schedule.scheduleJob('*/2 * * * *', async () => {
schedule.scheduleJob('59 9 * * 1-5', async () => {
try {
await deploy('qa')
} catch (e) {
logger.info('deleteTestSvc', e)
}
});
}
......@@ -15,6 +15,7 @@ const tag = require('./tag')
const cluster = require('./cluster')
const ingressRoute = require('./ingress')
const deploy = require('./restartLatest')
const deleteTestSvc = require('./deleteTestSvc')
const dailySyncDB = require('./dailySyncDB')
const client = require('../middleware/client')
......@@ -59,6 +60,7 @@ exports.start = function (port) {
// 加载所有路由
loadRoutes(router)
deploy()
deleteTestSvc()
dailySyncDB()
app.use(log4js.koaLogger(log4js.getLogger('http'), { level: 'auto', format: logFormat }))
app.use(router.routes())
......
......@@ -147,6 +147,9 @@ router.post('/modifyDeploy', async (ctx) => {
if (!data.label) {
data.label = data.type
}
if (data.type === 'base') {
data.type = data.serviceName
}
const resources = await makeResouce(data.serviceName, data.label)
data.resources = resources
await deployUpdate(ctx.cluterParams, ctx.client, data)
......
......@@ -15,4 +15,5 @@ module.exports = {
],
qaapiHost: 'http://qaapi.liangkebang.com',
latestDingRobot: 'https://oapi.dingtalk.com/robot/send?access_token=99e801a2cf26680e6ce09cb12f830c21a03ae3df07d18f6a38e1db54c0e95f2c',
deleteTestSvcRobot: 'https://oapi.dingtalk.com/robot/send?access_token=e6982a86338979a03d6a1e105469e3010ab1c0b18d80a49a84705c767dbf0e3c',
}
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