Avoid data race syncing secrets

This commit is contained in:
Manuel de Brito Fontes 2018-01-15 17:54:17 -03:00
parent 3fe8524318
commit 45326e4c58
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
2 changed files with 7 additions and 0 deletions

View file

@ -37,6 +37,9 @@ import (
// disk to allow copy of the content of the secret to disk to be used // disk to allow copy of the content of the secret to disk to be used
// by external processes. // by external processes.
func (s k8sStore) syncSecret(key string) { func (s k8sStore) syncSecret(key string) {
s.mu.Lock()
defer s.mu.Unlock()
glog.V(3).Infof("starting syncing of secret %v", key) glog.V(3).Infof("starting syncing of secret %v", key)
// TODO: getPemCertificate should not write to disk to avoid unnecessary overhead // TODO: getPemCertificate should not write to disk to avoid unnecessary overhead

View file

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"reflect" "reflect"
"sync"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
@ -182,6 +183,8 @@ type k8sStore struct {
filesystem file.Filesystem filesystem file.Filesystem
updateCh chan Event updateCh chan Event
mu *sync.Mutex
} }
// New creates a new object store to be used in the ingress controller // New creates a new object store to be used in the ingress controller
@ -200,6 +203,7 @@ func New(checkOCSP bool,
filesystem: fs, filesystem: fs,
updateCh: updateCh, updateCh: updateCh,
backendConfig: ngx_config.NewDefault(), backendConfig: ngx_config.NewDefault(),
mu: &sync.Mutex{},
} }
eventBroadcaster := record.NewBroadcaster() eventBroadcaster := record.NewBroadcaster()