Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
883f30a6
Commit
883f30a6
authored
Mar 15, 2020
by
scott
Browse files
Options
Downloads
Patches
Plain Diff
Fix time gap
parent
84da2bd6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
remoting/kubernetes/client.go
+13
-8
13 additions, 8 deletions
remoting/kubernetes/client.go
with
13 additions
and
8 deletions
remoting/kubernetes/client.go
+
13
−
8
View file @
883f30a6
...
@@ -70,6 +70,9 @@ type Client struct {
...
@@ -70,6 +70,9 @@ type Client struct {
ns
string
ns
string
// current resource version
lastResourceVersion
string
// the memory watcherSet
// the memory watcherSet
watcherSet
WatcherSet
watcherSet
WatcherSet
...
@@ -255,6 +258,9 @@ func (c *Client) initWatchSet() error {
...
@@ -255,6 +258,9 @@ func (c *Client) initWatchSet() error {
return
perrors
.
WithMessagef
(
err
,
"list pods in namespace (%s)"
,
c
.
ns
)
return
perrors
.
WithMessagef
(
err
,
"list pods in namespace (%s)"
,
c
.
ns
)
}
}
// set resource version
c
.
lastResourceVersion
=
pods
.
GetResourceVersion
()
for
_
,
pod
:=
range
pods
.
Items
{
for
_
,
pod
:=
range
pods
.
Items
{
logger
.
Debugf
(
"got the pod (name: %s), (label: %v), (annotations: %v)"
,
pod
.
Name
,
pod
.
GetLabels
(),
pod
.
GetAnnotations
())
logger
.
Debugf
(
"got the pod (name: %s), (label: %v), (annotations: %v)"
,
pod
.
Name
,
pod
.
GetLabels
(),
pod
.
GetAnnotations
())
c
.
handleWatchedPodEvent
(
&
pod
,
watch
.
Added
)
c
.
handleWatchedPodEvent
(
&
pod
,
watch
.
Added
)
...
@@ -271,6 +277,7 @@ func (c *Client) watchPods() error {
...
@@ -271,6 +277,7 @@ func (c *Client) watchPods() error {
watcher
,
err
:=
c
.
rawClient
.
CoreV1
()
.
Pods
(
c
.
ns
)
.
Watch
(
metav1
.
ListOptions
{
watcher
,
err
:=
c
.
rawClient
.
CoreV1
()
.
Pods
(
c
.
ns
)
.
Watch
(
metav1
.
ListOptions
{
LabelSelector
:
fields
.
OneTermEqualSelector
(
DubboIOLabelKey
,
DubboIOLabelValue
)
.
String
(),
LabelSelector
:
fields
.
OneTermEqualSelector
(
DubboIOLabelKey
,
DubboIOLabelValue
)
.
String
(),
Watch
:
true
,
Watch
:
true
,
ResourceVersion
:
c
.
lastResourceVersion
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
perrors
.
WithMessagef
(
err
,
"try to watch the namespace (%s) pods"
,
c
.
ns
)
return
perrors
.
WithMessagef
(
err
,
"try to watch the namespace (%s) pods"
,
c
.
ns
)
...
@@ -294,14 +301,12 @@ func (c *Client) watchPodsLoop() {
...
@@ -294,14 +301,12 @@ func (c *Client) watchPodsLoop() {
logger
.
Info
(
"watchPodsLoop goroutine game over"
)
logger
.
Info
(
"watchPodsLoop goroutine game over"
)
}()
}()
var
lastResourceVersion
string
for
{
for
{
wc
,
err
:=
c
.
rawClient
.
CoreV1
()
.
Pods
(
c
.
ns
)
.
Watch
(
metav1
.
ListOptions
{
wc
,
err
:=
c
.
rawClient
.
CoreV1
()
.
Pods
(
c
.
ns
)
.
Watch
(
metav1
.
ListOptions
{
LabelSelector
:
fields
.
OneTermEqualSelector
(
DubboIOLabelKey
,
DubboIOLabelValue
)
.
String
(),
LabelSelector
:
fields
.
OneTermEqualSelector
(
DubboIOLabelKey
,
DubboIOLabelValue
)
.
String
(),
Watch
:
true
,
Watch
:
true
,
ResourceVersion
:
lastResourceVersion
,
ResourceVersion
:
c
.
lastResourceVersion
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Warnf
(
"watch the namespace (%s) pods: %v, retry after 2 seconds"
,
c
.
ns
,
err
)
logger
.
Warnf
(
"watch the namespace (%s) pods: %v, retry after 2 seconds"
,
c
.
ns
,
err
)
...
@@ -309,7 +314,7 @@ func (c *Client) watchPodsLoop() {
...
@@ -309,7 +314,7 @@ func (c *Client) watchPodsLoop() {
continue
continue
}
}
logger
.
Infof
(
"the old kubernetes client broken, collect the resource status from resource version (%s)"
,
lastResourceVersion
)
logger
.
Infof
(
"the old kubernetes client broken, collect the resource status from resource version (%s)"
,
c
.
lastResourceVersion
)
select
{
select
{
case
<-
c
.
ctx
.
Done
()
:
case
<-
c
.
ctx
.
Done
()
:
...
@@ -350,8 +355,8 @@ func (c *Client) watchPodsLoop() {
...
@@ -350,8 +355,8 @@ func (c *Client) watchPodsLoop() {
}
}
// record the last resource version avoid to sync all pod
// record the last resource version avoid to sync all pod
lastResourceVersion
=
o
.
GetResourceVersion
()
c
.
lastResourceVersion
=
o
.
GetResourceVersion
()
logger
.
Infof
(
"kuber
e
ntes get the current resource version %v"
,
lastResourceVersion
)
logger
.
Infof
(
"kubern
e
tes get the current resource version %v"
,
c
.
lastResourceVersion
)
// check event object type
// check event object type
p
,
ok
:=
event
.
Object
.
(
*
v1
.
Pod
)
p
,
ok
:=
event
.
Object
.
(
*
v1
.
Pod
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment