Skip to content
Snippets Groups Projects
Commit bcda018a authored by scott's avatar scott
Browse files

delete unused select case

parent 883f30a6
No related branches found
No related tags found
No related merge requests found
...@@ -291,6 +291,10 @@ func (c *Client) watchPods() error { ...@@ -291,6 +291,10 @@ func (c *Client) watchPods() error {
return nil return nil
} }
type resourceVersionGetter interface {
GetResourceVersion() string
}
// watchPods // watchPods
// try to notify // try to notify
func (c *Client) watchPodsLoop() { func (c *Client) watchPodsLoop() {
...@@ -316,61 +320,49 @@ 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) logger.Infof("the old kubernetes client broken, collect the resource status from resource version (%s)", c.lastResourceVersion)
select { for {
case <-c.ctx.Done(): select {
// the client stopped // double check ctx
logger.Info("the kubernetes client stopped") case <-c.ctx.Done():
return logger.Info("the kubernetes client stopped, resultChan len %d", len(wc.ResultChan()))
return
default:
for { // get one element from result-chan
select { case event, ok := <-wc.ResultChan():
// double check ctx if !ok {
case <-c.ctx.Done(): wc.Stop()
logger.Info("the kubernetes client stopped") logger.Info("kubernetes watch chan die, create new")
goto onceWatch goto onceWatch
}
// get one element from result-chan if event.Type == watch.Error {
case event, ok := <-wc.ResultChan(): // watched a error event
if !ok { logger.Warnf("kubernetes watch api report err (%#v)", event)
wc.Stop() continue
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)
} }
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:
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment