mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 10:17:51 +00:00
Re-vendor
This commit is contained in:
parent
0429028c4f
commit
ab00b207af
910 changed files with 63539 additions and 106415 deletions
30
vendor/k8s.io/client-go/tools/cache/mutation_detector.go
generated
vendored
30
vendor/k8s.io/client-go/tools/cache/mutation_detector.go
generated
vendored
|
|
@ -36,9 +36,12 @@ func init() {
|
|||
mutationDetectionEnabled, _ = strconv.ParseBool(os.Getenv("KUBE_CACHE_MUTATION_DETECTOR"))
|
||||
}
|
||||
|
||||
// MutationDetector is able to monitor if the object be modified outside.
|
||||
// MutationDetector is able to monitor objects for mutation within a limited window of time
|
||||
type MutationDetector interface {
|
||||
// AddObject adds the given object to the set being monitored for a while from now
|
||||
AddObject(obj interface{})
|
||||
|
||||
// Run starts the monitoring and does not return until the monitoring is stopped.
|
||||
Run(stopCh <-chan struct{})
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +68,13 @@ type defaultCacheMutationDetector struct {
|
|||
name string
|
||||
period time.Duration
|
||||
|
||||
lock sync.Mutex
|
||||
// compareLock ensures only a single call to CompareObjects runs at a time
|
||||
compareObjectsLock sync.Mutex
|
||||
|
||||
// addLock guards addedObjs between AddObject and CompareObjects
|
||||
addedObjsLock sync.Mutex
|
||||
addedObjs []cacheObj
|
||||
|
||||
cachedObjs []cacheObj
|
||||
|
||||
retainDuration time.Duration
|
||||
|
|
@ -115,15 +124,22 @@ func (d *defaultCacheMutationDetector) AddObject(obj interface{}) {
|
|||
if obj, ok := obj.(runtime.Object); ok {
|
||||
copiedObj := obj.DeepCopyObject()
|
||||
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
d.cachedObjs = append(d.cachedObjs, cacheObj{cached: obj, copied: copiedObj})
|
||||
d.addedObjsLock.Lock()
|
||||
defer d.addedObjsLock.Unlock()
|
||||
d.addedObjs = append(d.addedObjs, cacheObj{cached: obj, copied: copiedObj})
|
||||
}
|
||||
}
|
||||
|
||||
func (d *defaultCacheMutationDetector) CompareObjects() {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
d.compareObjectsLock.Lock()
|
||||
defer d.compareObjectsLock.Unlock()
|
||||
|
||||
// move addedObjs into cachedObjs under lock
|
||||
// this keeps the critical section small to avoid blocking AddObject while we compare cachedObjs
|
||||
d.addedObjsLock.Lock()
|
||||
d.cachedObjs = append(d.cachedObjs, d.addedObjs...)
|
||||
d.addedObjs = nil
|
||||
d.addedObjsLock.Unlock()
|
||||
|
||||
altered := false
|
||||
for i, obj := range d.cachedObjs {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue