From 1a1b6f131514a4fe68d7b5376b6130c4d886011e Mon Sep 17 00:00:00 2001 From: huangxuesen Date: Wed, 11 Nov 2020 21:09:20 +0800 Subject: [PATCH] subnets: move forward the cursor to skip illegal subnet This PR fixs an issue when flannel gets illegal subnet event in watching leases, it doesn't move forward the etcd cursor and will stuck in the same invalid event forever. --- subnet/etcdv2/local_manager.go | 3 +++ subnet/watch.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/subnet/etcdv2/local_manager.go b/subnet/etcdv2/local_manager.go index 3fa50b9c5b..f1ff4ce650 100644 --- a/subnet/etcdv2/local_manager.go +++ b/subnet/etcdv2/local_manager.go @@ -345,6 +345,9 @@ func (m *LocalManager) WatchLeases(ctx context.Context, cursor interface{}) (Lea log.Warning("Watch of subnet leases failed because etcd index outside history window") return m.leasesWatchReset(ctx) + case index != 0: + return LeaseWatchResult{Cursor: watchCursor{index}}, err + default: return LeaseWatchResult{}, err } diff --git a/subnet/watch.go b/subnet/watch.go index 46f52e51f5..5704ec181a 100644 --- a/subnet/watch.go +++ b/subnet/watch.go @@ -40,6 +40,10 @@ func WatchLeases(ctx context.Context, sm Manager, ownLease *Lease, receiver chan return } + if res.Cursor != nil { + cursor = res.Cursor + } + log.Errorf("Watch subnets: %v", err) time.Sleep(time.Second) continue