diff --git a/backends/etcd/client.go b/backends/etcd/client.go index 0a9879dcc..38d4836fc 100644 --- a/backends/etcd/client.go +++ b/backends/etcd/client.go @@ -119,19 +119,15 @@ func (c *Client) WatchPrefix(prefix string, waitIndex uint64, stopChan chan bool prefix = "/" } + // return something > 0 to trigger a key retrieval from the store if waitIndex == 0 { - resp, err := c.client.Get(context.Background(), prefix, &client.GetOptions{ - Recursive: true, - Sort: false, - Quorum: true, - }) - if err != nil { - return 0, err - } - return resp.Index, nil + return 1, nil } - watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: waitIndex, Recursive: true}) + // Setting AfterIndex to 0 (default) means that the Watcher + // should start watching for events starting at the current + // index, whatever that may be. + watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: uint64(0), Recursive: true}) ctx, cancel := context.WithCancel(context.Background()) cancelRoutine := make(chan bool) defer close(cancelRoutine) diff --git a/resource/template/processor.go b/resource/template/processor.go index 0ba664511..70dd1a127 100644 --- a/resource/template/processor.go +++ b/resource/template/processor.go @@ -46,11 +46,11 @@ func IntervalProcessor(config Config, stopChan, doneChan chan bool, errChan chan func (p *intervalProcessor) Process() { defer close(p.doneChan) for { - ts, err := getTemplateResources(p.config) - if err != nil { - log.Fatal(err.Error()) - break - } + ts, err := getTemplateResources(p.config) + if err != nil { + log.Fatal(err.Error()) + break + } process(ts) select { case <-p.stopChan: