mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-19 01:27:10 +00:00
Refactor Start functions into an object
Kubernetes-commit: 6464774a9b94f6e8376e11d015fd55e98457e74c
This commit is contained in:
parent
0a8adc4df4
commit
1a0ee4cda2
4
tools/cache/controller.go
vendored
4
tools/cache/controller.go
vendored
@ -116,10 +116,10 @@ func (c *controller) Run(stopCh <-chan struct{}) {
|
|||||||
c.reflector = r
|
c.reflector = r
|
||||||
c.reflectorMutex.Unlock()
|
c.reflectorMutex.Unlock()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg wait.Group
|
||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
|
|
||||||
wait.StartWithChannelWithinGroup(stopCh, &wg, r.Run)
|
wg.StartWithChannel(stopCh, r.Run)
|
||||||
|
|
||||||
wait.Until(c.processLoop, time.Second, stopCh)
|
wait.Until(c.processLoop, time.Second, stopCh)
|
||||||
}
|
}
|
||||||
|
16
tools/cache/shared_informer.go
vendored
16
tools/cache/shared_informer.go
vendored
@ -147,7 +147,7 @@ type sharedIndexInformer struct {
|
|||||||
// stopCh is the channel used to stop the main Run process. We have to track it so that
|
// stopCh is the channel used to stop the main Run process. We have to track it so that
|
||||||
// late joiners can have a proper stop
|
// late joiners can have a proper stop
|
||||||
stopCh <-chan struct{}
|
stopCh <-chan struct{}
|
||||||
wg sync.WaitGroup
|
wg wait.Group
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummyController hides the fact that a SharedInformer is different from a dedicated one
|
// dummyController hides the fact that a SharedInformer is different from a dedicated one
|
||||||
@ -211,8 +211,8 @@ func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
|
|||||||
|
|
||||||
defer s.wg.Wait()
|
defer s.wg.Wait()
|
||||||
|
|
||||||
wait.StartWithChannelWithinGroup(stopCh, &s.wg, s.cacheMutationDetector.Run)
|
s.wg.StartWithChannel(stopCh, s.cacheMutationDetector.Run)
|
||||||
wait.StartWithChannelWithinGroup(stopCh, &s.wg, s.processor.run)
|
s.wg.StartWithChannel(stopCh, s.processor.run)
|
||||||
s.controller.Run(stopCh)
|
s.controller.Run(stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,8 +327,8 @@ func (s *sharedIndexInformer) AddEventHandlerWithResyncPeriod(handler ResourceEv
|
|||||||
|
|
||||||
s.processor.addListener(listener)
|
s.processor.addListener(listener)
|
||||||
|
|
||||||
wait.StartWithChannelWithinGroup(s.stopCh, &s.wg, listener.run)
|
s.wg.StartWithChannel(s.stopCh, listener.run)
|
||||||
wait.StartWithChannelWithinGroup(s.stopCh, &s.wg, listener.pop)
|
s.wg.StartWithChannel(s.stopCh, listener.pop)
|
||||||
|
|
||||||
items := s.indexer.List()
|
items := s.indexer.List()
|
||||||
for i := range items {
|
for i := range items {
|
||||||
@ -398,13 +398,13 @@ func (p *sharedProcessor) distribute(obj interface{}, sync bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *sharedProcessor) run(stopCh <-chan struct{}) {
|
func (p *sharedProcessor) run(stopCh <-chan struct{}) {
|
||||||
var wg sync.WaitGroup
|
var wg wait.Group
|
||||||
func() {
|
func() {
|
||||||
p.listenersLock.RLock()
|
p.listenersLock.RLock()
|
||||||
defer p.listenersLock.RUnlock()
|
defer p.listenersLock.RUnlock()
|
||||||
for _, listener := range p.listeners {
|
for _, listener := range p.listeners {
|
||||||
wait.StartWithChannelWithinGroup(stopCh, &wg, listener.run)
|
wg.StartWithChannel(stopCh, listener.run)
|
||||||
wait.StartWithChannelWithinGroup(stopCh, &wg, listener.pop)
|
wg.StartWithChannel(stopCh, listener.pop)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user