cache: add error handling to informers

When creating an informer, this adds a way to add custom error handling, so that
Kubernetes tooling can properly surface the errors to the end user.

Fixes https://github.com/kubernetes/client-go/issues/155

Kubernetes-commit: 435b40aa1e5c0ae44e0aeb9aa6dbde79838b3390
This commit is contained in:
Nick Santos
2020-01-17 12:46:08 -05:00
committed by Kubernetes Publisher
parent 8e91b7aa91
commit ccd5becdff
5 changed files with 114 additions and 23 deletions

View File

@@ -62,6 +62,9 @@ type FakeControllerSource struct {
changes []watch.Event // one change per resourceVersion
Broadcaster *watch.Broadcaster
lastRV int
// Set this to simulate an error on List()
ListError error
}
type FakePVControllerSource struct {
@@ -174,6 +177,11 @@ func (f *FakeControllerSource) getListItemsLocked() ([]runtime.Object, error) {
func (f *FakeControllerSource) List(options metav1.ListOptions) (runtime.Object, error) {
f.lock.RLock()
defer f.lock.RUnlock()
if f.ListError != nil {
return nil, f.ListError
}
list, err := f.getListItemsLocked()
if err != nil {
return nil, err