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
fa769943
Commit
fa769943
authored
Jun 05, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
暂存
parent
b985d1ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
3 deletions
+93
-3
service.js
app/service.js
+10
-2
service.js
kubeService/service.js
+83
-1
No files found.
app/service.js
View file @
fa769943
...
...
@@ -7,12 +7,14 @@ const templates = require('../serviceTemplate')
const
lruCache
=
require
(
'
../services/lruCache.service
'
)
const
{
ingressCreate
,
ingressDelete
}
=
require
(
'
../kubeService/ingress
'
)
const
{
projectConfig
,
defaultConfig
}
=
require
(
'
../serviceTemplate/resourceLimit
'
)
const
{
podGet
,
serviceCreate
}
=
require
(
'
../kubeService/service
'
)
const
{
podGet
,
serviceCreate
,
servicesGet
,
}
=
require
(
'
../kubeService/service
'
)
const
router
=
new
Router
()
module
.
exports
=
router
router
.
get
(
'
/
'
,
async
(
ctx
)
=>
{
const
serviceListTencent
=
async
(
ctx
)
=>
{
// 取节点列表的第一个作为服务的访问ip
const
cacheKey
=
'
k8s.nodes.first
'
const
c
=
lruCache
.
get
(
cacheKey
)
...
...
@@ -43,6 +45,12 @@ router.get('/', async (ctx) => {
}
await
Promise
.
all
(
task
)
ctx
.
body
=
ctx
.
ok
(
data
)
}
router
.
get
(
'
/
'
,
async
(
ctx
)
=>
{
const
data
=
await
servicesGet
(
ctx
.
query
.
namespace
)
console
.
log
(
1
,
data
)
ctx
.
body
=
ctx
.
ok
({
services
:
data
})
})
const
createService
=
async
(
ctx
)
=>
{
...
...
kubeService/service.js
View file @
fa769943
...
...
@@ -13,7 +13,7 @@ const client = new Client({
version
:
'
1.10
'
,
})
const
serviceGet
=
async
(
namespace
,
service
Name
)
=>
client
.
api
.
v1
.
namespaces
(
namespace
).
services
(
serviceNam
e
).
get
()
const
serviceGet
=
async
(
namespace
,
service
)
=>
client
.
api
.
v1
.
namespaces
(
namespace
).
services
(
servic
e
).
get
()
const
podGet
=
async
namespace
=>
client
.
api
.
v1
.
namespaces
(
namespace
).
pods
.
get
()
const
serviceCreate
=
async
(
data
)
=>
{
...
...
@@ -58,8 +58,90 @@ const serviceCreate = async (data) => {
}
}
const
formatServiceInfo
=
(
obj
)
=>
{
const
portObj
=
{}
obj
.
spec
.
ports
.
forEach
((
i
)
=>
{
portObj
[
`
${
i
.
name
}
_port`
]
=
i
.
nodePort
})
return
_
.
assign
(
portObj
,
{
clusterIp
:
obj
.
spec
.
clusterIP
,
ports
:
obj
.
spec
.
ports
,
userLabels
:
obj
.
metadata
.
labels
,
})
}
const
formatPodInfo
=
(
podInfo
)
=>
{
const
podStatus
=
podInfo
.
status
.
phase
===
'
Running
'
&&
podInfo
.
status
.
conditions
.
every
(
i
=>
i
.
status
===
'
True
'
)
?
'
Running
'
:
'
Pending
'
const
containerImage
=
_
.
get
(
podInfo
.
status
.
containerStatuses
,
'
[0].image
'
,
''
)
const
ret
=
{
serviceName
:
(
podInfo
.
metadata
.
labels
&&
podInfo
.
metadata
.
labels
[
'
qcloud-app
'
])
||
podInfo
.
metadata
.
name
,
type
:
podInfo
.
metadata
.
labels
.
tier
,
pod_name
:
podInfo
.
metadata
.
name
,
pod_status
:
podStatus
,
pod_ip
:
podInfo
.
status
.
podIP
,
host_ip
:
podInfo
.
status
.
hostIP
,
start_time
:
podInfo
.
status
.
startTime
,
// live: moment(new Date(podInfo.status.startTime)).startOf('minute').fromNow(),
image
:
containerImage
,
}
if
(
containerImage
!==
''
)
{
ret
.
branch
=
containerImage
.
split
(
'
:
'
)[
1
]
ret
.
branch_no_time
=
containerImage
.
split
(
'
:
'
)[
1
].
split
(
'
-
'
)[
0
]
ret
.
branch_time
=
containerImage
.
split
(
'
:
'
)[
1
].
split
(
'
-
'
)[
1
]
}
return
ret
}
const
formatIngressInfo
=
obj
=>
({
host
:
obj
.
spec
&&
obj
.
spec
.
rules
&&
obj
.
spec
.
rules
[
0
].
host
})
const
servicesGet
=
async
(
namespace
)
=>
{
const
ret
=
[]
const
service
=
{}
const
res
=
await
Promise
.
all
([
client
.
api
.
v1
.
namespaces
(
namespace
).
pods
.
get
(),
// client.api.v1.namespaces(namespace).pods.get({ qs: { labelSelector: 'tier!=job' } }),
client
.
api
.
v1
.
namespaces
(
namespace
).
services
.
get
(),
client
.
apis
.
extensions
.
v1beta1
.
namespaces
(
namespace
).
ingresses
.
get
(),
])
res
[
0
].
body
.
items
.
forEach
(
async
(
item
)
=>
{
const
serviceName
=
(
item
.
metadata
.
labels
&&
item
.
metadata
.
labels
[
'
qcloud-app
'
])
||
item
.
metadata
.
name
service
[
serviceName
]
=
formatPodInfo
(
item
)
})
res
[
1
].
body
.
items
.
forEach
(
async
(
item
)
=>
{
console
.
log
(
2
,
item
)
if
(
service
[
item
.
metadata
.
name
])
{
service
[
item
.
metadata
.
name
]
=
_
.
assign
(
service
[
item
.
metadata
.
name
],
formatServiceInfo
(
item
))
}
})
res
[
2
].
body
.
items
.
forEach
(
async
(
item
)
=>
{
if
(
service
[
item
.
metadata
.
name
])
{
service
[
item
.
metadata
.
name
]
=
_
.
assign
(
service
[
item
.
metadata
.
name
],
formatIngressInfo
(
item
))
}
})
for
(
const
index
in
service
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
service
,
index
))
{
ret
.
push
(
service
[
index
])
}
}
return
ret
}
module
.
exports
=
{
serviceGet
,
servicesGet
,
podGet
,
serviceCreate
,
}
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