Merge pull request #1578 from brendandburns/controller

Extract the service controller from the apiserver.
This commit is contained in:
Daniel Smith
2014-10-06 12:44:41 -07:00
5 changed files with 18 additions and 35 deletions

View File

@@ -25,7 +25,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
@@ -33,15 +32,13 @@ import (
// EndpointController manages service endpoints.
type EndpointController struct {
client *client.Client
serviceRegistry service.Registry
client *client.Client
}
// NewEndpointController returns a new *EndpointController.
func NewEndpointController(serviceRegistry service.Registry, client *client.Client) *EndpointController {
func NewEndpointController(client *client.Client) *EndpointController {
return &EndpointController{
serviceRegistry: serviceRegistry,
client: client,
client: client,
}
}

View File

@@ -26,7 +26,6 @@ import (
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
@@ -160,8 +159,7 @@ func TestSyncEndpointsEmpty(t *testing.T) {
serverResponse{http.StatusOK, api.ServiceList{}},
serverResponse{http.StatusOK, api.Endpoints{}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -173,10 +171,7 @@ func TestSyncEndpointsError(t *testing.T) {
serverResponse{http.StatusInternalServerError, api.ServiceList{}},
serverResponse{http.StatusOK, api.Endpoints{}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{
Err: fmt.Errorf("test error"),
}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err == nil {
t.Errorf("unexpected non-error")
}
@@ -204,8 +199,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
Endpoints: []string{"6.7.8.9:1000"},
}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -240,8 +234,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
Endpoints: []string{"1.2.3.4:8080"},
}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -264,8 +257,7 @@ func TestSyncEndpointsItems(t *testing.T) {
serverResponse{http.StatusOK, serviceList},
serverResponse{http.StatusOK, api.Endpoints{}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -293,18 +285,7 @@ func TestSyncEndpointsPodError(t *testing.T) {
serverResponse{http.StatusOK, serviceList},
serverResponse{http.StatusOK, api.Endpoints{}})
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
serviceRegistry := registrytest.ServiceRegistry{
List: api.ServiceList{
Items: []api.Service{
{
Selector: map[string]string{
"foo": "bar",
},
},
},
},
}
endpoints := NewEndpointController(&serviceRegistry, client)
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err == nil {
t.Error("Unexpected non-error")
}