mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +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
|
||||
}
|
||||
|
||||
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}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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}
|
||||
|
||||
s.lock.Lock()
|
||||
|
@ -45,7 +45,7 @@ type isImmutableFunc func(runtime.Object) bool
|
||||
|
||||
// objectCacheItem is a single item stored in objectCache.
|
||||
type objectCacheItem struct {
|
||||
refCount int
|
||||
refMap map[types.UID]int
|
||||
store *cacheStore
|
||||
reflector *cache.Reflector
|
||||
|
||||
@ -232,7 +232,7 @@ func (c *objectCache) newReflectorLocked(namespace, name string) *objectCacheIte
|
||||
0,
|
||||
)
|
||||
item := &objectCacheItem{
|
||||
refCount: 0,
|
||||
refMap: make(map[types.UID]int),
|
||||
store: store,
|
||||
reflector: reflector,
|
||||
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)
|
||||
c.items[key] = item
|
||||
}
|
||||
item.refCount++
|
||||
item.refMap[podUID]++
|
||||
}
|
||||
|
||||
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()
|
||||
defer c.lock.Unlock()
|
||||
if item, ok := c.items[key]; ok {
|
||||
item.refCount--
|
||||
if item.refCount == 0 {
|
||||
item.refMap[podUID]--
|
||||
if item.refMap[podUID] == 0 {
|
||||
delete(item.refMap, podUID)
|
||||
}
|
||||
if len(item.refMap) == 0 {
|
||||
// Stop the underlying reflector.
|
||||
item.stop()
|
||||
delete(c.items, key)
|
||||
|
Loading…
Reference in New Issue
Block a user