Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
> fix resource gone if server disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
kebe7jun committed Apr 15, 2022
1 parent d105523 commit 09e9b3e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) {
} else {
url = fmt.Sprintf("/apis/%s/%s/%s?watch=true", r.Group, r.Version, r.Resource)
}
first := true
ww, err := rt.Get().RequestURI(url).Timeout(time.Hour).Watch(ctx)
if err != nil {
log.Errorf("cluster(%s): create watcher for %s error: %v", cluster, url, err)
Expand All @@ -151,6 +152,12 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) {
for {
select {
case rr, open := <-ww.ResultChan():
if first {
// only clean resource at the first time
// to avoid the resources gone after server break.
w.store.Clean(r, cluster)
first = false
}
if open {
switch rr.Type {
case watch.Added:
Expand All @@ -163,7 +170,6 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) {
log.Warnf("cluster(%s): watch stream(%v) error: %v", cluster, r, rr.Object)
}
} else {
w.store.Clean(r, cluster)
log.Warnf("cluster(%s): watch stream(%v) closed", cluster, r)
ww.Stop()
time.Sleep(time.Second * 3)
Expand Down

0 comments on commit 09e9b3e

Please sign in to comment.