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:
commit
b273800421
|
@ -315,7 +315,6 @@ func (c *MultiClusterCache) Watch(ctx context.Context, gvr schema.GroupVersionRe
|
|||
}
|
||||
|
||||
mux.AddSource(w, func(e watch.Event) {
|
||||
// We can safely modify data because it is deepCopied in cacheWatcher.convertToWatchEvent
|
||||
setObjectResourceVersionFunc(cluster, e.Object)
|
||||
addCacheSourceAnnotation(e.Object, cluster)
|
||||
})
|
||||
|
|
|
@ -214,15 +214,16 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
|
|||
defer source.Stop()
|
||||
defer w.Stop()
|
||||
for {
|
||||
var event watch.Event
|
||||
var ok bool
|
||||
var copyEvent watch.Event
|
||||
select {
|
||||
case event, ok = <-source.ResultChan():
|
||||
case sourceEvent, ok := <-source.ResultChan():
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// sourceEvent object is cacheObject,all watcher use the same point,must deepcopy.
|
||||
copyEvent = *sourceEvent.DeepCopy()
|
||||
if decorator != nil {
|
||||
decorator(event)
|
||||
decorator(copyEvent)
|
||||
}
|
||||
case <-w.done:
|
||||
return
|
||||
|
@ -241,7 +242,7 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
|
|||
case <-w.done:
|
||||
return
|
||||
default:
|
||||
w.result <- event
|
||||
w.result <- copyEvent
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue