Fix k8s client panic
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
710508dc40
commit
926eb099f1
1 changed files with 15 additions and 8 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/parnurzeal/gorequest"
|
"github.com/parnurzeal/gorequest"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -160,7 +161,7 @@ func (c *clientImpl) WatchAll(labelSelector string, stopCh <-chan bool) (chan in
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return watchCh, errCh, fmt.Errorf("failed to create watch: %v", err)
|
return watchCh, errCh, fmt.Errorf("failed to create watch: %v", err)
|
||||||
}
|
}
|
||||||
go func() {
|
safe.Go(func() {
|
||||||
defer close(watchCh)
|
defer close(watchCh)
|
||||||
defer close(errCh)
|
defer close(errCh)
|
||||||
defer close(stopIngresses)
|
defer close(stopIngresses)
|
||||||
|
@ -188,7 +189,7 @@ func (c *clientImpl) WatchAll(labelSelector string, stopCh <-chan bool) (chan in
|
||||||
watchCh <- event
|
watchCh <- event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
return watchCh, errCh, nil
|
return watchCh, errCh, nil
|
||||||
}
|
}
|
||||||
|
@ -268,11 +269,16 @@ func (c *clientImpl) watch(url string, labelSelector string, stopCh <-chan bool)
|
||||||
return watchCh, errCh, fmt.Errorf("failed to do watch request: GET %q: %v", url, err)
|
return watchCh, errCh, fmt.Errorf("failed to do watch request: GET %q: %v", url, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
safe.Go(func() {
|
||||||
|
EndCh := make(chan bool, 1)
|
||||||
defer close(watchCh)
|
defer close(watchCh)
|
||||||
defer close(errCh)
|
defer close(errCh)
|
||||||
go func() {
|
defer close(EndCh)
|
||||||
|
safe.Go(func() {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
defer func() {
|
||||||
|
EndCh <- true
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
var eventList interface{}
|
var eventList interface{}
|
||||||
if err := json.NewDecoder(res.Body).Decode(&eventList); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&eventList); err != nil {
|
||||||
|
@ -283,11 +289,12 @@ func (c *clientImpl) watch(url string, labelSelector string, stopCh <-chan bool)
|
||||||
}
|
}
|
||||||
watchCh <- eventList
|
watchCh <- eventList
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
<-stopCh
|
<-stopCh
|
||||||
go func() {
|
safe.Go(func() {
|
||||||
cancel() // cancel watch request
|
cancel() // cancel watch request
|
||||||
}()
|
})
|
||||||
}()
|
<-EndCh
|
||||||
|
})
|
||||||
return watchCh, errCh, nil
|
return watchCh, errCh, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue