Commit 3fd8413a authored by kewei.jia's avatar kewei.jia

恢复删除的代码

parent 1dc91341
......@@ -6,7 +6,7 @@ const moment = require('moment')
const yaml = require('js-yaml')
const logger = require('koa-log4').getLogger('kubeService')
const yamls = require('../yamls')
const dict = require('./dictService')
const APP_CONFIG = require('../config')
const client = new Client({
config: config.fromKubeconfig(
......@@ -52,8 +52,13 @@ const serviceCreate = async (data) => {
break;
case 'Deployment':
logger.info('创建deploy', JSON.stringify(jsonObj))
await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: jsonObj })
let obj = jsonObj
if (APP_CONFIG.noHealthCheckApp.includes(serviceName)) {
obj = _.omit(jsonObj, ['spec.template.spec.containers[0].readinessProbe'])
}
logger.info('创建deploy', serviceName, JSON.stringify(obj))
await client.apis.apps.v1beta1.namespaces(namespace).deployments.post({ body: obj })
break;
case 'PersistentVolumeClaim':
......@@ -96,9 +101,11 @@ const serviceUpdate = async (data) => {
const formatServiceInfo = (obj) => {
const portObj = {}
obj.spec.ports.forEach((i) => {
portObj[`${i.name}_port`] = i.nodePort
})
if (obj.spec.type === 'NodePort') {
obj.spec.ports.forEach((i) => {
portObj[`port_${i.port}`] = i.nodePort
})
}
return _.assign(portObj, {
clusterIp: obj.spec.clusterIP,
......@@ -132,8 +139,8 @@ const formatPodInfo = (podInfo) => {
// }
const podStatus = getPodStatus(podInfo)
// const containerImage = _.get(podInfo.status.containerStatuses, '[0].image', '')
const containerImage = _.get(podInfo.spec.containers, '[0].image', '')
const imageID = _.get(podInfo.status.containerStatuses, '[0].imageID', '')
const image = _.get(podInfo.spec.containers, '[0].image', '')
const ret = {
serviceName: (podInfo.metadata.labels && podInfo.metadata.labels['qcloud-app']) || podInfo.metadata.name,
......@@ -143,14 +150,13 @@ const formatPodInfo = (podInfo) => {
lanIp: podInfo.status.hostIP,
startTime: podInfo.status.startTime,
createdAt: moment(new Date(podInfo.status.startTime)).startOf('minute').fromNow(),
image: containerImage,
image,
imageID,
labels: podInfo.metadata.labels,
}
if (containerImage !== '') {
ret.branch = containerImage.split(':')[1]
ret.branch_no_time = containerImage.split(':')[1].split('-')[0]
ret.branch_time = containerImage.split(':')[1].split('-')[1]
if (image !== '') {
ret.branch = image.split(':')[1]
}
return ret
......@@ -221,6 +227,7 @@ const getServiceDetail = async (namespace, name, type) => {
}
const serviceRestart = async (namespace, name) => {
logger.info('重置服务', namespace, name)
await client.api.v1.namespaces(namespace).pods(name).delete()
}
......@@ -231,7 +238,7 @@ const serviceDelete = async (namespace, name) => {
logger.info('删除svc', namespace, name)
await client.api.v1.namespaces(namespace).services(name).delete()
} catch (error) {
logger.error(error)
logger.warn(error.toString())
}
}
......@@ -245,7 +252,14 @@ const replicaSetDelete = async (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 pvcDelete = async (namespace, name) => {
try {
logger.info('删除pvc', namespace, name)
await client.api.v1.namespaces(namespace).persistentvolumeclaim(`${name}-${namespace}`).delete()
} catch (error) {
logger.warn(error.toString())
}
}
const getServices = async (namespace) => {
const data = await client.api.v1.namespaces(namespace).services.get()
return data
......@@ -264,4 +278,5 @@ module.exports = {
imageUpdate,
getReplicaSet,
replicaSetDelete,
pvcDelete,
}
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