diff --git a/pkg/agent/tunnel/tunnel.go b/pkg/agent/tunnel/tunnel.go index 648702f212..68f11e7702 100644 --- a/pkg/agent/tunnel/tunnel.go +++ b/pkg/agent/tunnel/tunnel.go @@ -68,10 +68,12 @@ func Setup(config *config.Node) error { } addresses := []string{config.ServerAddress} + endpointResourceVersion := "" endpoint, _ := client.CoreV1().Endpoints("default").Get("kubernetes", metav1.GetOptions{}) if endpoint != nil { addresses = getAddresses(endpoint) + endpointResourceVersion = endpoint.ResourceVersion } disconnect := map[string]context.CancelFunc{} @@ -88,10 +90,11 @@ func Setup(config *config.Node) error { connect: for { watch, err := client.CoreV1().Endpoints("default").Watch(metav1.ListOptions{ - FieldSelector: fields.Set{"metadata.name": "kubernetes"}.String(), + FieldSelector: fields.Set{"metadata.name": "kubernetes"}.String(), + ResourceVersion: endpointResourceVersion, }) if err != nil { - logrus.Errorf("Unable to watch for endpoints: %v", err) + logrus.Errorf("Unable to watch for tunnel endpoints: %v", err) time.Sleep(5 * time.Second) continue connect } @@ -100,21 +103,25 @@ func Setup(config *config.Node) error { select { case ev, ok := <-watch.ResultChan(): if !ok { - logrus.Error("endpoint watch channel closed") + logrus.Error("Tunnel endpoint watch channel closed") continue connect } endpoint, ok := ev.Object.(*v1.Endpoints) if !ok { - logrus.Error("could not case event object to endpoint") + logrus.Error("Tunnel could not case event object to endpoint") continue watching } + endpointResourceVersion = endpoint.ResourceVersion + + var addresses = getAddresses(endpoint) + logrus.Infof("Tunnel endpoint watch event: %v", addresses) validEndpoint := map[string]bool{} - var addresses = getAddresses(endpoint) + for _, address := range addresses { validEndpoint[address] = true if _, ok := disconnect[address]; !ok { - disconnect[address] = connect(wg, address, config, transportConfig) + disconnect[address] = connect(nil, address, config, transportConfig) } } @@ -173,7 +180,7 @@ func connect(waitGroup *sync.WaitGroup, address string, config *config.Node, tra }) if ctx.Err() != nil { - logrus.Infof("Stopping tunnel to %s", wsURL) + logrus.Infof("Stopped tunnel to %s", wsURL) return } } diff --git a/trash.lock b/trash.lock index a88cfbc277..1a56bff84d 100755 --- a/trash.lock +++ b/trash.lock @@ -229,7 +229,7 @@ import: - package: github.com/rancher/helm-controller version: v0.2.1 - package: github.com/rancher/remotedialer - version: 66218bc42b4fa27c34523c0d19a41a0e2b74983d + version: 4a5a661be67697d6369df54ef62d5a30b0385697 - package: github.com/rancher/wrangler version: 7737c167e16514a38229bc64c839cee8cd14e6d3 - package: github.com/rancher/wrangler-api diff --git a/vendor.conf b/vendor.conf index f17a254ae8..e187dfb76a 100644 --- a/vendor.conf +++ b/vendor.conf @@ -14,7 +14,7 @@ k8s.io/kubernetes v1.14.3-k3s.2 ht github.com/rancher/wrangler 7737c167e16514a38229bc64c839cee8cd14e6d3 github.com/rancher/wrangler-api v0.1.4 github.com/rancher/dynamiclistener 4716ac2362986f28bede3f3caf5d1ce347da55b0 -github.com/rancher/remotedialer 66218bc42b4fa27c34523c0d19a41a0e2b74983d +github.com/rancher/remotedialer 4a5a661be67697d6369df54ef62d5a30b0385697 github.com/rancher/helm-controller v0.2.1 github.com/matryer/moq ee5226d43009 https://github.com/rancher/moq.git github.com/coreos/flannel 823afe66b2266bf71f5bec24e6e28b26d70cfc7c https://github.com/ibuildthecloud/flannel.git diff --git a/vendor/github.com/rancher/remotedialer/client.go b/vendor/github.com/rancher/remotedialer/client.go index 48eefc9d7d..d56635e5f0 100644 --- a/vendor/github.com/rancher/remotedialer/client.go +++ b/vendor/github.com/rancher/remotedialer/client.go @@ -31,11 +31,11 @@ func connectToProxy(ctx context.Context, proxyURL string, headers http.Header, a } defer ws.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - if onConnect != nil { - if err := onConnect(ctx); err != nil { + ctxOnConnect, cancel := context.WithCancel(context.Background()) + defer cancel() + + if err := onConnect(ctxOnConnect); err != nil { return err } } @@ -51,7 +51,8 @@ func connectToProxy(ctx context.Context, proxyURL string, headers http.Header, a select { case <-ctx.Done(): - return ctx.Err() + logrus.WithField("url", proxyURL).WithField("err", ctx.Err()).Info("Proxy done") + return nil case err := <-result: return err }