Skip to content

Commit

Permalink
Fix List() calls that didn't fill in revision
Browse files Browse the repository at this point in the history
The watchercache requires the KVList to contain the revision
for correctness.  Without it, it can miss updates from the server.

Fix the resources that were missing the revision and panic if the
revision is missing to surface the problem in future.
  • Loading branch information
fasaxc committed Dec 13, 2024
1 parent 78451e9 commit 27fb6ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion libcalico-go/lib/backend/k8s/resources/ipam_affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ func (c *blockAffinityClient) listV1(ctx context.Context, list model.BlockAffini
affinityType := list.AffinityType
requestedIPVersion := list.IPVersion

kvpl := &model.KVPairList{KVPairs: []*model.KVPair{}}
kvpl := &model.KVPairList{
KVPairs: []*model.KVPair{},
Revision: v3list.Revision,
}
for _, i := range v3list.KVPairs {
v1kvp, err := c.toV1(i)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion libcalico-go/lib/backend/k8s/resources/ipam_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func (c *ipamBlockClient) List(ctx context.Context, list model.ListInterface, re
return nil, err
}

kvpl := &model.KVPairList{KVPairs: []*model.KVPair{}}
kvpl := &model.KVPairList{
KVPairs: []*model.KVPair{},
Revision: v3list.Revision,
}
for _, i := range v3list.KVPairs {
v1kvp, err := IPAMBlockV3toV1(i)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions libcalico-go/lib/backend/watchersyncer/watchercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func (wc *watcherCache) resyncAndCreateWatcher(ctx context.Context) {
wc.finishResync()

// Store the current watch revision. This gets updated on any new add/modified event.
wc.logger.Logger.WithField("revision", l.Revision).Debug("List completed.")
if l.Revision == "" || l.Revision == "0" {
wc.logger.Panic("BUG: List returned empty/zero revision. Watch would be inconsistent.")
}
wc.currentWatchRevision = l.Revision

// Mark the resync as complete.
Expand Down

0 comments on commit 27fb6ea

Please sign in to comment.