mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
refactor: Use plain channel send or receive
fix issue #4369 should use a simple channel send/receive instead of select with a single case Signed-off-by: Deshi Xiao <xiaods@gmail.com>
This commit is contained in:
parent
f9f1cabe9c
commit
f1622129e4
@ -92,42 +92,40 @@ func Setup(ctx context.Context, config *config.Node, proxy proxy.Proxy) error {
|
|||||||
}
|
}
|
||||||
watching:
|
watching:
|
||||||
for {
|
for {
|
||||||
select {
|
ev, ok := <-watch.ResultChan()
|
||||||
case ev, ok := <-watch.ResultChan():
|
if !ok || ev.Type == watchtypes.Error {
|
||||||
if !ok || ev.Type == watchtypes.Error {
|
if ok {
|
||||||
if ok {
|
logrus.Errorf("Tunnel endpoint watch channel closed: %v", ev)
|
||||||
logrus.Errorf("Tunnel endpoint watch channel closed: %v", ev)
|
|
||||||
}
|
|
||||||
watch.Stop()
|
|
||||||
continue connect
|
|
||||||
}
|
}
|
||||||
endpoint, ok := ev.Object.(*v1.Endpoints)
|
watch.Stop()
|
||||||
if !ok {
|
continue connect
|
||||||
logrus.Errorf("Tunnel could not convert event object to endpoint: %v", ev)
|
}
|
||||||
continue watching
|
endpoint, ok := ev.Object.(*v1.Endpoints)
|
||||||
|
if !ok {
|
||||||
|
logrus.Errorf("Tunnel could not convert event object to endpoint: %v", ev)
|
||||||
|
continue watching
|
||||||
|
}
|
||||||
|
|
||||||
|
newAddresses := util.GetAddresses(endpoint)
|
||||||
|
if reflect.DeepEqual(newAddresses, proxy.SupervisorAddresses()) {
|
||||||
|
continue watching
|
||||||
|
}
|
||||||
|
proxy.Update(newAddresses)
|
||||||
|
|
||||||
|
validEndpoint := map[string]bool{}
|
||||||
|
|
||||||
|
for _, address := range proxy.SupervisorAddresses() {
|
||||||
|
validEndpoint[address] = true
|
||||||
|
if _, ok := disconnect[address]; !ok {
|
||||||
|
disconnect[address] = connect(ctx, nil, address, tlsConfig)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newAddresses := util.GetAddresses(endpoint)
|
for address, cancel := range disconnect {
|
||||||
if reflect.DeepEqual(newAddresses, proxy.SupervisorAddresses()) {
|
if !validEndpoint[address] {
|
||||||
continue watching
|
cancel()
|
||||||
}
|
delete(disconnect, address)
|
||||||
proxy.Update(newAddresses)
|
logrus.Infof("Stopped tunnel to %s", address)
|
||||||
|
|
||||||
validEndpoint := map[string]bool{}
|
|
||||||
|
|
||||||
for _, address := range proxy.SupervisorAddresses() {
|
|
||||||
validEndpoint[address] = true
|
|
||||||
if _, ok := disconnect[address]; !ok {
|
|
||||||
disconnect[address] = connect(ctx, nil, address, tlsConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for address, cancel := range disconnect {
|
|
||||||
if !validEndpoint[address] {
|
|
||||||
cancel()
|
|
||||||
delete(disconnect, address)
|
|
||||||
logrus.Infof("Stopped tunnel to %s", address)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user