Added field selector for listing pods.

This commit is contained in:
Ravi Gadde
2015-04-20 11:53:06 -07:00
parent a45b5c3ebf
commit bf8f258471
18 changed files with 43 additions and 37 deletions

View File

@@ -30,7 +30,7 @@ type PodsNamespacer interface {
// PodInterface has methods to work with Pod resources.
type PodInterface interface {
List(selector labels.Selector) (*api.PodList, error)
List(label labels.Selector, field fields.Selector) (*api.PodList, error)
Get(name string) (*api.Pod, error)
Delete(name string) error
Create(pod *api.Pod) (*api.Pod, error)
@@ -54,10 +54,10 @@ func newPods(c *Client, namespace string) *pods {
}
}
// List takes a selector, and returns the list of pods that match that selector.
func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
// List takes label and field selectors, and returns the list of pods that match those selectors.
func (c *pods) List(label labels.Selector, field fields.Selector) (result *api.PodList, err error) {
result = &api.PodList{}
err = c.r.Get().Namespace(c.ns).Resource("pods").LabelsSelectorParam(selector).Do().Into(result)
err = c.r.Get().Namespace(c.ns).Resource("pods").LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
return
}

View File

@@ -22,6 +22,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"
)
@@ -31,7 +32,7 @@ func TestListEmptyPods(t *testing.T) {
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(ns, nil)},
Response: Response{StatusCode: 200, Body: &api.PodList{}},
}
podList, err := c.Setup().Pods(ns).List(labels.Everything())
podList, err := c.Setup().Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, podList, err)
}
@@ -57,7 +58,7 @@ func TestListPods(t *testing.T) {
},
},
}
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything())
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, receivedPodList, err)
}
@@ -91,7 +92,7 @@ func TestListPodsLabels(t *testing.T) {
c.Setup()
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.Pods(ns).List(selector)
receivedPodList, err := c.Pods(ns).List(selector, fields.Everything())
c.Validate(t, receivedPodList, err)
}

View File

@@ -30,7 +30,7 @@ type FakePods struct {
Namespace string
}
func (c *FakePods) List(selector labels.Selector) (*api.PodList, error) {
func (c *FakePods) List(label labels.Selector, field fields.Selector) (*api.PodList, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-pods"}, &api.PodList{})
return obj.(*api.PodList), err
}