Step #1 in migrating the service controller away from the apiserver.

Start using the API server for listing services.
This commit is contained in:
Brendan Burns
2014-08-27 21:32:52 -07:00
parent 5bed06f614
commit fee2b90608
4 changed files with 114 additions and 35 deletions

View File

@@ -317,6 +317,11 @@ func (c *Client) WatchReplicationControllers(label, field labels.Selector, resou
Watch()
}
func (c *Client) ListServices(selector labels.Selector) (list api.ServiceList, err error) {
err = c.Get().Path("services").SelectorParam("labels", selector).Do().Into(&list)
return
}
// GetService returns information about a particular service.
func (c *Client) GetService(name string) (result api.Service, err error) {
err = c.Get().Path("services").Path(name).Do().Into(&result)

View File

@@ -406,6 +406,57 @@ func (c *testClient) Validate(t *testing.T, received interface{}, err error) {
}
}
func TestListServices(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "GET", Path: "/services"},
Response: Response{StatusCode: 200,
Body: api.ServiceList{
Items: []api.Service{
{
JSONBase: api.JSONBase{ID: "name"},
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
Selector: map[string]string{
"one": "two",
},
},
},
},
},
}
receivedServiceList, err := c.Setup().ListServices(labels.Everything())
c.Validate(t, receivedServiceList, err)
}
func TestListServicesLabels(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "GET", Path: "/services", Query: url.Values{"labels": []string{"foo=bar,name=baz"}}},
Response: Response{StatusCode: 200,
Body: api.ServiceList{
Items: []api.Service{
{
JSONBase: api.JSONBase{ID: "name"},
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
Selector: map[string]string{
"one": "two",
},
},
},
},
},
}
c.Setup()
c.QueryValidator["labels"] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.ListServices(selector)
c.Validate(t, receivedServiceList, err)
}
func TestGetService(t *testing.T) {
c := &testClient{
Request: testRequest{Method: "GET", Path: "/services/1"},