Switch on Cacher for pods, endpoints and nodes.

This commit is contained in:
Wojciech Tyczynski
2015-08-17 09:59:12 +02:00
parent 44fa48e5af
commit ec6556987e
10 changed files with 151 additions and 21 deletions

View File

@@ -32,8 +32,24 @@ type REST struct {
}
// NewREST returns a RESTStorage object that will work against endpoints.
func NewREST(s storage.Interface) *REST {
func NewREST(s storage.Interface, useCacher bool) *REST {
prefix := "/services/endpoints"
storageInterface := s
if useCacher {
config := storage.CacherConfig{
CacheCapacity: 1000,
Storage: s,
Type: &api.Endpoints{},
ResourcePrefix: prefix,
KeyFunc: func(obj runtime.Object) (string, error) {
return storage.NamespaceKeyFunc(prefix, obj)
},
NewListFunc: func() runtime.Object { return &api.EndpointsList{} },
}
storageInterface = storage.NewCacher(config)
}
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Endpoints{} },
NewListFunc: func() runtime.Object { return &api.EndpointsList{} },
@@ -54,7 +70,7 @@ func NewREST(s storage.Interface) *REST {
CreateStrategy: endpoint.Strategy,
UpdateStrategy: endpoint.Strategy,
Storage: s,
Storage: storageInterface,
}
return &REST{store}
}

View File

@@ -33,7 +33,7 @@ import (
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
return NewREST(etcdStorage), fakeClient
return NewREST(etcdStorage, false), fakeClient
}
func validNewEndpoints() *api.Endpoints {

View File

@@ -49,8 +49,24 @@ func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object
}
// NewStorage returns a RESTStorage object that will work against nodes.
func NewREST(s storage.Interface, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
func NewREST(s storage.Interface, useCacher bool, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
prefix := "/minions"
storageInterface := s
if useCacher {
config := storage.CacherConfig{
CacheCapacity: 1000,
Storage: s,
Type: &api.Node{},
ResourcePrefix: prefix,
KeyFunc: func(obj runtime.Object) (string, error) {
return storage.NoNamespaceKeyFunc(prefix, obj)
},
NewListFunc: func() runtime.Object { return &api.NodeList{} },
}
storageInterface = storage.NewCacher(config)
}
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Node{} },
NewListFunc: func() runtime.Object { return &api.NodeList{} },
@@ -69,7 +85,7 @@ func NewREST(s storage.Interface, connection client.ConnectionInfoGetter) (*REST
CreateStrategy: minion.Strategy,
UpdateStrategy: minion.Strategy,
Storage: s,
Storage: storageInterface,
}
statusStore := *store

View File

@@ -44,7 +44,7 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
storage, _ := NewREST(etcdStorage, fakeConnectionInfoGetter{})
storage, _ := NewREST(etcdStorage, false, fakeConnectionInfoGetter{})
return storage, fakeClient
}

View File

@@ -57,8 +57,24 @@ type REST struct {
}
// NewStorage returns a RESTStorage object that will work against pods.
func NewStorage(s storage.Interface, k client.ConnectionInfoGetter) PodStorage {
func NewStorage(s storage.Interface, useCacher bool, k client.ConnectionInfoGetter) PodStorage {
prefix := "/pods"
storageInterface := s
if useCacher {
config := storage.CacherConfig{
CacheCapacity: 1000,
Storage: s,
Type: &api.Pod{},
ResourcePrefix: prefix,
KeyFunc: func(obj runtime.Object) (string, error) {
return storage.NamespaceKeyFunc(prefix, obj)
},
NewListFunc: func() runtime.Object { return &api.PodList{} },
}
storageInterface = storage.NewCacher(config)
}
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Pod{} },
NewListFunc: func() runtime.Object { return &api.PodList{} },
@@ -76,7 +92,7 @@ func NewStorage(s storage.Interface, k client.ConnectionInfoGetter) PodStorage {
},
EndpointName: "pods",
Storage: s,
Storage: storageInterface,
}
statusStore := *store

View File

@@ -43,7 +43,7 @@ import (
func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
storage := NewStorage(etcdStorage, nil)
storage := NewStorage(etcdStorage, false, nil)
return storage.Pod, storage.Binding, storage.Status, fakeClient
}
@@ -981,7 +981,8 @@ func TestEtcdWatchPodsMatch(t *testing.T) {
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Name: "foo",
Namespace: "default",
Labels: map[string]string{
"name": "foo",
},