Merge pull request #81577 from logicalhan/lazy-init

lock the mutation of the create boolean for safety
This commit is contained in:
Kubernetes Prow Robot 2019-08-19 02:53:44 -07:00 committed by GitHub
commit cb7c98e59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,12 +64,15 @@ type lazyMetric struct {
isDeprecated bool
isHidden bool
isCreated bool
createLock sync.RWMutex
markDeprecationOnce sync.Once
createOnce sync.Once
self kubeCollector
}
func (r *lazyMetric) IsCreated() bool {
r.createLock.RLock()
defer r.createLock.RUnlock()
return r.isCreated
}
@ -125,6 +128,8 @@ func (r *lazyMetric) Create(version *semver.Version) bool {
return false
}
r.createOnce.Do(func() {
r.createLock.Lock()
defer r.createLock.Unlock()
r.isCreated = true
if r.IsDeprecated() {
r.self.initializeDeprecatedMetric()