From e76dcbdfa26e5fb28c721b8ad7948c67a3ef657e Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Wed, 11 Feb 2015 11:42:21 -0500 Subject: [PATCH] Add ability to watch namespaces --- pkg/client/fake_namespaces.go | 6 ++++++ pkg/client/namespaces.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/client/fake_namespaces.go b/pkg/client/fake_namespaces.go index 7e7f7ff086d..09c18228837 100644 --- a/pkg/client/fake_namespaces.go +++ b/pkg/client/fake_namespaces.go @@ -19,6 +19,7 @@ package client import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) // FakeNamespaces implements NamespacesInterface. Meant to be embedded into a struct to get a default @@ -51,3 +52,8 @@ func (c *FakeNamespaces) Update(namespace *api.Namespace) (*api.Namespace, error c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "update-namespace", Value: namespace.Name}) return &api.Namespace{}, nil } + +func (c *FakeNamespaces) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { + c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-namespaces", Value: resourceVersion}) + return c.Fake.Watch, nil +} diff --git a/pkg/client/namespaces.go b/pkg/client/namespaces.go index 2611761c5ee..4bbdc76ec07 100644 --- a/pkg/client/namespaces.go +++ b/pkg/client/namespaces.go @@ -22,6 +22,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) type NamespacesInterface interface { @@ -34,6 +35,7 @@ type NamespaceInterface interface { List(selector labels.Selector) (*api.NamespaceList, error) Delete(name string) error Update(item *api.Namespace) (*api.Namespace, error) + Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) } // namespaces implements NamespacesInterface @@ -86,3 +88,14 @@ func (c *namespaces) Get(name string) (*api.Namespace, error) { func (c *namespaces) Delete(name string) error { return c.r.Delete().Resource("namespaces").Name(name).Do().Error() } + +// Watch returns a watch.Interface that watches the requested namespaces. +func (c *namespaces) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) { + return c.r.Get(). + Prefix("watch"). + Resource("namespaces"). + Param("resourceVersion", resourceVersion). + SelectorParam("labels", label). + SelectorParam("fields", field). + Watch() +}