Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tke-eos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
tke-eos
Commits
594b562e
Commit
594b562e
authored
Mar 28, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init ns
parent
d1d80b30
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
1 deletion
+127
-1
index.js
app/index.js
+6
-0
namespace.js
app/namespace.js
+84
-0
nodemon.json
nodemon.json
+1
-1
index.js
serviceTemplate/index.js
+2
-0
redis.template.txt
serviceTemplate/redis.template.txt
+34
-0
No files found.
app/index.js
View file @
594b562e
...
...
@@ -22,6 +22,12 @@ const logFormat = ':req[x-real-ip] :req[x-forwarded-for] - -'
const
cluster
=
require
(
'
../services/tke.clusterService
'
).
create
()
const
container
=
require
(
'
../services/tke.containerService
'
).
create
()
const
logFormat
=
'
:req[x-real-ip] :req[x-forwarded-for] - -
'
+
'
":method :url HTTP/:http-version"
'
+
'
:status :content-length ":referrer"
'
+
'
":user-agent" :req[x-auth-token] :response-time
'
+
'
ms
'
;
const
logger
=
log4js
.
getLogger
()
log4js
.
configure
(
logConf
.
devlog
)
function
loadRoutes
(
router
)
{
...
...
app/namespace.js
View file @
594b562e
const
Router
=
require
(
'
koa-router
'
)
const
yaml
=
require
(
'
js-yaml
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
(
'
router:namespace
'
);
const
templates
=
require
(
'
../serviceTemplate
'
)
let
newNsKey
=
''
const
router
=
new
Router
();
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
(
ctx
)
=>
{
const
data
=
await
ctx
.
cluster
.
namespace_get
()
ctx
.
body
=
ctx
.
ok
(
data
)
...
...
@@ -14,7 +19,86 @@ router.post('/create', async (ctx) => {
ctx
.
body
=
ctx
.
ok
()
})
const
IMAGES
=
{
zookeeper
:
'
zookeeper:3.4.10
'
,
rabbitmq
:
'
rabbitmq:3.6-management
'
,
mysql
:
'
mysql:5.7
'
,
redis
:
'
ccr.ccs.tencentyun.com/qa-db/redis:v4
'
,
}
router
.
post
(
'
/init
'
,
async
(
ctx
)
=>
{
const
body
=
ctx
.
request
.
body
if
(
body
.
code
!==
newNsKey
)
{
throw
new
Error
(
'
创建确认码不正确
'
)
}
await
ctx
.
cluster
.
namespace_create
(
body
.
namespace
)
await
ctx
.
cluster
.
ingress_create
(
body
.
namespace
)
async
function
serviceCreate
(
element
,
index
)
{
if
(
index
!==
'
common
'
)
{
const
data
=
{
namespace
:
body
.
namespace
,
image
:
`ccr.ccs.tencentyun.com/qa-
${
index
}
/
${
element
}
:tke-latest`
,
type
:
index
,
serviceName
:
element
,
system_name
:
element
,
}
const
template
=
templates
[
index
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
}
return
data
[
arguments
[
1
]]
})
const
params
=
yaml
.
load
(
template
)
await
ctx
.
cluster
.
service_create
(
params
,
index
)
}
if
(
index
===
'
common
'
)
{
const
data
=
{
namespace
:
body
.
namespace
,
image
:
IMAGES
[
element
],
}
const
template
=
templates
[
element
].
replace
(
/{{
([
A-Za-z0-9_
]
+
)
}}/g
,
function
()
{
if
(
data
[
arguments
[
1
]]
===
undefined
)
{
throw
new
Error
(
'
缺少模板所需变量
'
)
}
return
data
[
arguments
[
1
]]
})
const
params
=
yaml
.
load
(
template
)
await
ctx
.
cluster
.
service_create
(
params
)
}
}
for
(
const
index
in
body
.
systems
)
{
if
({}.
hasOwnProperty
.
call
(
body
.
systems
,
index
))
{
for
(
const
item
in
body
.
systems
[
index
])
{
if
({}.
hasOwnProperty
.
call
(
body
.
systems
[
index
],
item
))
{
serviceCreate
(
body
.
systems
[
index
][
item
],
index
)
}
}
}
}
ctx
.
body
=
ctx
.
ok
(
'
正在创建
'
)
})
router
.
post
(
'
/delete
'
,
async
(
ctx
)
=>
{
await
ctx
.
cluster
.
namespace_delete
(
ctx
.
request
.
body
.
name
)
ctx
.
body
=
ctx
.
ok
()
})
function
generateUUID
()
{
let
d
=
new
Date
().
getTime
();
const
uuid
=
'
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
'
.
replace
(
/
[
xy
]
/g
,
(
c
)
=>
{
const
r
=
(
d
+
Math
.
random
()
*
16
)
%
16
|
0
;
d
=
Math
.
floor
(
d
/
16
);
return
(
c
===
'
x
'
?
r
:
(
r
&
0x3
|
0x8
)).
toString
(
16
);
});
return
uuid
;
}
router
.
get
(
'
/get_code
'
,
async
(
ctx
)
=>
{
newNsKey
=
newNsKey
===
''
?
generateUUID
()
:
newNsKey
ctx
.
body
=
ctx
.
ok
(
newNsKey
)
})
nodemon.json
View file @
594b562e
{
"delay"
:
"
2
500"
,
"delay"
:
"500"
,
"ignore"
:
[
"*.test.js"
,
"fixtures/*"
],
"ext"
:
"js json txt"
}
\ No newline at end of file
serviceTemplate/index.js
View file @
594b562e
...
...
@@ -6,6 +6,7 @@ const node = fs.readFileSync('serviceTemplate/node.template.txt', 'utf8')
const
rabbitmq
=
fs
.
readFileSync
(
'
serviceTemplate/rabbitmq.template.txt
'
,
'
utf8
'
)
const
zookeeper
=
fs
.
readFileSync
(
'
serviceTemplate/zookeeper.template.txt
'
,
'
utf8
'
)
const
mysql
=
fs
.
readFileSync
(
'
serviceTemplate/mysql.template.txt
'
,
'
utf8
'
)
const
redis
=
fs
.
readFileSync
(
'
serviceTemplate/redis.template.txt
'
,
'
utf8
'
)
module
.
exports
=
{
ui
,
...
...
@@ -14,4 +15,5 @@ module.exports = {
rabbitmq
,
zookeeper
,
mysql
,
redis
,
}
serviceTemplate/redis.template.txt
0 → 100644
View file @
594b562e
serviceName: redis
namespace: {{namespace}}
replicas: 1
accessType: ClusterIP
portMappings.0.protocol: TCP
portMappings.0.lbPort: 6379
portMappings.0.containerPort: 6379
portMappings.1.protocol: TCP
portMappings.1.lbPort: 6380
portMappings.1.containerPort: 6380
portMappings.2.protocol: TCP
portMappings.2.lbPort: 6381
portMappings.2.containerPort: 6381
portMappings.3.protocol: TCP
portMappings.3.lbPort: 6382
portMappings.3.containerPort: 6382
portMappings.4.protocol: TCP
portMappings.4.lbPort: 6383
portMappings.4.containerPort: 6383
containers.0.containerName: redis
containers.0.image: {{image}}
containers.0.volumeMounts.0.volumeName: redis-vol
containers.0.volumeMounts.0.mountPath: /var/lib/redis
containers.0.volumeMounts.0.mode: rw
volumes.0.name: redis-vol
volumes.0.volumeType: hostPath
volumes.0.hostPath: /var/lib/data/redis/{{namespace}}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment