Commit 9dbf3e85 authored by 智勇's avatar 智勇

创建ns支持多集群

parent 19ac4619
...@@ -25,6 +25,31 @@ const getAllNamespace = async (client) => { ...@@ -25,6 +25,31 @@ const getAllNamespace = async (client) => {
}) })
return data return data
} }
const makeManifest = (data) => {
if (!data.debug) {
data.debug = '"0"'
}
if (!data.mock) {
data.mock = '"0"'
}
if (data.label === 'java') {
data.serviceType = data.debug === '"0"' ? 'ClusterIP' : 'NodePort'
}
const yamlManifest = yamls[data.type].replace(/{{([A-Za-z0-9_\.]+)}}/g, function () {
if (_.get(data, arguments[1], null) === null) {
throw new Error(`缺少模板所需变量: ${arguments[1]}`)
}
return _.get(data, arguments[1])
})
const manifestArray = yamlManifest.split('---')
return manifestArray
}
const createNamespace = async (client, name, description) => { const createNamespace = async (client, name, description) => {
const parmas = { const parmas = {
apiVersion: 'v1', apiVersion: 'v1',
...@@ -46,33 +71,20 @@ const createNamespace = async (client, name, description) => { ...@@ -46,33 +71,20 @@ const createNamespace = async (client, name, description) => {
], ],
}, },
} }
const res = await client.api.v1.namespaces.post({ body: parmas }) logger.info('创建namespace', name, JSON.stringify(parmas))
return res await client.api.v1.namespaces.post({ body: parmas })
}
const makeManifest = (data) => {
if (!data.debug) {
data.debug = '"0"'
}
if (!data.mock) { const manifestArray = makeManifest({ namespace: name, type: 'tencenthubkey' })
data.mock = '"1"' for (const item of manifestArray) {
} const manifest = yaml.load(item);
logger.info('创建secret', JSON.stringify(manifest))
if (data.label === 'java') { await client.api.v1.namespaces(name)
data.serviceType = data.debug === '"0"' ? 'ClusterIP' : 'NodePort' .secrets
.post({ body: manifest })
} }
const yamlManifest = yamls[data.type].replace(/{{([A-Za-z0-9_\.]+)}}/g, function () {
if (_.get(data, arguments[1], null) === null) {
throw new Error(`缺少模板所需变量: ${arguments[1]}`)
}
return _.get(data, arguments[1])
})
const manifestArray = yamlManifest.split('---')
return manifestArray
} }
const serviceCreate = async (cluster, client, data) => { const serviceCreate = async (cluster, client, data) => {
data.cluster = cluster data.cluster = cluster
const { namespace, serviceName } = data const { namespace, serviceName } = data
...@@ -179,38 +191,31 @@ const formatServiceInfo = (obj) => { ...@@ -179,38 +191,31 @@ const formatServiceInfo = (obj) => {
} }
const getPodStatus = (podInfo) => { const getPodStatus = (podInfo) => {
if (podInfo.status.phase === 'Pending') {
return 'Pending'
}
if (podInfo.status.conditions) {
for (const item of podInfo.status.conditions) {
if (item.type === 'Initialized' && item.status === 'False') {
return 'Initializing'
}
if (item.type === 'PodScheduled' && item.status === 'False') {
return 'PodScheduling'
}
if (item.type === 'ContainersReady' && item.status === 'False') {
return 'ContainerCreating'
}
if (item.type === 'Ready' && item.status === 'False') {
return 'Waiting'
}
if (item.type === 'Ready' && item.status === 'True') {
return 'Normal'
}
}
}
if (podInfo.metadata.deletionTimestamp) { if (podInfo.metadata.deletionTimestamp) {
return 'Terminating' return 'Terminating'
} }
let status
if (!podInfo.status.containerStatuses) {
status = 'Pending'
} else {
if (podInfo.status.containerStatuses[0].state.waiting) {
status = 'ContainerCreating'
}
if (podInfo.status.containerStatuses[0].state.running && !podInfo.status.containerStatuses[0].ready) {
status = 'Waiting'
}
if (podInfo.status.containerStatuses[0].state.running && podInfo.status.containerStatuses[0].ready) {
status = 'Normal'
}
}
return status
} }
const formatPodInfo = (podInfo) => { const formatPodInfo = (podInfo) => {
const podStatus = getPodStatus(podInfo) const podStatus = getPodStatus(podInfo)
// for debug // for debug
// if (podInfo.metadata.name.indexOf('xyqb-user2') !== -1) { // if (podInfo.metadata.name.indexOf('zookeeper') !== -1) {
// console.log(1, podStatus, JSON.stringify(podInfo.status.conditions)) // console.log(1, podStatus, JSON.stringify(podInfo))
// } // }
const imageID = _.get(podInfo.status.containerStatuses, '[0].imageID', '') const imageID = _.get(podInfo.status.containerStatuses, '[0].imageID', '')
const image = _.get(podInfo.spec.containers, '[0].image', '') const image = _.get(podInfo.spec.containers, '[0].image', '')
......
...@@ -10,6 +10,7 @@ const ui = fs.readFileSync('yamls/ui.node.yaml', 'utf8') ...@@ -10,6 +10,7 @@ const ui = fs.readFileSync('yamls/ui.node.yaml', 'utf8')
const node = fs.readFileSync('yamls/ui.node.yaml', 'utf8') const node = fs.readFileSync('yamls/ui.node.yaml', 'utf8')
const java = fs.readFileSync('yamls/java.yaml', 'utf8') const java = fs.readFileSync('yamls/java.yaml', 'utf8')
const python = fs.readFileSync('yamls/python.yaml', 'utf8') const python = fs.readFileSync('yamls/python.yaml', 'utf8')
const tencenthubkey = fs.readFileSync('yamls/tencenthubkey.yaml', 'utf8')
module.exports = { module.exports = {
mysql, mysql,
...@@ -22,4 +23,5 @@ module.exports = { ...@@ -22,4 +23,5 @@ module.exports = {
node, node,
java, java,
python, python,
tencenthubkey,
} }
apiVersion: v1
data:
.dockercfg: eyJodWIudGVuY2VudHl1bi5jb20iOnsidXNlcm5hbWUiOiIxMDAwMDg2MzIyNjkiLCJwYXNzd29yZCI6ImV5SmhiR2NpT2lKSVV6STFOaUlzSW5SNWNDSTZJa3BYVkNKOS5leUpsZUhBaU9qRTROelk1T0RZNE5UVXNJbXAwYVNJNkltVXdORGs1TVRKaExXVmpPVEV0TkdVeE5TMDVPRFF6TFdOa05URXlZV05sWXpGak1TSXNJbWxoZENJNk1UVTJNVFl5TmpnMU5Td2libUptSWpveE5UWXhOakkyT0RVMUxDSnpkV0lpT2lJeE1EQXdNRGcyTXpJeU5qa2lmUS5FY0NuclRSRG12MjFicHczdENld1pBdHhpMko0WEdEVHQwYUM2cDNKSGhNIiwiZW1haWwiOiIxMDAwMDg2MzIyNjlAcXEuY29tIiwiYXV0aCI6Ik1UQXdNREE0TmpNeU1qWTVPbVY1U21oaVIyTnBUMmxLU1ZWNlNURk9hVWx6U1c1U05XTkRTVFpKYTNCWVZrTktPUzVsZVVwc1pVaEJhVTlxUlRST2VsazFUMFJaTkU1VVZYTkpiWEF3WVZOSk5rbHRWWGRPUkdzMVRWUkthRXhYVm1wUFZFVjBUa2RWZUU1VE1EVlBSRkY2VEZkT2EwNVVSWGxaVjA1c1dYcEdhazFUU1hOSmJXeG9aRU5KTmsxVVZUSk5WRmw1VG1wbk1VNVRkMmxpYlVwdFNXcHZlRTVVV1hoT2Fra3lUMFJWTVV4RFNucGtWMGxwVDJsSmVFMUVRWGROUkdjeVRYcEplVTVxYTJsbVVTNUZZME51Y2xSU1JHMTJNakZpY0hjemRFTmxkMXBCZEhocE1rbzBXRWRFVkhRd1lVTTJjRE5LU0doTiJ9fQ==
kind: Secret
metadata:
labels:
qcloud-app: tencenthubkey
name: tencenthubkey
namespace: {{namespace}}
type: kubernetes.io/dockercfg
---
apiVersion: v1
data:
.dockercfg: eyJjY3IuY2NzLnRlbmNlbnR5dW4uY29tIjp7InVzZXJuYW1lIjoiMTAwMDA4NjMyMjY5IiwicGFzc3dvcmQiOiJ7QXBwbGljYXRpb25Ub2tlbjo0MTM1NWY2OWQyY2U3ZWUyYmE2YjQxZmMxNzJlNzM0MH0iLCJlbWFpbCI6IjEwMDAwODYzMjI2OUBxcS5jb20iLCJhdXRoIjoiTVRBd01EQTROak15TWpZNU9udEJjSEJzYVdOaGRHbHZibFJ2YTJWdU9qUXhNelUxWmpZNVpESmpaVGRsWlRKaVlUWmlOREZtWXpFM01tVTNNelF3ZlE9PSJ9fQ==
kind: Secret
metadata:
labels:
qcloud-app: qcloudregistrykey
name: qcloudregistrykey
namespace: {{namespace}}
type: kubernetes.io/dockercfg
\ No newline at end of file
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