Commit 3a197e04 authored by kewei.jia's avatar kewei.jia Committed by 智勇

添加QKE 功能支持

parent 4f2831c2
...@@ -20,7 +20,7 @@ const { ...@@ -20,7 +20,7 @@ const {
replicaSetDelete, replicaSetDelete,
pvcDelete, pvcDelete,
} = require('../kubeService/service') } = require('../kubeService/service')
const newClient = require('./../resource/getClient') const getClient = require('./../resource/getClient')
const router = new Router() const router = new Router()
module.exports = router module.exports = router
...@@ -174,12 +174,26 @@ router.get('/listEnvVars', async (ctx) => { ...@@ -174,12 +174,26 @@ router.get('/listEnvVars', async (ctx) => {
}) })
// for container // for container
const clientNew = {}
router.get('/listEnvVarsNew', async (ctx) => { router.get('/listEnvVarsNew', async (ctx) => {
const envVars = {} const envVars = {}
const { namespace, client } = newClient(ctx) let cluster;
let namespace;
const parmars = ctx.request.query.namespace || ''
if (parmars.search('@') === -1) {
cluster = 'qa'
namespace = ctx.request.query.namespace
} else {
namespace = parmars.split('@')[0];
cluster = parmars.split('@')[1]
}
if (!clientNew[cluster]) {
console.log('为空')
clientNew[cluster] = getClient(cluster)
}
const res = await Promise.all([ const res = await Promise.all([
getPods(client, namespace), getPods(clientNew[cluster], namespace),
getServices(client, namespace), getServices(clientNew[cluster], namespace),
]) ])
res[0].body.items.forEach(async (item) => { res[0].body.items.forEach(async (item) => {
......
...@@ -2,17 +2,7 @@ const path = require('path') ...@@ -2,17 +2,7 @@ const path = require('path')
const Client = require('kubernetes-client').Client const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config const config = require('kubernetes-client').config
const newClient = function client(ctx) { module.exports = function getClient(cluster) {
const parmars = ctx.request.query.namespace || ''
if (parmars.search('@') === -1) {
ctx.body = {
code: '0001',
msg: '参数传入不合法',
}
return false
}
const namespace = parmars.split('@')[0];
const cluster = parmars.split('@')[1]
let yaml = '' let yaml = ''
switch (cluster) { switch (cluster) {
case 'qa': case 'qa':
...@@ -25,17 +15,12 @@ const newClient = function client(ctx) { ...@@ -25,17 +15,12 @@ const newClient = function client(ctx) {
yaml = './../kubeService/kubeConfig-qke.yaml' yaml = './../kubeService/kubeConfig-qke.yaml'
break break
default: default:
ctx.body = { throw Error('未获取到Client')
code: '0001',
msg: '请选择集群的名字',
}
} }
const client = new Client({ return new Client({
config: config.fromKubeconfig( config: config.fromKubeconfig(
path.resolve(__dirname, yaml), path.resolve(__dirname, yaml),
), ),
version: '1.10', version: '1.10',
}) })
return { namespace, client }
} }
module.exports = newClient
...@@ -21,12 +21,12 @@ metadata: ...@@ -21,12 +21,12 @@ metadata:
name: {{serviceName}}-{{namespace}} name: {{serviceName}}-{{namespace}}
namespace: {{namespace}} namespace: {{namespace}}
spec: spec:
storageClassName: cbs storageClassName: cbs-3
accessModes: accessModes:
- ReadWriteOnce - ReadWriteOnce
resources: resources:
requests: requests:
storage: 1Gi storage: 20Gi
--- ---
...@@ -82,6 +82,8 @@ spec: ...@@ -82,6 +82,8 @@ spec:
volumeMounts: volumeMounts:
- mountPath: "/var/lib/mysql" - mountPath: "/var/lib/mysql"
name: {{serviceName}} name: {{serviceName}}
# nodeSelector:
# zone: "3"
volumes: volumes:
- name: {{serviceName}} - name: {{serviceName}}
persistentVolumeClaim: persistentVolumeClaim:
......
...@@ -35,6 +35,8 @@ spec: ...@@ -35,6 +35,8 @@ spec:
qcloud-app: {{serviceName}} qcloud-app: {{serviceName}}
type: base type: base
spec: spec:
nodeSelector:
zone: "3"
containers: containers:
- image: ccr.ccs.tencentyun.com/{{image}} - image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always imagePullPolicy: Always
......
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