Merge pull request #76868 from tedyu/res-quota-mon-read

Use read lock for QuotaMonitor#IsSynced
k3s-v1.15.3
Kubernetes Prow Robot 2019-05-01 20:42:31 -07:00 committed by GitHub
commit b03e4bbc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -69,7 +69,7 @@ type event struct {
type QuotaMonitor struct { type QuotaMonitor struct {
// each monitor list/watches a resource and determines if we should replenish quota // each monitor list/watches a resource and determines if we should replenish quota
monitors monitors monitors monitors
monitorLock sync.Mutex monitorLock sync.RWMutex
// informersStarted is closed after after all of the controllers have been initialized and are running. // informersStarted is closed after after all of the controllers have been initialized and are running.
// After that it is safe to start them here, before that it is not. // After that it is safe to start them here, before that it is not.
informersStarted <-chan struct{} informersStarted <-chan struct{}
@ -280,8 +280,8 @@ func (qm *QuotaMonitor) StartMonitors() {
// true at one time, and then later return false if all monitors were // true at one time, and then later return false if all monitors were
// reconstructed. // reconstructed.
func (qm *QuotaMonitor) IsSynced() bool { func (qm *QuotaMonitor) IsSynced() bool {
qm.monitorLock.Lock() qm.monitorLock.RLock()
defer qm.monitorLock.Unlock() defer qm.monitorLock.RUnlock()
if len(qm.monitors) == 0 { if len(qm.monitors) == 0 {
klog.V(4).Info("quota monitor not synced: no monitors") klog.V(4).Info("quota monitor not synced: no monitors")