Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to watch namespaces from client #4313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/client/fake_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions pkg/client/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
10 changes: 10 additions & 0 deletions pkg/client/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package client

import (
"net/url"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -132,3 +133,12 @@ func TestNamespaceDelete(t *testing.T) {
err := c.Setup().Namespaces().Delete("foo")
c.Validate(t, nil, err)
}

func TestNamespaceWatch(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "GET", Path: "/watch/namespaces", Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200},
}
_, err := c.Setup().Namespaces().Watch(labels.Everything(), labels.Everything(), "")
c.Validate(t, nil, err)
}