Fix type cast problems now that watch can pass errors

This commit is contained in:
Daniel Smith 2014-09-25 11:42:58 -07:00
parent a981ae5480
commit 212f5305a8
2 changed files with 13 additions and 6 deletions

View File

@ -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)

View File

@ -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)
})
}