From 212f5305a88cc02827d8cd0d1f8a4175173c6274 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Thu, 25 Sep 2014 11:42:58 -0700 Subject: [PATCH] Fix type cast problems now that watch can pass errors --- pkg/registry/controller/rest.go | 8 +++++++- pkg/registry/etcd/etcd.go | 11 ++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/registry/controller/rest.go b/pkg/registry/controller/rest.go index cfd39bcbcf7..bc3fb05dc5c 100644 --- a/pkg/registry/controller/rest.go +++ b/pkg/registry/controller/rest.go @@ -150,8 +150,14 @@ func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (wat if err != nil { return nil, err } + // TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering. + // TODO(lavalamp): this watch method needs a test. return watch.Filter(incoming, func(e watch.Event) (watch.Event, bool) { - repController := e.Object.(*api.ReplicationController) + repController, ok := e.Object.(*api.ReplicationController) + if !ok { + // must be an error event-- pass it on + return e, true + } match := label.Matches(labels.Set(repController.Labels)) if match { rs.fillCurrentState(repController) diff --git a/pkg/registry/etcd/etcd.go b/pkg/registry/etcd/etcd.go index 58839a46f7a..e1a184fc374 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -85,12 +85,13 @@ func (r *Registry) ListPodsPredicate(filter func(*api.Pod) bool) (*api.PodList, // WatchPods begins watching for new, changed, or deleted pods. func (r *Registry) WatchPods(resourceVersion uint64, filter func(*api.Pod) bool) (watch.Interface, error) { return r.WatchList("/registry/pods", resourceVersion, func(obj runtime.Object) bool { - pod, ok := obj.(*api.Pod) - if !ok { - glog.Errorf("Unexpected object during pod watch: %#v", obj) - return false + switch t := obj.(type) { + case *api.Pod: + return filter(t) + default: + // Must be an error + return true } - return filter(pod) }) }