Merge pull request #19970 from caesarxuchao/namespaced-cacher

Auto commit by PR queue bot
pull/6/head
k8s-merge-robot 2016-01-30 03:44:19 -08:00
commit dc3ee665a7
24 changed files with 44 additions and 26 deletions

View File

@ -35,8 +35,10 @@ type REST struct {
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *REST {
prefix := "/testtype"
newListFunc := func() runtime.Object { return &testgroup.TestTypeList{} }
// Usually you should reuse your RESTCreateStrategy.
strategy := &NotNamespaceScoped{}
storageInterface := storageDecorator(
s, 100, &testgroup.TestType{}, prefix, false, newListFunc)
s, 100, &testgroup.TestType{}, prefix, strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &testgroup.TestType{} },
// NewListFunc returns an object capable of storing results of an etcd list.
@ -63,3 +65,10 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
}
return &REST{store}
}
type NotNamespaceScoped struct {
}
func (*NotNamespaceScoped) NamespaceScoped() bool {
return false
}

View File

@ -118,3 +118,9 @@ func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.Obje
}
return objectMeta, kind, nil
}
// NamespaceScopedStrategy has a method to tell if the object must be in a namespace.
type NamespaceScopedStrategy interface {
// NamespaceScoped returns if the object must be in a namespace.
NamespaceScoped() bool
}

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.ConfigMapList{} }
storageInterface := storageDecorator(
s, 100, &api.ConfigMap{}, prefix, false, newListFunc)
s, 100, &api.ConfigMap{}, prefix, configmap.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object {

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &api.ReplicationControllerList{} }
storageInterface := storageDecorator(
s, 100, &api.ReplicationController{}, prefix, true, newListFunc)
s, 100, &api.ReplicationController{}, prefix, controller.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ReplicationController{} },

View File

@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &extensions.DaemonSetList{} }
storageInterface := storageDecorator(
s, 100, &extensions.DaemonSet{}, prefix, false, newListFunc)
s, 100, &extensions.DaemonSet{}, prefix, daemonset.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.DaemonSet{} },

View File

@ -62,7 +62,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &extensions.DeploymentList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Deployment{}, prefix, false, newListFunc)
s, 100, &extensions.Deployment{}, prefix, deployment.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Deployment{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.EndpointsList{} }
storageInterface := storageDecorator(
s, 1000, &api.Endpoints{}, prefix, true, newListFunc)
s, 1000, &api.Endpoints{}, prefix, endpoint.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Endpoints{} },

View File

@ -17,6 +17,7 @@ limitations under the License.
package etcd
import (
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
@ -28,9 +29,9 @@ func StorageWithCacher(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface {
return storage.NewCacher(
storageInterface, capacity, etcdstorage.APIObjectVersioner{},
objectType, resourcePrefix, namespaceScoped, newListFunc)
objectType, resourcePrefix, scopeStrategy, newListFunc)
}

View File

@ -17,6 +17,7 @@ limitations under the License.
package generic
import (
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
)
@ -28,7 +29,7 @@ type StorageDecorator func(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface
// Returns given 'storageInterface' without any decoration.
@ -37,7 +38,7 @@ func UndecoratedStorage(
capacity int,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface {
return storageInterface
}

View File

@ -38,7 +38,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &extensions.HorizontalPodAutoscalerList{} }
storageInterface := storageDecorator(
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, false, newListFunc)
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, horizontalpodautoscaler.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.HorizontalPodAutoscaler{} },

View File

@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &extensions.IngressList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Ingress{}, prefix, false, newListFunc)
s, 100, &extensions.Ingress{}, prefix, ingress.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Ingress{} },

View File

@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &extensions.JobList{} }
storageInterface := storageDecorator(
s, 100, &extensions.Job{}, prefix, false, newListFunc)
s, 100, &extensions.Job{}, prefix, job.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &extensions.Job{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.LimitRangeList{} }
storageInterface := storageDecorator(
s, 100, &api.LimitRange{}, prefix, true, newListFunc)
s, 100, &api.LimitRange{}, prefix, limitrange.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.LimitRange{} },

View File

@ -53,7 +53,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &api.NamespaceList{} }
storageInterface := storageDecorator(
s, 100, &api.Namespace{}, prefix, true, newListFunc)
s, 100, &api.Namespace{}, prefix, namespace.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Namespace{} },

View File

@ -57,7 +57,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator, con
newListFunc := func() runtime.Object { return &api.NodeList{} }
storageInterface := storageDecorator(
s, 1000, &api.Node{}, prefix, false, newListFunc)
s, 1000, &api.Node{}, prefix, node.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Node{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &api.PersistentVolumeList{} }
storageInterface := storageDecorator(
s, 100, &api.PersistentVolume{}, prefix, true, newListFunc)
s, 100, &api.PersistentVolume{}, prefix, persistentvolume.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PersistentVolume{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &api.PersistentVolumeClaimList{} }
storageInterface := storageDecorator(
s, 100, &api.PersistentVolumeClaim{}, prefix, true, newListFunc)
s, 100, &api.PersistentVolumeClaim{}, prefix, persistentvolumeclaim.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PersistentVolumeClaim{} },

View File

@ -67,7 +67,7 @@ func NewStorage(
newListFunc := func() runtime.Object { return &api.PodList{} }
storageInterface := storageDecorator(
s, 1000, &api.Pod{}, prefix, true, newListFunc)
s, 1000, &api.Pod{}, prefix, pod.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Pod{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.PodTemplateList{} }
storageInterface := storageDecorator(
s, 100, &api.PodTemplate{}, prefix, false, newListFunc)
s, 100, &api.PodTemplate{}, prefix, podtemplate.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.PodTemplate{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
newListFunc := func() runtime.Object { return &api.ResourceQuotaList{} }
storageInterface := storageDecorator(
s, 100, &api.ResourceQuota{}, prefix, true, newListFunc)
s, 100, &api.ResourceQuota{}, prefix, resourcequota.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ResourceQuota{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.SecretList{} }
storageInterface := storageDecorator(
s, 100, &api.Secret{}, prefix, true, newListFunc)
s, 100, &api.Secret{}, prefix, secret.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Secret{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.ServiceList{} }
storageInterface := storageDecorator(
s, 100, &api.Service{}, prefix, false, newListFunc)
s, 100, &api.Service{}, prefix, service.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.Service{} },

View File

@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
newListFunc := func() runtime.Object { return &api.ServiceAccountList{} }
storageInterface := storageDecorator(
s, 100, &api.ServiceAccount{}, prefix, true, newListFunc)
s, 100, &api.ServiceAccount{}, prefix, serviceaccount.Strategy, newListFunc)
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.ServiceAccount{} },

View File

@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime"
@ -115,7 +116,7 @@ func NewCacher(
versioner Versioner,
objectType runtime.Object,
resourcePrefix string,
namespaceScoped bool,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) Interface {
config := CacherConfig{
CacheCapacity: capacity,
@ -125,7 +126,7 @@ func NewCacher(
ResourcePrefix: resourcePrefix,
NewListFunc: newListFunc,
}
if namespaceScoped {
if scopeStrategy.NamespaceScoped() {
config.KeyFunc = func(obj runtime.Object) (string, error) {
return NamespaceKeyFunc(resourcePrefix, obj)
}