Skip to content

Commit

Permalink
Merge pull request kubernetes#5493 from sdminonne/issue_341_step_2
Browse files Browse the repository at this point in the history
Another step to introduce  fields.Selector
  • Loading branch information
nikhiljindal committed Mar 17, 2015
2 parents 3e84c26 + 31ddefc commit 89f18f6
Show file tree
Hide file tree
Showing 42 changed files with 161 additions and 114 deletions.
5 changes: 3 additions & 2 deletions cluster/addons/dns/kube2sky/kube2sky.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
kfields "github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
klabels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
tools "github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
kwatch "github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
Expand Down Expand Up @@ -194,7 +195,7 @@ func main() {
// across ALL namespaces
type servicesWatcher interface {
List(label klabels.Selector) (*kapi.ServiceList, error)
Watch(label, field klabels.Selector, resourceVersion string) (kwatch.Interface, error)
Watch(label klabels.Selector, field kfields.Selector, resourceVersion string) (kwatch.Interface, error)
}

type operation int
Expand Down Expand Up @@ -239,7 +240,7 @@ func watchLoop(svcWatcher servicesWatcher, updates chan<- serviceUpdate, resourc
updates <- serviceUpdate{Op: SetServices, Services: services.Items}
}

watcher, err := svcWatcher.Watch(klabels.Everything(), klabels.Everything(), *resourceVersion)
watcher, err := svcWatcher.Watch(klabels.Everything(), kfields.Everything(), *resourceVersion)
if err != nil {
log.Printf("Failed to watch for service changes: %v", err)
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/cache/listwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package cache
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand All @@ -39,12 +39,12 @@ type ListWatch struct {
}

// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector labels.Selector) *ListWatch {
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
listFunc := func() (runtime.Object, error) {
return c.Get().Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
return c.Get().Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
}
watchFunc := func(resourceVersion string) (watch.Interface, error) {
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
}
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/client/cache/listwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

func parseSelectorOrDie(s string) labels.Selector {
selector, err := labels.Parse(s)
func parseSelectorOrDie(s string) fields.Selector {
selector, err := fields.ParseSelector(s)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestListWatchesCanList(t *testing.T) {
location string
resource string
namespace string
fieldSelector labels.Selector
fieldSelector fields.Selector
}{
// Minion
{
Expand All @@ -96,14 +96,14 @@ func TestListWatchesCanList(t *testing.T) {
location: buildLocation(buildResourcePath("", api.NamespaceAll, "pods"), buildQueryValues(api.NamespaceAll, url.Values{"fields": []string{getHostFieldLabel() + "="}})),
resource: "pods",
namespace: api.NamespaceAll,
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
},
// pod in namespace "foo"
{
location: buildLocation(buildResourcePath("", "foo", "pods"), buildQueryValues("foo", url.Values{"fields": []string{getHostFieldLabel() + "="}})),
resource: "pods",
namespace: "foo",
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
},
}
for _, item := range table {
Expand All @@ -128,7 +128,7 @@ func TestListWatchesCanWatch(t *testing.T) {
location string
resource string
namespace string
fieldSelector labels.Selector
fieldSelector fields.Selector
}{
// Minion
{
Expand All @@ -151,15 +151,15 @@ func TestListWatchesCanWatch(t *testing.T) {
rv: "0",
resource: "pods",
namespace: api.NamespaceAll,
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
},
// pod with namespace foo and assigned field selector
{
location: buildLocation(buildResourcePath("watch", "foo", "pods"), buildQueryValues("foo", url.Values{"fields": []string{getHostFieldLabel() + "="}, "resourceVersion": []string{"0"}})),
rv: "0",
resource: "pods",
namespace: "foo",
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
},
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
Expand Down Expand Up @@ -241,8 +242,8 @@ func validateLabels(a, b string) bool {
}

func validateFields(a, b string) bool {
sA, _ := labels.ParseSelector(a)
sB, _ := labels.ParseSelector(b)
sA, _ := fields.ParseSelector(a)
sB, _ := fields.ParseSelector(b)
return sA.String() == sB.String()
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/client/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand All @@ -36,7 +37,7 @@ type EndpointsInterface interface {
List(selector labels.Selector) (*api.EndpointsList, error)
Get(name string) (*api.Endpoints, error)
Update(endpoints *api.Endpoints) (*api.Endpoints, error)
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}

// endpoints implements EndpointsInterface
Expand All @@ -63,7 +64,7 @@ func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, e
err = c.r.Get().
Namespace(c.ns).
Resource("endpoints").
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
Do().
Into(result)
return
Expand All @@ -81,14 +82,14 @@ func (c *endpoints) Get(name string) (result *api.Endpoints, err error) {
}

// Watch returns a watch.Interface that watches the requested endpoints for a service.
func (c *endpoints) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *endpoints) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("endpoints").
Param("resourceVersion", resourceVersion).
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
Watch()
}

Expand Down
19 changes: 10 additions & 9 deletions pkg/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
Expand All @@ -35,9 +36,9 @@ type EventNamespacer interface {
type EventInterface interface {
Create(event *api.Event) (*api.Event, error)
Update(event *api.Event) (*api.Event, error)
List(label, field labels.Selector) (*api.EventList, error)
List(label labels.Selector, field fields.Selector) (*api.EventList, error)
Get(name string) (*api.Event, error)
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
// Search finds events about the specified object
Search(objOrRef runtime.Object) (*api.EventList, error)
Delete(name string) error
Expand Down Expand Up @@ -96,13 +97,13 @@ func (e *events) Update(event *api.Event) (*api.Event, error) {
}

// List returns a list of events matching the selectors.
func (e *events) List(label, field labels.Selector) (*api.EventList, error) {
func (e *events) List(label labels.Selector, field fields.Selector) (*api.EventList, error) {
result := &api.EventList{}
err := e.client.Get().
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
Resource("events").
SelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
SelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
Do().
Into(result)
return result, err
Expand All @@ -125,14 +126,14 @@ func (e *events) Get(name string) (*api.Event, error) {
}

// Watch starts watching for events matching the given selectors.
func (e *events) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (e *events) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return e.client.Get().
Prefix("watch").
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
Resource("events").
Param("resourceVersion", resourceVersion).
SelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
SelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
Watch()
}

Expand All @@ -147,7 +148,7 @@ func (e *events) Search(objOrRef runtime.Object) (*api.EventList, error) {
if e.namespace != "" && ref.Namespace != e.namespace {
return nil, fmt.Errorf("won't be able to find any events of namespace '%v' in namespace '%v'", ref.Namespace, e.namespace)
}
fields := labels.Set{}
fields := fields.Set{}
if ref.Kind != "" {
fields["involvedObject.kind"] = ref.Kind
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestEventList(t *testing.T) {
Response: Response{StatusCode: 200, Body: eventList},
}
response, err := c.Setup().Events(ns).List(labels.Everything(),
labels.Everything())
fields.Everything())

if err != nil {
t.Errorf("%#v should be nil.", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/fake_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand All @@ -44,7 +45,7 @@ func (c *FakeEndpoints) Get(name string) (*api.Endpoints, error) {
return &api.Endpoints{}, nil
}

func (c *FakeEndpoints) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeEndpoints) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-endpoints", Value: resourceVersion})
return c.Fake.Watch, c.Fake.Err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/fake_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
Expand All @@ -42,7 +43,7 @@ func (c *FakeEvents) Update(event *api.Event) (*api.Event, error) {
}

// List returns a list of events matching the selectors.
func (c *FakeEvents) List(label, field labels.Selector) (*api.EventList, error) {
func (c *FakeEvents) List(label labels.Selector, field fields.Selector) (*api.EventList, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "list-events"})
return &c.Fake.EventsList, nil
}
Expand All @@ -54,7 +55,7 @@ func (c *FakeEvents) Get(id string) (*api.Event, error) {
}

// Watch starts watching for events matching the given selectors.
func (c *FakeEvents) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeEvents) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-events", Value: resourceVersion})
return c.Fake.Watch, c.Fake.Err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/fake_limit_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (c *FakeLimitRanges) Update(limitRange *api.LimitRange) (*api.LimitRange, e
return &api.LimitRange{}, nil
}

func (c *FakeLimitRanges) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeLimitRanges) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-limitRange", Value: resourceVersion})
return c.Fake.Watch, nil
}
3 changes: 2 additions & 1 deletion pkg/client/fake_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (c *FakeNamespaces) Update(namespace *api.Namespace) (*api.Namespace, error
return &api.Namespace{}, nil
}

func (c *FakeNamespaces) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeNamespaces) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-namespaces", Value: resourceVersion})
return c.Fake.Watch, nil
}
3 changes: 2 additions & 1 deletion pkg/client/fake_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (c *FakePods) Update(pod *api.Pod) (*api.Pod, error) {
return &api.Pod{}, nil
}

func (c *FakePods) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakePods) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-pods", Value: resourceVersion})
return c.Fake.Watch, c.Fake.Err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/fake_replication_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (c *FakeReplicationControllers) Delete(controller string) error {
return nil
}

func (c *FakeReplicationControllers) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeReplicationControllers) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-controllers", Value: resourceVersion})
return c.Fake.Watch, nil
}
3 changes: 2 additions & 1 deletion pkg/client/fake_resource_quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ func (c *FakeResourceQuotas) Status(resourceQuota *api.ResourceQuota) (*api.Reso
return &api.ResourceQuota{}, nil
}

func (c *FakeResourceQuotas) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (c *FakeResourceQuotas) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-resourceQuota", Value: resourceVersion})
return c.Fake.Watch, nil
}
Loading

0 comments on commit 89f18f6

Please sign in to comment.