mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
commit
c746dd8df5
@ -85,9 +85,21 @@ func MakeReplicationManager(etcdClient *etcd.Client, kubeClient client.ClientInt
|
|||||||
|
|
||||||
func (rm *ReplicationManager) WatchControllers() {
|
func (rm *ReplicationManager) WatchControllers() {
|
||||||
watchChannel := make(chan *etcd.Response)
|
watchChannel := make(chan *etcd.Response)
|
||||||
go util.Forever(func() { rm.etcdClient.Watch("/registry/controllers", 0, true, watchChannel, nil) }, 0)
|
go func() {
|
||||||
|
defer util.HandleCrash()
|
||||||
|
defer func() {
|
||||||
|
close(watchChannel)
|
||||||
|
}()
|
||||||
|
rm.etcdClient.Watch("/registry/controllers", 0, true, watchChannel, nil)
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
watchResponse := <-watchChannel
|
watchResponse, ok := <-watchChannel
|
||||||
|
if !ok {
|
||||||
|
// watchChannel has been closed. Let the util.Forever() that
|
||||||
|
// called us call us again.
|
||||||
|
return
|
||||||
|
}
|
||||||
if watchResponse == nil {
|
if watchResponse == nil {
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
continue
|
continue
|
||||||
|
@ -18,7 +18,9 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +28,15 @@ import (
|
|||||||
func HandleCrash() {
|
func HandleCrash() {
|
||||||
r := recover()
|
r := recover()
|
||||||
if r != nil {
|
if r != nil {
|
||||||
log.Printf("Recovered from panic: %#v", r)
|
callers := ""
|
||||||
|
for i := 0; true; i++ {
|
||||||
|
_, file, line, ok := runtime.Caller(i)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
callers = callers + fmt.Sprintf("%v:%v\n", file, line)
|
||||||
|
}
|
||||||
|
log.Printf("Recovered from panic: %#v (%v)\n%v", r, r, callers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user