Skip to content

Commit 088ea47

Browse files
Wei WengWei Weng
authored andcommitted
resolve AI comments
Signed-off-by: Wei Weng <Wei.Weng@microsoft.com>
1 parent c341417 commit 088ea47

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/utils/informer/informermanager.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ func (s *informerManagerImpl) Stop() {
206206
}
207207

208208
func (s *informerManagerImpl) AddEventHandlerToInformer(resource schema.GroupVersionResource, handler cache.ResourceEventHandler) {
209+
s.resourcesLock.Lock()
210+
defer s.resourcesLock.Unlock()
211+
209212
// Get or create the informer (this is idempotent - if it exists, we get the same instance)
210-
// The idempotent behavior is important because it is called by both the change detector and informer populator,
211-
// which run concurrently on the leader hub agent.
213+
// The idempotent behavior is important because this method may be called multiple times,
214+
// potentially concurrently, and relies on the shared informer instance from the factory.
212215
informer := s.informerFactory.ForResource(resource).Informer()
213216

214217
// Add the event handler to the informer
@@ -225,6 +228,7 @@ func (s *informerManagerImpl) CreateInformerForResource(resource APIResourceMeta
225228
if !exist {
226229
// Register this resource in our tracking map
227230
resource.isPresent = true
231+
resource.isStaticResource = false
228232
s.apiResources[resource.GroupVersionKind] = &resource
229233

230234
// Create the informer without adding any event handler

0 commit comments

Comments
 (0)