Remove unnecessary loop

This commit is contained in:
Ilya Galimyanov 2018-08-23 10:40:03 +03:00 committed by Traefiker Bot
parent e4a7375d34
commit 0861c59bec

View file

@ -122,40 +122,36 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
pool.Go(func(stop chan bool) { pool.Go(func(stop chan bool) {
operation := func() error { operation := func() error {
for { stopWatch := make(chan struct{}, 1)
stopWatch := make(chan struct{}, 1) defer close(stopWatch)
defer close(stopWatch) eventsChan, err := k8sClient.WatchAll(p.Namespaces, stopWatch)
eventsChan, err := k8sClient.WatchAll(p.Namespaces, stopWatch) if err != nil {
if err != nil { log.Errorf("Error watching kubernetes events: %v", err)
log.Errorf("Error watching kubernetes events: %v", err) timer := time.NewTimer(1 * time.Second)
timer := time.NewTimer(1 * time.Second) select {
select { case <-timer.C:
case <-timer.C: return err
return err case <-stop:
case <-stop: return nil
return nil
}
} }
for { }
select { for {
case <-stop: select {
return nil case <-stop:
case event := <-eventsChan: return nil
log.Debugf("Received Kubernetes event kind %T", event) case event := <-eventsChan:
log.Debugf("Received Kubernetes event kind %T", event)
templateObjects, err := p.loadIngresses(k8sClient) templateObjects, err := p.loadIngresses(k8sClient)
if err != nil { if err != nil {
return err return err
} }
if reflect.DeepEqual(p.lastConfiguration.Get(), templateObjects) {
if reflect.DeepEqual(p.lastConfiguration.Get(), templateObjects) { log.Debugf("Skipping Kubernetes event kind %T", event)
log.Debugf("Skipping Kubernetes event kind %T", event) } else {
} else { p.lastConfiguration.Set(templateObjects)
p.lastConfiguration.Set(templateObjects) configurationChan <- types.ConfigMessage{
configurationChan <- types.ConfigMessage{ ProviderName: "kubernetes",
ProviderName: "kubernetes", Configuration: p.loadConfig(*templateObjects),
Configuration: p.loadConfig(*templateObjects),
}
} }
} }
} }