Skip to content

Commit

Permalink
Consolidate multiple stop channels into one
Browse files Browse the repository at this point in the history
  • Loading branch information
thoro committed Aug 20, 2017
1 parent 72fd0d2 commit 9bd4bb8
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ func (kr *KubeRouter) stopApiWatchers() {
func (kr *KubeRouter) Run() error {

var err error
var nscStopCh, npcStopCh, nrcStopCh chan struct{}
var wg sync.WaitGroup

stopCh := make(chan struct{})

err = kr.startApiWatchers()
if err != nil {
return errors.New("Failed to start API watchers: " + err.Error())
Expand All @@ -125,29 +126,29 @@ func (kr *KubeRouter) Run() error {
if err != nil {
return errors.New("Failed to create network policy controller: " + err.Error())
}
npcStopCh = make(chan struct{})

wg.Add(1)
go npc.Run(npcStopCh, &wg)
go npc.Run(stopCh, &wg)
}

if kr.Config.RunRouter {
nrc, err := controllers.NewNetworkRoutingController(kr.Client, kr.Config)
if err != nil {
return errors.New("Failed to create network routing controller: " + err.Error())
}
nrcStopCh = make(chan struct{})

wg.Add(1)
go nrc.Run(nrcStopCh, &wg)
go nrc.Run(stopCh, &wg)
}

if kr.Config.RunServiceProxy {
nsc, err := controllers.NewNetworkServicesController(kr.Client, kr.Config)
if err != nil {
return errors.New("Failed to create network services controller: " + err.Error())
}
nscStopCh = make(chan struct{})

wg.Add(1)
go nsc.Run(nscStopCh, &wg)
go nsc.Run(stopCh, &wg)
}

// Handle SIGINT and SIGTERM
Expand All @@ -156,15 +157,7 @@ func (kr *KubeRouter) Run() error {
<-ch

glog.Infof("Shutting down the controllers")
if kr.Config.RunServiceProxy {
nscStopCh <- struct{}{}
}
if kr.Config.RunFirewall {
npcStopCh <- struct{}{}
}
if kr.Config.RunRouter {
nrcStopCh <- struct{}{}
}
close(stopCh)

kr.stopApiWatchers()

Expand Down

0 comments on commit 9bd4bb8

Please sign in to comment.