Adding fields selector

This commit is contained in:
Salvatore Dario Minonne
2015-03-07 00:29:03 +01:00
parent 9aa744925e
commit 925fa6baf8
46 changed files with 725 additions and 116 deletions

View File

@@ -24,6 +24,7 @@ import (
etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/constraint"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
@@ -55,7 +56,7 @@ func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingRE
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Pod).Name, nil
},
PredicateFunc: func(label, field labels.Selector) generic.Matcher {
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return pod.MatchPod(label, field)
},
EndpointName: "pods",
@@ -96,12 +97,12 @@ func (r *REST) NewList() runtime.Object {
}
// List obtains a list of pods with labels that match selector.
func (r *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
func (r *REST) List(ctx api.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
return r.store.List(ctx, label, field)
}
// Watch begins watching for new, changed, or deleted pods.
func (r *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (r *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return r.store.Watch(ctx, label, field, resourceVersion)
}

View File

@@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -179,7 +180,7 @@ func TestListError(t *testing.T) {
storage, _, _ := NewREST(helper, nil)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), labels.Everything())
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != fakeEtcdClient.Err {
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
}
@@ -208,7 +209,7 @@ func TestListCacheError(t *testing.T) {
cache := &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable}
storage = storage.WithPodStatus(cache)
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), labels.Everything())
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("Expected no error, got %#v", err)
}
@@ -232,7 +233,7 @@ func TestListEmptyPodList(t *testing.T) {
storage, _, _ := NewREST(helper, nil)
cache := &fakeCache{}
storage = storage.WithPodStatus(cache)
pods, err := storage.List(api.NewContext(), labels.Everything(), labels.Everything())
pods, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -271,7 +272,7 @@ func TestListPodList(t *testing.T) {
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
storage = storage.WithPodStatus(cache)
podsObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), labels.Everything())
podsObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
pods := podsObj.(*api.PodList)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -357,7 +358,7 @@ func TestListPodListSelection(t *testing.T) {
t.Errorf("unexpected error: %v", err)
continue
}
field, err := labels.ParseSelector(item.field)
field, err := fields.ParseSelector(item.field)
if err != nil {
t.Errorf("unexpected error: %v", err)
continue
@@ -1451,7 +1452,7 @@ func TestEtcdEmptyList(t *testing.T) {
E: nil,
}
obj, err := registry.List(ctx, labels.Everything(), labels.Everything())
obj, err := registry.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -1469,7 +1470,7 @@ func TestEtcdListNotFound(t *testing.T) {
R: &etcd.Response{},
E: tools.EtcdErrorNotFound,
}
obj, err := registry.List(ctx, labels.Everything(), labels.Everything())
obj, err := registry.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -1504,7 +1505,7 @@ func TestEtcdList(t *testing.T) {
},
E: nil,
}
obj, err := registry.List(ctx, labels.Everything(), labels.Everything())
obj, err := registry.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -1524,7 +1525,7 @@ func TestEtcdWatchPods(t *testing.T) {
ctx := api.NewDefaultContext()
watching, err := registry.Watch(ctx,
labels.Everything(),
labels.Everything(),
fields.Everything(),
"1",
)
if err != nil {
@@ -1551,7 +1552,7 @@ func TestEtcdWatchPodsMatch(t *testing.T) {
ctx := api.NewDefaultContext()
watching, err := registry.Watch(ctx,
labels.SelectorFromSet(labels.Set{"name": "foo"}),
labels.Everything(),
fields.Everything(),
"1",
)
if err != nil {
@@ -1590,7 +1591,7 @@ func TestEtcdWatchPodsNotMatch(t *testing.T) {
ctx := api.NewDefaultContext()
watching, err := registry.Watch(ctx,
labels.SelectorFromSet(labels.Set{"name": "foo"}),
labels.Everything(),
fields.Everything(),
"1",
)
if err != nil {

View File

@@ -19,6 +19,7 @@ package pod
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@@ -29,7 +30,7 @@ type Registry interface {
// ListPods obtains a list of pods having labels which match selector.
ListPods(ctx api.Context, selector labels.Selector) (*api.PodList, error)
// Watch for new/changed/deleted pods
WatchPods(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error)
WatchPods(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
// Get a specific pod
GetPod(ctx api.Context, podID string) (*api.Pod, error)
// Create a pod based on a specification.
@@ -64,14 +65,14 @@ func NewRegistry(s Storage) Registry {
}
func (s *storage) ListPods(ctx api.Context, label labels.Selector) (*api.PodList, error) {
obj, err := s.List(ctx, label, labels.Everything())
obj, err := s.List(ctx, label, fields.Everything())
if err != nil {
return nil, err
}
return obj.(*api.PodList), nil
}
func (s *storage) WatchPods(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
func (s *storage) WatchPods(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return s.Watch(ctx, label, field, resourceVersion)
}

View File

@@ -24,6 +24,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -116,7 +117,7 @@ func PodStatusReset(cache PodStatusGetter) rest.ObjectFunc {
}
// MatchPod returns a generic matcher for a given label and field selector.
func MatchPod(label, field labels.Selector) generic.Matcher {
func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
podObj, ok := obj.(*api.Pod)
if !ok {