Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Send Possibly Stale Object on Broken WatchConn to Keep Meshery in Sync #102

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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