Implement label queries for controller registry

This commit is contained in:
Daniel Smith 2014-06-16 18:17:08 -07:00
parent 154ec0db1e
commit ad2ec27e91

View File

@ -18,10 +18,10 @@ package registry
import ( import (
"encoding/json" "encoding/json"
"net/url"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
) )
// Implementation of RESTStorage for the api server. // Implementation of RESTStorage for the api server.
@ -35,13 +35,14 @@ func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTSt
} }
} }
func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { func (storage *ControllerRegistryStorage) List(query labels.Query) (interface{}, error) {
result := api.ReplicationControllerList{JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"}} result := api.ReplicationControllerList{JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"}}
controllers, err := storage.registry.ListControllers() controllers, err := storage.registry.ListControllers()
if err == nil { if err == nil {
result = api.ReplicationControllerList{ for _, controller := range controllers {
JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"}, if query.Matches(labels.LabelSet(controller.Labels)) {
Items: controllers, result.Items = append(result.Items, controller)
}
} }
} }
return result, err return result, err