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) {
|
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)
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue