Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
bcda018a
Commit
bcda018a
authored
5 years ago
by
scott
Browse files
Options
Downloads
Patches
Plain Diff
delete unused select case
parent
883f30a6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
remoting/kubernetes/client.go
+41
-49
41 additions, 49 deletions
remoting/kubernetes/client.go
with
41 additions
and
49 deletions
remoting/kubernetes/client.go
+
41
−
49
View file @
bcda018a
...
...
@@ -291,6 +291,10 @@ func (c *Client) watchPods() error {
return
nil
}
type
resourceVersionGetter
interface
{
GetResourceVersion
()
string
}
// watchPods
// try to notify
func
(
c
*
Client
)
watchPodsLoop
()
{
...
...
@@ -316,61 +320,49 @@ func (c *Client) watchPodsLoop() {
logger
.
Infof
(
"the old kubernetes client broken, collect the resource status from resource version (%s)"
,
c
.
lastResourceVersion
)
select
{
case
<-
c
.
ctx
.
Done
()
:
// the client stopped
logger
.
Info
(
"the kubernetes client stopped"
)
return
default
:
for
{
select
{
// double check ctx
case
<-
c
.
ctx
.
Done
()
:
logger
.
Info
(
"the kubernetes client stopped, resultChan len %d"
,
len
(
wc
.
ResultChan
()))
return
for
{
select
{
// double check ctx
case
<-
c
.
ctx
.
Done
()
:
logger
.
Info
(
"
the
kubernetes
client stopped
"
)
// get one element from result-chan
case
event
,
ok
:=
<-
wc
.
ResultChan
()
:
if
!
ok
{
wc
.
Stop
()
logger
.
Info
(
"kubernetes
watch chan die, create new
"
)
goto
onceWatch
}
// get one element from result-chan
case
event
,
ok
:=
<-
wc
.
ResultChan
()
:
if
!
ok
{
wc
.
Stop
()
logger
.
Info
(
"kubernetes watch chan die, create new"
)
goto
onceWatch
}
if
event
.
Type
==
watch
.
Error
{
// watched a error event
logger
.
Warnf
(
"kubernetes watch api report err (%#v)"
,
event
)
continue
}
type
resourceVersionGetter
interface
{
GetResourceVersion
()
string
}
o
,
ok
:=
event
.
Object
.
(
resourceVersionGetter
)
if
!
ok
{
continue
}
// record the last resource version avoid to sync all pod
c
.
lastResourceVersion
=
o
.
GetResourceVersion
()
logger
.
Infof
(
"kubernetes get the current resource version %v"
,
c
.
lastResourceVersion
)
// check event object type
p
,
ok
:=
event
.
Object
.
(
*
v1
.
Pod
)
if
!
ok
{
// not a pod
continue
}
// handle the watched pod
go
c
.
handleWatchedPodEvent
(
p
,
event
.
Type
)
if
event
.
Type
==
watch
.
Error
{
// watched a error event
logger
.
Warnf
(
"kubernetes watch api report err (%#v)"
,
event
)
continue
}
o
,
ok
:=
event
.
Object
.
(
resourceVersionGetter
)
if
!
ok
{
logger
.
Warnf
(
"kubernetes response object not a versioned object"
)
continue
}
// record the last resource version avoid to sync all pod
c
.
lastResourceVersion
=
o
.
GetResourceVersion
()
logger
.
Infof
(
"kubernetes get the current resource version %v"
,
c
.
lastResourceVersion
)
// check event object type
p
,
ok
:=
event
.
Object
.
(
*
v1
.
Pod
)
if
!
ok
{
// not a pod
continue
}
// handle the watched pod
go
c
.
handleWatchedPodEvent
(
p
,
event
.
Type
)
}
onceWatch
:
}
onceWatch
:
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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