Skip to content

Commit

Permalink
Merge pull request #102 from meshery/nithish/fix/fallback_on_watchErr
Browse files Browse the repository at this point in the history
Fix: Send Possibly Stale Object on Broken WatchConn to Keep Meshery in Sync
  • Loading branch information
leecalcote authored Jan 17, 2022
2 parents f176bbe + 95bea23 commit 1c9ac67
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/pipeline/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ func (c *ResourceWatcher) startWatching(s cache.SharedIndexInformer) {
}
},
DeleteFunc: func(obj interface{}) {
// It is not guaranteed that this will always be unstructured
// to avoid panicking check if it is truly unstructured
objCasted, ok := obj.(*unstructured.Unstructured)
// the obj can only be of two types, Unstructured or DeletedFinalStateUnknown.
// DeletedFinalStateUnknown means that the object that we receive may be `stale`
// because of the way informer behaves

// refer 'https://pkg.go.dev/k8s.io/client-go/tools/cache#ResourceEventHandler.OnDelete'

var objCasted *unstructured.Unstructured
objCasted = obj.(*unstructured.Unstructured)

possiblyStaleObj, ok := obj.(cache.DeletedFinalStateUnknown)
if ok {
c.log.Info("received delete event for:", objCasted.GetName())
c.publishItem(objCasted, broker.Delete)
objCasted = possiblyStaleObj.Obj.(*unstructured.Unstructured)
}
c.log.Info("received delete event for:", objCasted.GetName())
c.publishItem(objCasted, broker.Delete)
},
}
s.AddEventHandler(handlers)
Expand Down

0 comments on commit 1c9ac67

Please sign in to comment.