Replace with roughly equivalent code which relies upon the existing
mutexes for synchronization.
Signed-off-by: Cory Snider <csnider@mirantis.com>
| ... | ... |
@@ -87,8 +87,6 @@ type Controller struct {
|
| 87 | 87 |
cfg *config.Config |
| 88 | 88 |
store *datastore.Store |
| 89 | 89 |
extKeyListener net.Listener |
| 90 |
- watchCh chan *Endpoint |
|
| 91 |
- unWatchCh chan *Endpoint |
|
| 92 | 90 |
svcRecords map[string]*svcInfo |
| 93 | 91 |
nmap map[string]*netWatch |
| 94 | 92 |
serviceBindings map[serviceKey]*service |
| ... | ... |
@@ -114,6 +112,7 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
|
| 114 | 114 |
sandboxes: map[string]*Sandbox{},
|
| 115 | 115 |
svcRecords: make(map[string]*svcInfo), |
| 116 | 116 |
serviceBindings: make(map[serviceKey]*service), |
| 117 |
+ nmap: make(map[string]*netWatch), |
|
| 117 | 118 |
agentInitDone: make(chan struct{}),
|
| 118 | 119 |
networkLocker: locker.New(), |
| 119 | 120 |
DiagnosticServer: diagnostic.New(), |
| ... | ... |
@@ -20,7 +20,6 @@ func (c *Controller) initStores() error {
|
| 20 | 20 |
return err |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
- c.startWatch() |
|
| 24 | 23 |
return nil |
| 25 | 24 |
} |
| 26 | 25 |
|
| ... | ... |
@@ -190,11 +189,11 @@ type netWatch struct {
|
| 190 | 190 |
} |
| 191 | 191 |
|
| 192 | 192 |
func (c *Controller) watchSvcRecord(ep *Endpoint) {
|
| 193 |
- c.watchCh <- ep |
|
| 193 |
+ go c.processEndpointCreate(ep) |
|
| 194 | 194 |
} |
| 195 | 195 |
|
| 196 | 196 |
func (c *Controller) unWatchSvcRecord(ep *Endpoint) {
|
| 197 |
- c.unWatchCh <- ep |
|
| 197 |
+ go c.processEndpointDelete(ep) |
|
| 198 | 198 |
} |
| 199 | 199 |
|
| 200 | 200 |
func (c *Controller) processEndpointCreate(ep *Endpoint) {
|
| ... | ... |
@@ -249,28 +248,6 @@ func (c *Controller) processEndpointDelete(ep *Endpoint) {
|
| 249 | 249 |
c.mu.Unlock() |
| 250 | 250 |
} |
| 251 | 251 |
|
| 252 |
-func (c *Controller) watchLoop() {
|
|
| 253 |
- for {
|
|
| 254 |
- select {
|
|
| 255 |
- case ep := <-c.watchCh: |
|
| 256 |
- c.processEndpointCreate(ep) |
|
| 257 |
- case ep := <-c.unWatchCh: |
|
| 258 |
- c.processEndpointDelete(ep) |
|
| 259 |
- } |
|
| 260 |
- } |
|
| 261 |
-} |
|
| 262 |
- |
|
| 263 |
-func (c *Controller) startWatch() {
|
|
| 264 |
- if c.watchCh != nil {
|
|
| 265 |
- return |
|
| 266 |
- } |
|
| 267 |
- c.watchCh = make(chan *Endpoint) |
|
| 268 |
- c.unWatchCh = make(chan *Endpoint) |
|
| 269 |
- c.nmap = make(map[string]*netWatch) |
|
| 270 |
- |
|
| 271 |
- go c.watchLoop() |
|
| 272 |
-} |
|
| 273 |
- |
|
| 274 | 252 |
func (c *Controller) networkCleanup() {
|
| 275 | 253 |
for _, n := range c.getNetworksFromStore() {
|
| 276 | 254 |
if n.inDelete {
|