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
7720239c
Commit
7720239c
authored
Jul 04, 2019
by
智勇
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jiakewei' into 'master'
恢复删除的代码 See merge request !34
parents
1dc91341
3fd8413a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
15 deletions
+30
-15
service.js
kubeService/service.js
+30
-15
No files found.
kubeService/service.js
View file @
7720239c
...
...
@@ -6,7 +6,7 @@ const moment = require('moment')
const
yaml
=
require
(
'
js-yaml
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
(
'
kubeService
'
)
const
yamls
=
require
(
'
../yamls
'
)
const
dict
=
require
(
'
./dictService
'
)
const
APP_CONFIG
=
require
(
'
../config
'
)
const
client
=
new
Client
({
config
:
config
.
fromKubeconfig
(
...
...
@@ -52,8 +52,13 @@ const serviceCreate = async (data) => {
break
;
case
'
Deployment
'
:
logger
.
info
(
'
创建deploy
'
,
JSON
.
stringify
(
jsonObj
))
await
client
.
apis
.
apps
.
v1beta1
.
namespaces
(
namespace
).
deployments
.
post
({
body
:
jsonObj
})
let
obj
=
jsonObj
if
(
APP_CONFIG
.
noHealthCheckApp
.
includes
(
serviceName
))
{
obj
=
_
.
omit
(
jsonObj
,
[
'
spec.template.spec.containers[0].readinessProbe
'
])
}
logger
.
info
(
'
创建deploy
'
,
serviceName
,
JSON
.
stringify
(
obj
))
await
client
.
apis
.
apps
.
v1beta1
.
namespaces
(
namespace
).
deployments
.
post
({
body
:
obj
})
break
;
case
'
PersistentVolumeClaim
'
:
...
...
@@ -96,9 +101,11 @@ const serviceUpdate = async (data) => {
const
formatServiceInfo
=
(
obj
)
=>
{
const
portObj
=
{}
obj
.
spec
.
ports
.
forEach
((
i
)
=>
{
portObj
[
`
${
i
.
name
}
_port`
]
=
i
.
nodePort
})
if
(
obj
.
spec
.
type
===
'
NodePort
'
)
{
obj
.
spec
.
ports
.
forEach
((
i
)
=>
{
portObj
[
`port_
${
i
.
port
}
`
]
=
i
.
nodePort
})
}
return
_
.
assign
(
portObj
,
{
clusterIp
:
obj
.
spec
.
clusterIP
,
...
...
@@ -132,8 +139,8 @@ const formatPodInfo = (podInfo) => {
// }
const
podStatus
=
getPodStatus
(
podInfo
)
// const containerImage = _.get(podInfo.status.containerStatuses, '[0].image
', '')
const
containerI
mage
=
_
.
get
(
podInfo
.
spec
.
containers
,
'
[0].image
'
,
''
)
const
imageID
=
_
.
get
(
podInfo
.
status
.
containerStatuses
,
'
[0].imageID
'
,
''
)
const
i
mage
=
_
.
get
(
podInfo
.
spec
.
containers
,
'
[0].image
'
,
''
)
const
ret
=
{
serviceName
:
(
podInfo
.
metadata
.
labels
&&
podInfo
.
metadata
.
labels
[
'
qcloud-app
'
])
||
podInfo
.
metadata
.
name
,
...
...
@@ -143,14 +150,13 @@ const formatPodInfo = (podInfo) => {
lanIp
:
podInfo
.
status
.
hostIP
,
startTime
:
podInfo
.
status
.
startTime
,
createdAt
:
moment
(
new
Date
(
podInfo
.
status
.
startTime
)).
startOf
(
'
minute
'
).
fromNow
(),
image
:
containerImage
,
image
,
imageID
,
labels
:
podInfo
.
metadata
.
labels
,
}
if
(
containerImage
!==
''
)
{
ret
.
branch
=
containerImage
.
split
(
'
:
'
)[
1
]
ret
.
branch_no_time
=
containerImage
.
split
(
'
:
'
)[
1
].
split
(
'
-
'
)[
0
]
ret
.
branch_time
=
containerImage
.
split
(
'
:
'
)[
1
].
split
(
'
-
'
)[
1
]
if
(
image
!==
''
)
{
ret
.
branch
=
image
.
split
(
'
:
'
)[
1
]
}
return
ret
...
...
@@ -221,6 +227,7 @@ const getServiceDetail = async (namespace, name, type) => {
}
const
serviceRestart
=
async
(
namespace
,
name
)
=>
{
logger
.
info
(
'
重置服务
'
,
namespace
,
name
)
await
client
.
api
.
v1
.
namespaces
(
namespace
).
pods
(
name
).
delete
()
}
...
...
@@ -231,7 +238,7 @@ const serviceDelete = async (namespace, name) => {
logger
.
info
(
'
删除svc
'
,
namespace
,
name
)
await
client
.
api
.
v1
.
namespaces
(
namespace
).
services
(
name
).
delete
()
}
catch
(
error
)
{
logger
.
error
(
error
)
logger
.
warn
(
error
.
toString
()
)
}
}
...
...
@@ -245,7 +252,14 @@ const replicaSetDelete = async (namespace, name) => {
await
client
.
apis
.
apps
.
v1
.
namespaces
(
namespace
).
replicasets
.
delete
({
qs
:
{
labelSelector
:
`qcloud-app=
${
name
}
`
}
})
// await client.apis.apps.v1.namespaces(namespace).replicasets(rsName).delete()
}
const
pvcDelete
=
async
(
namespace
,
name
)
=>
{
try
{
logger
.
info
(
'
删除pvc
'
,
namespace
,
name
)
await
client
.
api
.
v1
.
namespaces
(
namespace
).
persistentvolumeclaim
(
`
${
name
}
-
${
namespace
}
`
).
delete
()
}
catch
(
error
)
{
logger
.
warn
(
error
.
toString
())
}
}
const
getServices
=
async
(
namespace
)
=>
{
const
data
=
await
client
.
api
.
v1
.
namespaces
(
namespace
).
services
.
get
()
return
data
...
...
@@ -264,4 +278,5 @@ module.exports = {
imageUpdate
,
getReplicaSet
,
replicaSetDelete
,
pvcDelete
,
}
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