mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
record podUID in refMap in watchBasedManager
Signed-off-by: Ruquan Zhao <ruquan.zhao@arm.com>
This commit is contained in:
parent
936265e870
commit
ccb4ca8954
@ -92,7 +92,7 @@ func isObjectOlder(newObject, oldObject runtime.Object) bool {
|
|||||||
return newVersion < oldVersion
|
return newVersion < oldVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *objectStore) AddReference(namespace, name string, podUID types.UID) {
|
func (s *objectStore) AddReference(namespace, name string, _ types.UID) {
|
||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
// AddReference is called from RegisterPod, thus it needs to be efficient.
|
// AddReference is called from RegisterPod, thus it needs to be efficient.
|
||||||
@ -114,7 +114,7 @@ func (s *objectStore) AddReference(namespace, name string, podUID types.UID) {
|
|||||||
item.data = nil
|
item.data = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *objectStore) DeleteReference(namespace, name string, podUID types.UID) {
|
func (s *objectStore) DeleteReference(namespace, name string, _ types.UID) {
|
||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
|
@ -45,7 +45,7 @@ type isImmutableFunc func(runtime.Object) bool
|
|||||||
|
|
||||||
// objectCacheItem is a single item stored in objectCache.
|
// objectCacheItem is a single item stored in objectCache.
|
||||||
type objectCacheItem struct {
|
type objectCacheItem struct {
|
||||||
refCount int
|
refMap map[types.UID]int
|
||||||
store *cacheStore
|
store *cacheStore
|
||||||
reflector *cache.Reflector
|
reflector *cache.Reflector
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ func (c *objectCache) newReflectorLocked(namespace, name string) *objectCacheIte
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
item := &objectCacheItem{
|
item := &objectCacheItem{
|
||||||
refCount: 0,
|
refMap: make(map[types.UID]int),
|
||||||
store: store,
|
store: store,
|
||||||
reflector: reflector,
|
reflector: reflector,
|
||||||
hasSynced: func() (bool, error) { return store.hasSynced(), nil },
|
hasSynced: func() (bool, error) { return store.hasSynced(), nil },
|
||||||
@ -261,7 +261,7 @@ func (c *objectCache) AddReference(namespace, name string, podUID types.UID) {
|
|||||||
item = c.newReflectorLocked(namespace, name)
|
item = c.newReflectorLocked(namespace, name)
|
||||||
c.items[key] = item
|
c.items[key] = item
|
||||||
}
|
}
|
||||||
item.refCount++
|
item.refMap[podUID]++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *objectCache) DeleteReference(namespace, name string, podUID types.UID) {
|
func (c *objectCache) DeleteReference(namespace, name string, podUID types.UID) {
|
||||||
@ -270,8 +270,11 @@ func (c *objectCache) DeleteReference(namespace, name string, podUID types.UID)
|
|||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if item, ok := c.items[key]; ok {
|
if item, ok := c.items[key]; ok {
|
||||||
item.refCount--
|
item.refMap[podUID]--
|
||||||
if item.refCount == 0 {
|
if item.refMap[podUID] == 0 {
|
||||||
|
delete(item.refMap, podUID)
|
||||||
|
}
|
||||||
|
if len(item.refMap) == 0 {
|
||||||
// Stop the underlying reflector.
|
// Stop the underlying reflector.
|
||||||
item.stop()
|
item.stop()
|
||||||
delete(c.items, key)
|
delete(c.items, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user