Skip to content

Commit

Permalink
Merge pull request #652 from erikwilson/update-tunnel-wait
Browse files Browse the repository at this point in the history
Fix tunnel endpoint upgrade
  • Loading branch information
erikwilson authored Jul 18, 2019
2 parents 33a5954 + 23b0797 commit 75b8d71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func run(ctx context.Context, cfg cmds.Agent) error {
return err
}

if err := tunnel.Setup(nodeConfig); err != nil {
if err := tunnel.Setup(ctx, nodeConfig); err != nil {
return err
}

Expand Down
19 changes: 17 additions & 2 deletions pkg/agent/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func getAddresses(endpoint *v1.Endpoints) []string {
return serverAddresses
}

func Setup(config *config.Node) error {
func Setup(ctx context.Context, config *config.Node) error {
restConfig, err := clientcmd.BuildConfigFromFlags("", config.AgentConfig.KubeConfigNode)
if err != nil {
return err
Expand Down Expand Up @@ -83,7 +83,6 @@ func Setup(config *config.Node) error {
disconnect[address] = connect(wg, address, config, transportConfig)
}
}
wg.Wait()

go func() {
connect:
Expand Down Expand Up @@ -134,6 +133,19 @@ func Setup(config *config.Node) error {
}
}()

wait := make(chan int, 1)
go func() {
wg.Wait()
wait <- 0
}()

select {
case <-ctx.Done():
logrus.Error("tunnel context canceled while waiting for connection")
return ctx.Err()
case <-wait:
}

return nil
}

Expand Down Expand Up @@ -178,6 +190,9 @@ func connect(waitGroup *sync.WaitGroup, address string, config *config.Node, tra
})

if ctx.Err() != nil {
if waitGroup != nil {
once.Do(waitGroup.Done)
}
logrus.Infof("Stopped tunnel to %s", wsURL)
return
}
Expand Down

0 comments on commit 75b8d71

Please sign in to comment.