Commit 1c667e4f authored by deads2k's avatar deads2k

move core storage out of master.go

parent 24031f50
...@@ -28,7 +28,6 @@ import ( ...@@ -28,7 +28,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"time"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/api/meta"
...@@ -47,12 +46,9 @@ import ( ...@@ -47,12 +46,9 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
extensionsapiv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" extensionsapiv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/apis/rbac" "k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apiserver/request"
"k8s.io/kubernetes/pkg/generated/openapi" "k8s.io/kubernetes/pkg/generated/openapi"
"k8s.io/kubernetes/pkg/genericapiserver" "k8s.io/kubernetes/pkg/genericapiserver"
"k8s.io/kubernetes/pkg/kubelet/client" "k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/registry/core/endpoint"
"k8s.io/kubernetes/pkg/registry/core/namespace"
ipallocator "k8s.io/kubernetes/pkg/registry/core/service/ipallocator" ipallocator "k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
extensionsrest "k8s.io/kubernetes/pkg/registry/extensions/rest" extensionsrest "k8s.io/kubernetes/pkg/registry/extensions/rest"
"k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata" "k8s.io/kubernetes/pkg/registry/extensions/thirdpartyresourcedata"
...@@ -62,7 +58,6 @@ import ( ...@@ -62,7 +58,6 @@ import (
"k8s.io/kubernetes/pkg/storage" "k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest" "k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing" etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/util/intstr"
utilnet "k8s.io/kubernetes/pkg/util/net" utilnet "k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/version" "k8s.io/kubernetes/pkg/version"
...@@ -82,7 +77,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert. ...@@ -82,7 +77,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
master := &Master{ master := &Master{
GenericAPIServer: &genericapiserver.GenericAPIServer{}, GenericAPIServer: &genericapiserver.GenericAPIServer{},
} }
config := Config{ config := &Config{
GenericConfig: &genericapiserver.Config{}, GenericConfig: &genericapiserver.Config{},
} }
...@@ -108,6 +103,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert. ...@@ -108,6 +103,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{} config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}
config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper() config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper()
config.GenericConfig.EnableVersion = true config.GenericConfig.EnableVersion = true
config.EnableCoreControllers = false
// TODO: this is kind of hacky. The trouble is that the sync loop // TODO: this is kind of hacky. The trouble is that the sync loop
// runs in a go-routine and there is no way to validate in the test // runs in a go-routine and there is no way to validate in the test
...@@ -117,9 +113,14 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert. ...@@ -117,9 +113,14 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
// run the sync routine and register types manually. // run the sync routine and register types manually.
config.disableThirdPartyControllerForTesting = true config.disableThirdPartyControllerForTesting = true
master.nodeRegistry = registrytest.NewNodeRegistry([]string{"node1", "node2"}, api.NodeResources{}) master, err := config.Complete().New()
if err != nil {
t.Fatal(err)
}
return master, server, config, assert.New(t) master.legacyRESTStorage.NodeRegistry = registrytest.NewNodeRegistry([]string{"node1", "node2"}, api.NodeResources{})
return master, server, *config, assert.New(t)
} }
func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) { func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
...@@ -187,26 +188,6 @@ func TestNew(t *testing.T) { ...@@ -187,26 +188,6 @@ func TestNew(t *testing.T) {
assert.Equal(master.ProxyTransport.(*http.Transport).TLSClientConfig, config.GenericConfig.ProxyTLSClientConfig) assert.Equal(master.ProxyTransport.(*http.Transport).TLSClientConfig, config.GenericConfig.ProxyTLSClientConfig)
} }
// TestNamespaceSubresources ensures the namespace subresource parsing in apiserver/handlers.go doesn't drift
func TestNamespaceSubresources(t *testing.T) {
master, etcdserver, _, _ := newMaster(t)
defer etcdserver.Terminate(t)
expectedSubresources := request.NamespaceSubResourcesForTest
foundSubresources := sets.NewString()
for k := range master.v1ResourcesStorage {
parts := strings.Split(k, "/")
if len(parts) == 2 && parts[0] == "namespaces" {
foundSubresources.Insert(parts[1])
}
}
if !reflect.DeepEqual(expectedSubresources.List(), foundSubresources.List()) {
t.Errorf("Expected namespace subresources %#v, got %#v. Update apiserver/handlers.go#namespaceSubresources", expectedSubresources.List(), foundSubresources.List())
}
}
// TestVersion tests /version // TestVersion tests /version
func TestVersion(t *testing.T) { func TestVersion(t *testing.T) {
s, etcdserver, _, _ := newMaster(t) s, etcdserver, _, _ := newMaster(t)
...@@ -232,10 +213,10 @@ func TestVersion(t *testing.T) { ...@@ -232,10 +213,10 @@ func TestVersion(t *testing.T) {
// TestGetServersToValidate verifies the unexported getServersToValidate function // TestGetServersToValidate verifies the unexported getServersToValidate function
func TestGetServersToValidate(t *testing.T) { func TestGetServersToValidate(t *testing.T) {
master, etcdserver, config, assert := setUp(t) _, etcdserver, config, assert := setUp(t)
defer etcdserver.Terminate(t) defer etcdserver.Terminate(t)
servers := master.getServersToValidate(&config) servers := getServersToValidate(config.StorageFactory)
// Expected servers to validate: scheduler, controller-manager and etcd. // Expected servers to validate: scheduler, controller-manager and etcd.
assert.Equal(3, len(servers), "unexpected server list: %#v", servers) assert.Equal(3, len(servers), "unexpected server list: %#v", servers)
...@@ -276,74 +257,6 @@ func (*fakeEndpointReconciler) ReconcileEndpoints(serviceName string, ip net.IP, ...@@ -276,74 +257,6 @@ func (*fakeEndpointReconciler) ReconcileEndpoints(serviceName string, ip net.IP,
return nil return nil
} }
// TestNewBootstrapController verifies master fields are properly copied into controller
func TestNewBootstrapController(t *testing.T) {
// Tests a subset of inputs to ensure they are set properly in the controller
master, etcdserver, _, assert := setUp(t)
defer etcdserver.Terminate(t)
portRange := utilnet.PortRange{Base: 10, Size: 10}
master.namespaceRegistry = namespace.NewRegistry(nil)
master.serviceRegistry = registrytest.NewServiceRegistry()
master.endpointRegistry = endpoint.NewRegistry(nil)
master.ServiceNodePortRange = portRange
master.MasterCount = 1
master.ServiceReadWritePort = 1000
master.PublicReadWritePort = 1010
// test with an empty EndpointReconcilerConfig to ensure the defaults are applied
controller := master.NewBootstrapController(EndpointReconcilerConfig{})
assert.Equal(controller.NamespaceRegistry, master.namespaceRegistry)
assert.Equal(controller.EndpointReconciler, NewMasterCountEndpointReconciler(master.MasterCount, master.endpointRegistry))
assert.Equal(controller.EndpointInterval, DefaultEndpointReconcilerInterval)
assert.Equal(controller.ServiceRegistry, master.serviceRegistry)
assert.Equal(controller.ServiceNodePortRange, portRange)
assert.Equal(controller.ServicePort, master.ServiceReadWritePort)
assert.Equal(controller.PublicServicePort, master.PublicReadWritePort)
// test with a filled-in EndpointReconcilerConfig to make sure its values are used
controller = master.NewBootstrapController(EndpointReconcilerConfig{
Reconciler: &fakeEndpointReconciler{},
Interval: 5 * time.Second,
})
assert.Equal(controller.EndpointReconciler, &fakeEndpointReconciler{})
assert.Equal(controller.EndpointInterval, 5*time.Second)
}
// TestControllerServicePorts verifies master extraServicePorts are
// correctly copied into controller
func TestControllerServicePorts(t *testing.T) {
master, etcdserver, _, assert := setUp(t)
defer etcdserver.Terminate(t)
master.namespaceRegistry = namespace.NewRegistry(nil)
master.serviceRegistry = registrytest.NewServiceRegistry()
master.endpointRegistry = endpoint.NewRegistry(nil)
master.ExtraServicePorts = []api.ServicePort{
{
Name: "additional-port-1",
Port: 1000,
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(1000),
},
{
Name: "additional-port-2",
Port: 1010,
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(1010),
},
}
controller := master.NewBootstrapController(EndpointReconcilerConfig{})
assert.Equal(int32(1000), controller.ExtraServicePorts[0].Port)
assert.Equal(int32(1010), controller.ExtraServicePorts[1].Port)
}
// TestGetNodeAddresses verifies that proper results are returned // TestGetNodeAddresses verifies that proper results are returned
// when requesting node addresses. // when requesting node addresses.
func TestGetNodeAddresses(t *testing.T) { func TestGetNodeAddresses(t *testing.T) {
...@@ -351,14 +264,14 @@ func TestGetNodeAddresses(t *testing.T) { ...@@ -351,14 +264,14 @@ func TestGetNodeAddresses(t *testing.T) {
defer etcdserver.Terminate(t) defer etcdserver.Terminate(t)
// Fail case (no addresses associated with nodes) // Fail case (no addresses associated with nodes)
nodes, _ := master.nodeRegistry.ListNodes(api.NewDefaultContext(), nil) nodes, _ := master.legacyRESTStorage.NodeRegistry.ListNodes(api.NewDefaultContext(), nil)
addrs, err := master.getNodeAddresses() addrs, err := master.getNodeAddresses()
assert.Error(err, "getNodeAddresses should have caused an error as there are no addresses.") assert.Error(err, "getNodeAddresses should have caused an error as there are no addresses.")
assert.Equal([]string(nil), addrs) assert.Equal([]string(nil), addrs)
// Pass case with External type IP // Pass case with External type IP
nodes, _ = master.nodeRegistry.ListNodes(api.NewDefaultContext(), nil) nodes, _ = master.legacyRESTStorage.NodeRegistry.ListNodes(api.NewDefaultContext(), nil)
for index := range nodes.Items { for index := range nodes.Items {
nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeExternalIP, Address: "127.0.0.1"}} nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeExternalIP, Address: "127.0.0.1"}}
} }
...@@ -367,7 +280,7 @@ func TestGetNodeAddresses(t *testing.T) { ...@@ -367,7 +280,7 @@ func TestGetNodeAddresses(t *testing.T) {
assert.Equal([]string{"127.0.0.1", "127.0.0.1"}, addrs) assert.Equal([]string{"127.0.0.1", "127.0.0.1"}, addrs)
// Pass case with LegacyHost type IP // Pass case with LegacyHost type IP
nodes, _ = master.nodeRegistry.ListNodes(api.NewDefaultContext(), nil) nodes, _ = master.legacyRESTStorage.NodeRegistry.ListNodes(api.NewDefaultContext(), nil)
for index := range nodes.Items { for index := range nodes.Items {
nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeLegacyHostIP, Address: "127.0.0.2"}} nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeLegacyHostIP, Address: "127.0.0.2"}}
} }
......
...@@ -51,7 +51,7 @@ type ThirdPartyController struct { ...@@ -51,7 +51,7 @@ type ThirdPartyController struct {
thirdPartyResourceRegistry *thirdpartyresourceetcd.REST thirdPartyResourceRegistry *thirdpartyresourceetcd.REST
} }
// Synchronize a single resource with RESTful resources on the master // SyncOneResource synchronizes a single resource with RESTful resources on the master
func (t *ThirdPartyController) SyncOneResource(rsrc *extensions.ThirdPartyResource) error { func (t *ThirdPartyController) SyncOneResource(rsrc *extensions.ThirdPartyResource) error {
// TODO: we also need to test if the existing installed resource matches the resource we are sync-ing. // TODO: we also need to test if the existing installed resource matches the resource we are sync-ing.
// Currently, if there is an older, incompatible resource installed, we won't remove it. We should detect // Currently, if there is an older, incompatible resource installed, we won't remove it. We should detect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment