Commit 972107c1 authored by 智勇's avatar 智勇

增加是否已有PersistentVolumeClaim 判断

parent 917f25a5
......@@ -51,7 +51,7 @@ const createService = async (ctx) => {
} = ctx.request.body
logger.info('创建服务', ctx.request.body)
if (serviceName === 'mysql') {
serviceCreate(namespace, serviceName, image)
await serviceCreate(namespace, serviceName, image, label)
ctx.body = ctx.ok('创建成功')
return
}
......
......@@ -30,8 +30,9 @@ const serviceCreate = async (namespace, serviceName, image) => {
const yamlArray = yamlManifest.split('---')
yamlArray.forEach(async (item) => {
for (const item of yamlArray) {
const jsonObj = yaml.load(item);
let pvc
switch (jsonObj.kind) {
case 'Service':
......@@ -43,13 +44,17 @@ const serviceCreate = async (namespace, serviceName, image) => {
break;
case 'PersistentVolumeClaim':
await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: jsonObj })
pvc = await client.api.v1.namespaces(namespace).persistentvolumeclaims.get()
pvc = pvc.body.items.filter(item => item.metadata.name === serviceName)
if (!pvc.length) {
await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: jsonObj })
}
break;
default:
break;
}
})
}
}
module.exports = {
......
......@@ -17,6 +17,7 @@ apiVersion: apps/v1beta1
kind: Deployment
metadata:
labels:
type: base
qcloud-app: {{app}}
name: {{app}}
namespace: {{namespace}}
......
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