mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Add RegisterFakeOnDelete to test federation object deletion
This commit is contained in:
parent
80ceb5b3d6
commit
be0d7f0aeb
@ -288,6 +288,32 @@ func RegisterFakeCopyOnUpdate(resource string, client *core.Fake, watcher *Watch
|
||||
return objChan
|
||||
}
|
||||
|
||||
// RegisterFakeOnDelete registers a reactor in the given fake client that passes
|
||||
// all deleted objects to the given watcher. Since we could get only name of the
|
||||
// deleted object from DeleteAction, this register function relies on the getObject
|
||||
// function passed to get the object by name and pass it watcher.
|
||||
func RegisterFakeOnDelete(resource string, client *core.Fake, watcher *WatcherDispatcher, getObject func(name, namespace string) runtime.Object) {
|
||||
client.AddReactor("delete", resource, func(action core.Action) (bool, runtime.Object, error) {
|
||||
deleteAction := action.(core.DeleteAction)
|
||||
obj := getObject(deleteAction.GetName(), deleteAction.GetNamespace())
|
||||
glog.V(7).Infof("Deleting %s: %v", resource, obj)
|
||||
|
||||
operation := func() {
|
||||
glog.V(4).Infof("Object deleted %v", obj)
|
||||
watcher.Delete(obj)
|
||||
}
|
||||
select {
|
||||
case watcher.orderExecution <- operation:
|
||||
break
|
||||
case <-time.After(pushTimeout):
|
||||
glog.Errorf("Fake client execution channel blocked")
|
||||
glog.Errorf("Tried to push %v", deleteAction)
|
||||
}
|
||||
return true, obj, nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Adds an update reactor to the given fake client.
|
||||
// The reactor just returns the object passed to update action.
|
||||
// This is used as a hack to workaround https://github.com/kubernetes/kubernetes/issues/40939.
|
||||
|
Loading…
Reference in New Issue
Block a user