Commit 7720239c authored by 智勇's avatar 智勇

Merge branch 'jiakewei' into 'master'

恢复删除的代码



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