Merge pull request #3376 from niuyueyang1996/fix-object-same-point

karmada-search: fix the problem that ResourceVersion base64 encrypted repeatedly when starting multiple informer to watch resource
This commit is contained in:
karmada-bot 2023-04-11 15:24:59 +08:00 committed by GitHub
commit b273800421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -315,7 +315,6 @@ func (c *MultiClusterCache) Watch(ctx context.Context, gvr schema.GroupVersionRe
} }
mux.AddSource(w, func(e watch.Event) { mux.AddSource(w, func(e watch.Event) {
// We can safely modify data because it is deepCopied in cacheWatcher.convertToWatchEvent
setObjectResourceVersionFunc(cluster, e.Object) setObjectResourceVersionFunc(cluster, e.Object)
addCacheSourceAnnotation(e.Object, cluster) addCacheSourceAnnotation(e.Object, cluster)
}) })

View File

@ -214,15 +214,16 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
defer source.Stop() defer source.Stop()
defer w.Stop() defer w.Stop()
for { for {
var event watch.Event var copyEvent watch.Event
var ok bool
select { select {
case event, ok = <-source.ResultChan(): case sourceEvent, ok := <-source.ResultChan():
if !ok { if !ok {
return return
} }
// sourceEvent object is cacheObject,all watcher use the same point,must deepcopy.
copyEvent = *sourceEvent.DeepCopy()
if decorator != nil { if decorator != nil {
decorator(event) decorator(copyEvent)
} }
case <-w.done: case <-w.done:
return return
@ -241,7 +242,7 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
case <-w.done: case <-w.done:
return return
default: default:
w.result <- event w.result <- copyEvent
} }
}() }()
} }