Add field selector to List, implement for pods.

This commit is contained in:
Daniel Smith
2014-09-16 16:15:40 -07:00
parent 3f659f7d74
commit 4e9cf2ccb4
18 changed files with 153 additions and 39 deletions

View File

@@ -88,7 +88,7 @@ type SimpleRESTStorage struct {
injectedFunction func(obj runtime.Object) (returnObj runtime.Object, err error)
}
func (storage *SimpleRESTStorage) List(labels.Selector) (runtime.Object, error) {
func (storage *SimpleRESTStorage) List(label, field labels.Selector) (runtime.Object, error) {
result := &SimpleList{
Items: storage.list,
}

View File

@@ -30,8 +30,7 @@ type RESTStorage interface {
New() runtime.Object
// List selects resources in the storage which match to the selector.
// TODO: add field selector in addition to label selector.
List(labels.Selector) (runtime.Object, error)
List(label, field labels.Selector) (runtime.Object, error)
// Get finds a resource in the storage by id and returns it.
// Although it can return an arbitrary error value, IsNotFound(err) is true for the

View File

@@ -70,12 +70,17 @@ func (h *RESTHandler) handleRESTStorage(parts []string, req *http.Request, w htt
case "GET":
switch len(parts) {
case 1:
selector, err := labels.ParseSelector(req.URL.Query().Get("labels"))
label, err := labels.ParseSelector(req.URL.Query().Get("labels"))
if err != nil {
errorJSON(err, h.codec, w)
return
}
list, err := storage.List(selector)
field, err := labels.ParseSelector(req.URL.Query().Get("fields"))
if err != nil {
errorJSON(err, h.codec, w)
return
}
list, err := storage.List(label, field)
if err != nil {
errorJSON(err, h.codec, w)
return