Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit ebcff4b

Browse files
author
Chao Xu
committed
fix the namespaceScoped of cachers
1 parent 2aff6cc commit ebcff4b

File tree

24 files changed

+44
-26
lines changed

24 files changed

+44
-26
lines changed

examples/apiserver/rest/reststorage.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ type REST struct {
3535
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *REST {
3636
prefix := "/testtype"
3737
newListFunc := func() runtime.Object { return &testgroup.TestTypeList{} }
38+
// Usually you should reuse your RESTCreateStrategy.
39+
strategy := &NotNamespaceScoped{}
3840
storageInterface := storageDecorator(
39-
s, 100, &testgroup.TestType{}, prefix, false, newListFunc)
41+
s, 100, &testgroup.TestType{}, prefix, strategy, newListFunc)
4042
store := &etcdgeneric.Etcd{
4143
NewFunc: func() runtime.Object { return &testgroup.TestType{} },
4244
// 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
6365
}
6466
return &REST{store}
6567
}
68+
69+
type NotNamespaceScoped struct {
70+
}
71+
72+
func (*NotNamespaceScoped) NamespaceScoped() bool {
73+
return false
74+
}

pkg/api/rest/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.Obje
118118
}
119119
return objectMeta, kind, nil
120120
}
121+
122+
// NamespaceScopedStrategy has a method to tell if the object must be in a namespace.
123+
type NamespaceScopedStrategy interface {
124+
// NamespaceScoped returns if the object must be in a namespace.
125+
NamespaceScoped() bool
126+
}

pkg/registry/configmap/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.ConfigMapList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.ConfigMap{}, prefix, false, newListFunc)
40+
s, 100, &api.ConfigMap{}, prefix, configmap.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object {

pkg/registry/controller/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3737

3838
newListFunc := func() runtime.Object { return &api.ReplicationControllerList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.ReplicationController{}, prefix, true, newListFunc)
40+
s, 100, &api.ReplicationController{}, prefix, controller.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.ReplicationController{} },

pkg/registry/daemonset/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3939

4040
newListFunc := func() runtime.Object { return &extensions.DaemonSetList{} }
4141
storageInterface := storageDecorator(
42-
s, 100, &extensions.DaemonSet{}, prefix, false, newListFunc)
42+
s, 100, &extensions.DaemonSet{}, prefix, daemonset.Strategy, newListFunc)
4343

4444
store := &etcdgeneric.Etcd{
4545
NewFunc: func() runtime.Object { return &extensions.DaemonSet{} },

pkg/registry/deployment/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
6262

6363
newListFunc := func() runtime.Object { return &extensions.DeploymentList{} }
6464
storageInterface := storageDecorator(
65-
s, 100, &extensions.Deployment{}, prefix, false, newListFunc)
65+
s, 100, &extensions.Deployment{}, prefix, deployment.Strategy, newListFunc)
6666

6767
store := &etcdgeneric.Etcd{
6868
NewFunc: func() runtime.Object { return &extensions.Deployment{} },

pkg/registry/endpoint/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.EndpointsList{} }
3939
storageInterface := storageDecorator(
40-
s, 1000, &api.Endpoints{}, prefix, true, newListFunc)
40+
s, 1000, &api.Endpoints{}, prefix, endpoint.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.Endpoints{} },

pkg/registry/generic/etcd/storage_factory.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package etcd
1818

1919
import (
20+
"k8s.io/kubernetes/pkg/api/rest"
2021
"k8s.io/kubernetes/pkg/runtime"
2122
"k8s.io/kubernetes/pkg/storage"
2223
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
@@ -28,9 +29,9 @@ func StorageWithCacher(
2829
capacity int,
2930
objectType runtime.Object,
3031
resourcePrefix string,
31-
namespaceScoped bool,
32+
scopeStrategy rest.NamespaceScopedStrategy,
3233
newListFunc func() runtime.Object) storage.Interface {
3334
return storage.NewCacher(
3435
storageInterface, capacity, etcdstorage.APIObjectVersioner{},
35-
objectType, resourcePrefix, namespaceScoped, newListFunc)
36+
objectType, resourcePrefix, scopeStrategy, newListFunc)
3637
}

pkg/registry/generic/storage_decorator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package generic
1818

1919
import (
20+
"k8s.io/kubernetes/pkg/api/rest"
2021
"k8s.io/kubernetes/pkg/runtime"
2122
"k8s.io/kubernetes/pkg/storage"
2223
)
@@ -28,7 +29,7 @@ type StorageDecorator func(
2829
capacity int,
2930
objectType runtime.Object,
3031
resourcePrefix string,
31-
namespaceScoped bool,
32+
scopeStrategy rest.NamespaceScopedStrategy,
3233
newListFunc func() runtime.Object) storage.Interface
3334

3435
// Returns given 'storageInterface' without any decoration.
@@ -37,7 +38,7 @@ func UndecoratedStorage(
3738
capacity int,
3839
objectType runtime.Object,
3940
resourcePrefix string,
40-
namespaceScoped bool,
41+
scopeStrategy rest.NamespaceScopedStrategy,
4142
newListFunc func() runtime.Object) storage.Interface {
4243
return storageInterface
4344
}

pkg/registry/horizontalpodautoscaler/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3838

3939
newListFunc := func() runtime.Object { return &extensions.HorizontalPodAutoscalerList{} }
4040
storageInterface := storageDecorator(
41-
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, false, newListFunc)
41+
s, 100, &extensions.HorizontalPodAutoscaler{}, prefix, horizontalpodautoscaler.Strategy, newListFunc)
4242

4343
store := &etcdgeneric.Etcd{
4444
NewFunc: func() runtime.Object { return &extensions.HorizontalPodAutoscaler{} },

pkg/registry/ingress/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3939

4040
newListFunc := func() runtime.Object { return &extensions.IngressList{} }
4141
storageInterface := storageDecorator(
42-
s, 100, &extensions.Ingress{}, prefix, false, newListFunc)
42+
s, 100, &extensions.Ingress{}, prefix, ingress.Strategy, newListFunc)
4343

4444
store := &etcdgeneric.Etcd{
4545
NewFunc: func() runtime.Object { return &extensions.Ingress{} },

pkg/registry/job/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3939

4040
newListFunc := func() runtime.Object { return &extensions.JobList{} }
4141
storageInterface := storageDecorator(
42-
s, 100, &extensions.Job{}, prefix, false, newListFunc)
42+
s, 100, &extensions.Job{}, prefix, job.Strategy, newListFunc)
4343

4444
store := &etcdgeneric.Etcd{
4545
NewFunc: func() runtime.Object { return &extensions.Job{} },

pkg/registry/limitrange/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.LimitRangeList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.LimitRange{}, prefix, true, newListFunc)
40+
s, 100, &api.LimitRange{}, prefix, limitrange.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.LimitRange{} },

pkg/registry/namespace/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
5353

5454
newListFunc := func() runtime.Object { return &api.NamespaceList{} }
5555
storageInterface := storageDecorator(
56-
s, 100, &api.Namespace{}, prefix, true, newListFunc)
56+
s, 100, &api.Namespace{}, prefix, namespace.Strategy, newListFunc)
5757

5858
store := &etcdgeneric.Etcd{
5959
NewFunc: func() runtime.Object { return &api.Namespace{} },

pkg/registry/node/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator, con
5757

5858
newListFunc := func() runtime.Object { return &api.NodeList{} }
5959
storageInterface := storageDecorator(
60-
s, 1000, &api.Node{}, prefix, false, newListFunc)
60+
s, 1000, &api.Node{}, prefix, node.Strategy, newListFunc)
6161

6262
store := &etcdgeneric.Etcd{
6363
NewFunc: func() runtime.Object { return &api.Node{} },

pkg/registry/persistentvolume/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3737

3838
newListFunc := func() runtime.Object { return &api.PersistentVolumeList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.PersistentVolume{}, prefix, true, newListFunc)
40+
s, 100, &api.PersistentVolume{}, prefix, persistentvolume.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.PersistentVolume{} },

pkg/registry/persistentvolumeclaim/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3737

3838
newListFunc := func() runtime.Object { return &api.PersistentVolumeClaimList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.PersistentVolumeClaim{}, prefix, true, newListFunc)
40+
s, 100, &api.PersistentVolumeClaim{}, prefix, persistentvolumeclaim.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.PersistentVolumeClaim{} },

pkg/registry/pod/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewStorage(
6767

6868
newListFunc := func() runtime.Object { return &api.PodList{} }
6969
storageInterface := storageDecorator(
70-
s, 1000, &api.Pod{}, prefix, true, newListFunc)
70+
s, 1000, &api.Pod{}, prefix, pod.Strategy, newListFunc)
7171

7272
store := &etcdgeneric.Etcd{
7373
NewFunc: func() runtime.Object { return &api.Pod{} },

pkg/registry/podtemplate/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.PodTemplateList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.PodTemplate{}, prefix, false, newListFunc)
40+
s, 100, &api.PodTemplate{}, prefix, podtemplate.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.PodTemplate{} },

pkg/registry/resourcequota/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*R
3737

3838
newListFunc := func() runtime.Object { return &api.ResourceQuotaList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.ResourceQuota{}, prefix, true, newListFunc)
40+
s, 100, &api.ResourceQuota{}, prefix, resourcequota.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.ResourceQuota{} },

pkg/registry/secret/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.SecretList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.Secret{}, prefix, true, newListFunc)
40+
s, 100, &api.Secret{}, prefix, secret.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.Secret{} },

pkg/registry/service/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.ServiceList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.Service{}, prefix, false, newListFunc)
40+
s, 100, &api.Service{}, prefix, service.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.Service{} },

pkg/registry/serviceaccount/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *RE
3737

3838
newListFunc := func() runtime.Object { return &api.ServiceAccountList{} }
3939
storageInterface := storageDecorator(
40-
s, 100, &api.ServiceAccount{}, prefix, true, newListFunc)
40+
s, 100, &api.ServiceAccount{}, prefix, serviceaccount.Strategy, newListFunc)
4141

4242
store := &etcdgeneric.Etcd{
4343
NewFunc: func() runtime.Object { return &api.ServiceAccount{} },

pkg/storage/cacher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"k8s.io/kubernetes/pkg/api"
2828
"k8s.io/kubernetes/pkg/api/meta"
29+
"k8s.io/kubernetes/pkg/api/rest"
2930
"k8s.io/kubernetes/pkg/client/cache"
3031
"k8s.io/kubernetes/pkg/conversion"
3132
"k8s.io/kubernetes/pkg/runtime"
@@ -115,7 +116,7 @@ func NewCacher(
115116
versioner Versioner,
116117
objectType runtime.Object,
117118
resourcePrefix string,
118-
namespaceScoped bool,
119+
scopeStrategy rest.NamespaceScopedStrategy,
119120
newListFunc func() runtime.Object) Interface {
120121
config := CacherConfig{
121122
CacheCapacity: capacity,
@@ -125,7 +126,7 @@ func NewCacher(
125126
ResourcePrefix: resourcePrefix,
126127
NewListFunc: newListFunc,
127128
}
128-
if namespaceScoped {
129+
if scopeStrategy.NamespaceScoped() {
129130
config.KeyFunc = func(obj runtime.Object) (string, error) {
130131
return NamespaceKeyFunc(resourcePrefix, obj)
131132
}

0 commit comments

Comments
 (0)