Skip to content

Commit 7afb8d6

Browse files
Merge pull request #392 from HeavyHorst/master
fixed broken etcd watch support
2 parents 9bb4aa7 + 7f05488 commit 7afb8d6

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

backends/etcd/client.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,15 @@ func (c *Client) WatchPrefix(prefix string, waitIndex uint64, stopChan chan bool
119119
prefix = "/"
120120
}
121121

122+
// return something > 0 to trigger a key retrieval from the store
122123
if waitIndex == 0 {
123-
resp, err := c.client.Get(context.Background(), prefix, &client.GetOptions{
124-
Recursive: true,
125-
Sort: false,
126-
Quorum: true,
127-
})
128-
if err != nil {
129-
return 0, err
130-
}
131-
return resp.Index, nil
124+
return 1, nil
132125
}
133126

134-
watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: waitIndex, Recursive: true})
127+
// Setting AfterIndex to 0 (default) means that the Watcher
128+
// should start watching for events starting at the current
129+
// index, whatever that may be.
130+
watcher := c.client.Watcher(prefix, &client.WatcherOptions{AfterIndex: uint64(0), Recursive: true})
135131
ctx, cancel := context.WithCancel(context.Background())
136132
cancelRoutine := make(chan bool)
137133
defer close(cancelRoutine)

resource/template/processor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ func IntervalProcessor(config Config, stopChan, doneChan chan bool, errChan chan
4646
func (p *intervalProcessor) Process() {
4747
defer close(p.doneChan)
4848
for {
49-
ts, err := getTemplateResources(p.config)
50-
if err != nil {
51-
log.Fatal(err.Error())
52-
break
53-
}
49+
ts, err := getTemplateResources(p.config)
50+
if err != nil {
51+
log.Fatal(err.Error())
52+
break
53+
}
5454
process(ts)
5555
select {
5656
case <-p.stopChan:

0 commit comments

Comments
 (0)