@@ -107,9 +107,10 @@ func (kr *KubeRouter) stopApiWatchers() {
107107func (kr * KubeRouter ) Run () error {
108108
109109 var err error
110- var nscStopCh , npcStopCh , nrcStopCh chan struct {}
111110 var wg sync.WaitGroup
112111
112+ stopCh := make (chan struct {})
113+
113114 err = kr .startApiWatchers ()
114115 if err != nil {
115116 return errors .New ("Failed to start API watchers: " + err .Error ())
@@ -125,29 +126,29 @@ func (kr *KubeRouter) Run() error {
125126 if err != nil {
126127 return errors .New ("Failed to create network policy controller: " + err .Error ())
127128 }
128- npcStopCh = make ( chan struct {})
129+
129130 wg .Add (1 )
130- go npc .Run (npcStopCh , & wg )
131+ go npc .Run (stopCh , & wg )
131132 }
132133
133134 if kr .Config .RunRouter {
134135 nrc , err := controllers .NewNetworkRoutingController (kr .Client , kr .Config )
135136 if err != nil {
136137 return errors .New ("Failed to create network routing controller: " + err .Error ())
137138 }
138- nrcStopCh = make ( chan struct {})
139+
139140 wg .Add (1 )
140- go nrc .Run (nrcStopCh , & wg )
141+ go nrc .Run (stopCh , & wg )
141142 }
142143
143144 if kr .Config .RunServiceProxy {
144145 nsc , err := controllers .NewNetworkServicesController (kr .Client , kr .Config )
145146 if err != nil {
146147 return errors .New ("Failed to create network services controller: " + err .Error ())
147148 }
148- nscStopCh = make ( chan struct {})
149+
149150 wg .Add (1 )
150- go nsc .Run (nscStopCh , & wg )
151+ go nsc .Run (stopCh , & wg )
151152 }
152153
153154 // Handle SIGINT and SIGTERM
@@ -156,15 +157,7 @@ func (kr *KubeRouter) Run() error {
156157 <- ch
157158
158159 glog .Infof ("Shutting down the controllers" )
159- if kr .Config .RunServiceProxy {
160- nscStopCh <- struct {}{}
161- }
162- if kr .Config .RunFirewall {
163- npcStopCh <- struct {}{}
164- }
165- if kr .Config .RunRouter {
166- nrcStopCh <- struct {}{}
167- }
160+ close (stopCh )
168161
169162 kr .stopApiWatchers ()
170163
0 commit comments