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

增加是否已有PersistentVolumeClaim 判断

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