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