Skip to content

Commit deb7531

Browse files
author
Thibault Gilles
committed
Only watch leaf for our service
1 parent 969b934 commit deb7531

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

consul/watcher.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Watcher struct {
5555
downstream downstream
5656
certCAs [][]byte
5757
certCAPool *x509.CertPool
58-
leafs map[string]*certLeaf
58+
leaf *certLeaf
5959

6060
update chan struct{}
6161
}
@@ -68,7 +68,6 @@ func New(service string, consul *api.Client) *Watcher {
6868
C: make(chan Config),
6969
upstreams: make(map[string]*upstream),
7070
update: make(chan struct{}, 1),
71-
leafs: make(map[string]*certLeaf),
7271
}
7372
}
7473

@@ -129,7 +128,6 @@ func (w *Watcher) handleProxyChange(first bool, srv *api.AgentService) {
129128
w.lock.Unlock()
130129
if !ok {
131130
w.startUpstream(up)
132-
w.watchLeaf(up.DestinationName)
133131
}
134132
}
135133
}
@@ -228,11 +226,11 @@ func (w *Watcher) watchLeaf(service string) {
228226
if changed {
229227
log.Debugf("consul: leaf cert for service %s changed", service)
230228
w.lock.Lock()
231-
if _, ok := w.leafs[service]; !ok {
232-
w.leafs[service] = &certLeaf{}
229+
if w.leaf == nil {
230+
w.leaf = &certLeaf{}
233231
}
234-
w.leafs[service].Cert = []byte(cert.CertPEM)
235-
w.leafs[service].Key = []byte(cert.PrivateKeyPEM)
232+
w.leaf.Cert = []byte(cert.CertPEM)
233+
w.leaf.Key = []byte(cert.PrivateKeyPEM)
236234
w.lock.Unlock()
237235
w.notifyChanged()
238236
}
@@ -335,8 +333,8 @@ func (w *Watcher) genCfg() Config {
335333

336334
TLS: TLS{
337335
CAs: w.certCAs,
338-
Cert: w.leafs[w.serviceName].Cert,
339-
Key: w.leafs[w.serviceName].Key,
336+
Cert: w.leaf.Cert,
337+
Key: w.leaf.Key,
340338
},
341339
},
342340
}
@@ -349,8 +347,8 @@ func (w *Watcher) genCfg() Config {
349347

350348
TLS: TLS{
351349
CAs: w.certCAs,
352-
Cert: w.leafs[w.serviceName].Cert,
353-
Key: w.leafs[w.serviceName].Key,
350+
Cert: w.leaf.Cert,
351+
Key: w.leaf.Key,
354352
},
355353
}
356354

0 commit comments

Comments
 (0)