Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define sync channels without creating and closing them #19

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions subcommand/sync-catalog/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func (c *Command) Run(args []string) int {
ctx, cancelF := context.WithCancel(context.Background())

// Start the K8S-to-Consul syncer
toConsulCh := make(chan struct{})
close(toConsulCh)
var toConsulCh chan struct{}
if c.flagToConsul {
// Build the Consul sync and start it
syncer := &catalogFromK8S.ConsulSyncer{
Expand Down Expand Up @@ -149,8 +148,7 @@ func (c *Command) Run(args []string) int {
}

// Start Consul-to-K8S sync
toK8SCh := make(chan struct{})
close(toK8SCh)
var toK8SCh chan struct{}
if c.flagToK8S {
sink := &catalogFromConsul.K8SSink{
Client: clientset,
Expand Down Expand Up @@ -187,20 +185,28 @@ func (c *Command) Run(args []string) int {
// Unexpected exit
case <-toConsulCh:
cancelF()
<-toK8SCh
if toK8SCh != nil {
<-toK8SCh
}
return 1

// Unexpected exit
case <-toK8SCh:
cancelF()
<-toConsulCh
if toConsulCh != nil {
<-toConsulCh
}
return 1

// Interrupted, gracefully exit
case <-sigCh:
cancelF()
<-toConsulCh
<-toK8SCh
if toConsulCh != nil {
<-toConsulCh
}
if toK8SCh != nil {
<-toK8SCh
}
return 0
}
}
Expand Down