Skip to content

Commit cab8dd1

Browse files
committed
Re-implement gvkFixupWatcher as a watch.FilterFunc
Signed-off-by: Richard Wall <[email protected]>
1 parent 1999e97 commit cab8dd1

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

pkg/cache/internal/informers_map.go

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -409,41 +409,15 @@ func createMetadataListWatch(gvk schema.GroupVersionKind, ip *specificInformersM
409409
}, nil
410410
}
411411

412-
type gvkFixupWatcher struct {
413-
watcher watch.Interface
414-
ch chan watch.Event
415-
gvk schema.GroupVersionKind
416-
wg sync.WaitGroup
417-
}
418-
419412
func newGVKFixupWatcher(gvk schema.GroupVersionKind, watcher watch.Interface) watch.Interface {
420-
ch := make(chan watch.Event)
421-
w := &gvkFixupWatcher{
422-
gvk: gvk,
423-
watcher: watcher,
424-
ch: ch,
425-
}
426-
w.wg.Add(1)
427-
go w.run()
428-
return w
429-
}
430-
431-
func (w *gvkFixupWatcher) run() {
432-
for e := range w.watcher.ResultChan() {
433-
e.Object.GetObjectKind().SetGroupVersionKind(w.gvk)
434-
w.ch <- e
435-
}
436-
w.wg.Done()
437-
}
438-
439-
func (w *gvkFixupWatcher) Stop() {
440-
w.watcher.Stop()
441-
w.wg.Wait()
442-
close(w.ch)
443-
}
444-
445-
func (w *gvkFixupWatcher) ResultChan() <-chan watch.Event {
446-
return w.ch
413+
return watch.Filter(
414+
watcher,
415+
func(in watch.Event) (out watch.Event, keep bool) {
416+
in.DeepCopyInto(&out)
417+
out.Object.GetObjectKind().SetGroupVersionKind(gvk)
418+
return out, true
419+
},
420+
)
447421
}
448422

449423
// resyncPeriod returns a function which generates a duration each time it is

0 commit comments

Comments
 (0)