mirror of https://github.com/k3s-io/k3s
Merge pull request #19970 from caesarxuchao/namespaced-cacher
Auto commit by PR queue botpull/6/head
commit
dc3ee665a7
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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{} },
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue