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
4cee0479
Commit
4cee0479
authored
Jun 28, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
定时更新latest
parent
8e6b7056
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
13 deletions
+88
-13
index.js
app/index.js
+2
-0
restartLatest.js
app/restartLatest.js
+52
-0
service.js
kubeService/service.js
+13
-12
package-lock.json
package-lock.json
+15
-0
package.json
package.json
+2
-1
tke.containerService.js
services/tke.containerService.js
+4
-0
No files found.
app/index.js
View file @
4cee0479
...
...
@@ -14,6 +14,7 @@ const repositoryRouter = require('./repository')
const
tag
=
require
(
'
./tag
'
)
const
commonServiceRoute
=
require
(
'
./commonService
'
)
const
ingressRoute
=
require
(
'
./ingress
'
)
const
deploy
=
require
(
'
./restartLatest
'
)
const
logFormat
=
'
:req[x-real-ip] :req[x-forwarded-for] - -
'
+
'
":method :url HTTP/:http-version"
'
...
...
@@ -53,6 +54,7 @@ exports.start = function () {
schedule
(
'
0 */1 * * * ?
'
)
// 加载所有路由
loadRoutes
(
router
)
deploy
()
app
.
use
(
log4js
.
koaLogger
(
log4js
.
getLogger
(
'
http
'
),
{
level
:
'
auto
'
,
format
:
logFormat
}))
app
.
use
(
router
.
routes
())
app
.
listen
(
4000
)
...
...
app/restartLatest.js
0 → 100644
View file @
4cee0479
const
schedule
=
require
(
'
node-schedule
'
)
const
_
=
require
(
'
lodash
'
)
const
sleep
=
require
(
'
sleep
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
(
'
deployLatest
'
)
const
cluster
=
require
(
'
../services/tke.clusterService
'
).
create
()
const
container
=
require
(
'
../services/tke.containerService
'
).
create
()
const
{
getServiceDetail
,
serviceRestart
,
getServicesFormat
}
=
require
(
'
../kubeService/service
'
)
const
keepNamespace
=
[
'
default
'
,
'
kube-system
'
]
const
repoNS
=
[
'
qa-java
'
,
'
qa-ui
'
,
'
qa-node
'
,
'
qa-python
'
]
const
testNamespace
=
[
'
qa
'
,
'
fe
'
,
'
data
'
,
'
fis
'
,
'
xyqb2
'
]
const
deploy
=
async
()
=>
{
logger
.
info
(
'
deployLatest start
'
)
for
(
const
ns
of
repoNS
)
{
const
repoNSData
=
await
container
.
repository_get
(
ns
)
for
(
const
repo
of
repoNSData
.
repoInfo
)
{
logger
.
info
(
'
开始检查仓库项目:
'
,
repo
.
reponame
)
const
repoName
=
repo
.
reponame
.
split
(
'
/
'
)[
1
]
const
repoType
=
repo
.
reponame
.
split
(
'
/
'
)[
0
].
split
(
'
-
'
)[
1
]
const
latest
=
await
container
.
getTagByName
(
repo
.
reponame
,
'
latest
'
)
const
latestImageID
=
_
.
get
(
latest
.
tagInfo
,
'
[0].tagId
'
,
''
)
let
ns
=
await
cluster
.
namespace_get
()
ns
=
ns
.
namespaces
&&
ns
.
namespaces
.
filter
(
item
=>
testNamespace
.
includes
(
item
.
name
))
for
(
const
namespace
of
ns
)
{
const
svcs
=
await
getServicesFormat
(
namespace
.
name
)
for
(
const
svc
of
svcs
)
{
if
(
svc
.
serviceName
===
repoName
&&
svc
.
image
.
indexOf
(
'
latest
'
)
!==
-
1
)
{
const
data
=
await
getServiceDetail
(
namespace
.
name
,
repoName
,
repoType
)
if
(
latestImageID
!==
data
.
imageID
.
split
(
'
@
'
)[
1
])
{
logger
.
info
(
'
部署项目
'
,
namespace
.
name
,
data
.
podName
)
await
serviceRestart
(
namespace
.
name
,
data
.
podName
)
sleep
.
msleep
(
500
)
}
}
}
}
logger
.
info
(
'
仓库项目检查完毕:
'
,
repo
.
reponame
)
}
}
logger
.
info
(
'
deployLatest end
'
)
}
module
.
exports
=
()
=>
{
schedule
.
scheduleJob
(
'
0 2 * * *
'
,
async
()
=>
{
try
{
await
deploy
()
}
catch
(
e
)
{
logger
.
info
(
'
deployLatest
'
,
e
)
}
});
}
kubeService/service.js
View file @
4cee0479
...
...
@@ -6,7 +6,6 @@ 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
client
=
new
Client
({
config
:
config
.
fromKubeconfig
(
...
...
@@ -88,7 +87,7 @@ const serviceUpdate = async (data) => {
for
(
const
item
of
yamlArray
)
{
const
jsonObj
=
yaml
.
load
(
item
);
if
(
jsonObj
.
kind
===
'
Deployment
'
)
{
logger
.
info
(
'
Deployment
:
'
,
JSON
.
stringify
(
jsonObj
))
logger
.
info
(
'
更新deploy
:
'
,
JSON
.
stringify
(
jsonObj
))
await
client
.
apis
.
apps
.
v1beta1
.
namespaces
(
namespace
).
deployments
(
serviceName
).
put
({
body
:
jsonObj
})
}
}
...
...
@@ -96,9 +95,11 @@ const serviceUpdate = async (data) => {
const
formatServiceInfo
=
(
obj
)
=>
{
const
portObj
=
{}
if
(
obj
.
spec
.
type
===
'
NodePort
'
)
{
obj
.
spec
.
ports
.
forEach
((
i
)
=>
{
portObj
[
`
${
i
.
name
}
_port
`
]
=
i
.
nodePort
portObj
[
`port_
${
i
.
port
}
`
]
=
i
.
nodePort
})
}
return
_
.
assign
(
portObj
,
{
clusterIp
:
obj
.
spec
.
clusterIP
,
...
...
@@ -132,8 +133,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 +144,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 +221,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
()
}
...
...
package-lock.json
View file @
4cee0479
...
...
@@ -4133,6 +4133,21 @@
"integrity"
:
"sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
,
"dev"
:
true
},
"sleep"
:
{
"version"
:
"6.1.0"
,
"resolved"
:
"http://npmprivate.quantgroups.com/sleep/-/sleep-6.1.0.tgz"
,
"integrity"
:
"sha512-Z1x4JjJxsru75Tqn8F4tnOFeEu3HjtITTsumYUiuz54sGKdISgLCek9AUlXlVVrkhltRFhNUsJDJE76SFHTDIQ=="
,
"requires"
:
{
"nan"
:
"^2.13.2"
},
"dependencies"
:
{
"nan"
:
{
"version"
:
"2.14.0"
,
"resolved"
:
"http://npmprivate.quantgroups.com/nan/-/nan-2.14.0.tgz"
,
"integrity"
:
"sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
}
}
},
"slice-ansi"
:
{
"version"
:
"2.1.0"
,
"resolved"
:
"http://npmprivate.quantgroups.com/slice-ansi/-/slice-ansi-2.1.0.tgz"
,
...
...
package.json
View file @
4cee0479
...
...
@@ -16,7 +16,8 @@
"
lru-cache
"
:
"
^5.1.1
"
,
"
moment
"
:
"
^2.24.0
"
,
"
node-schedule
"
:
"
^1.3.2
"
,
"
request
"
:
"
^2.88.0
"
"
request
"
:
"
^2.88.0
"
,
"
sleep
"
:
"
^6.1.0
"
},
"devDependencies"
:
{
"
eslint
"
:
"
^5.15.3
"
,
...
...
services/tke.containerService.js
View file @
4cee0479
...
...
@@ -15,6 +15,10 @@ class Container extends Client {
return
this
.
post
(
'
GetTagList
'
,
{
reponame
})
}
getTagByName
(
reponame
,
tag
)
{
return
this
.
post
(
'
GetTagList
'
,
{
reponame
,
tag
})
}
getNamespaceInfo
(
namespace
)
{
return
this
.
post
(
'
GetNamespaceInfo
'
,
{
namespace
,
limit
:
50
})
}
...
...
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